test_resolution.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import numpy as np
  2. import pytest
  3. import pytz
  4. from pandas._libs.tslibs import (
  5. Resolution,
  6. get_resolution,
  7. )
  8. from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
  9. import pandas._testing as tm
  10. def test_get_resolution_nano():
  11. # don't return the fallback RESO_DAY
  12. arr = np.array([1], dtype=np.int64)
  13. res = get_resolution(arr)
  14. assert res == Resolution.RESO_NS
  15. def test_get_resolution_non_nano_data():
  16. arr = np.array([1], dtype=np.int64)
  17. res = get_resolution(arr, None, NpyDatetimeUnit.NPY_FR_us.value)
  18. assert res == Resolution.RESO_US
  19. res = get_resolution(arr, pytz.UTC, NpyDatetimeUnit.NPY_FR_us.value)
  20. assert res == Resolution.RESO_US
  21. @pytest.mark.parametrize(
  22. "freqstr,expected",
  23. [
  24. ("Y", "year"),
  25. ("Q", "quarter"),
  26. ("M", "month"),
  27. ("D", "day"),
  28. ("h", "hour"),
  29. ("min", "minute"),
  30. ("s", "second"),
  31. ("ms", "millisecond"),
  32. ("us", "microsecond"),
  33. ("ns", "nanosecond"),
  34. ],
  35. )
  36. def test_get_attrname_from_abbrev(freqstr, expected):
  37. reso = Resolution.get_reso_from_freqstr(freqstr)
  38. assert reso.attr_abbrev == freqstr
  39. assert reso.attrname == expected
  40. @pytest.mark.parametrize("freq", ["A", "H", "T", "S", "L", "U", "N"])
  41. def test_units_A_H_T_S_L_U_N_deprecated_from_attrname_to_abbrevs(freq):
  42. # GH#52536
  43. msg = f"'{freq}' is deprecated and will be removed in a future version."
  44. with tm.assert_produces_warning(FutureWarning, match=msg):
  45. Resolution.get_reso_from_freqstr(freq)