diff --git a/asv_bench/benchmarks/arithmetic.py b/asv_bench/benchmarks/arithmetic.py index 4fd9740f184c8..49543c166d047 100644 --- a/asv_bench/benchmarks/arithmetic.py +++ b/asv_bench/benchmarks/arithmetic.py @@ -262,7 +262,7 @@ class Timeseries: def setup(self, tz): N = 10**6 halfway = (N // 2) - 1 - self.s = Series(date_range("20010101", periods=N, freq="T", tz=tz)) + self.s = Series(date_range("20010101", periods=N, freq="min", tz=tz)) self.ts = self.s[halfway] self.s2 = Series(date_range("20010101", periods=N, freq="s", tz=tz)) @@ -460,7 +460,7 @@ class OffsetArrayArithmetic: def setup(self, offset): N = 10000 - rng = date_range(start="1/1/2000", periods=N, freq="T") + rng = date_range(start="1/1/2000", periods=N, freq="min") self.rng = rng self.ser = Series(rng) @@ -479,7 +479,7 @@ class ApplyIndex: def setup(self, offset): N = 10000 - rng = date_range(start="1/1/2000", periods=N, freq="T") + rng = date_range(start="1/1/2000", periods=N, freq="min") self.rng = rng def time_apply_index(self, offset): diff --git a/asv_bench/benchmarks/eval.py b/asv_bench/benchmarks/eval.py index 8a3d224c59a09..656d16a910a9f 100644 --- a/asv_bench/benchmarks/eval.py +++ b/asv_bench/benchmarks/eval.py @@ -44,7 +44,7 @@ class Query: def setup(self): N = 10**6 halfway = (N // 2) - 1 - index = pd.date_range("20010101", periods=N, freq="T") + index = pd.date_range("20010101", periods=N, freq="min") s = pd.Series(index) self.ts = s.iloc[halfway] self.df = pd.DataFrame({"a": np.random.randn(N), "dates": index}, index=index) diff --git a/asv_bench/benchmarks/gil.py b/asv_bench/benchmarks/gil.py index 4d5c31d2dddf8..4993ffd2c47d0 100644 --- a/asv_bench/benchmarks/gil.py +++ b/asv_bench/benchmarks/gil.py @@ -178,7 +178,7 @@ def time_kth_smallest(self): class ParallelDatetimeFields: def setup(self): N = 10**6 - self.dti = date_range("1900-01-01", periods=N, freq="T") + self.dti = date_range("1900-01-01", periods=N, freq="min") self.period = self.dti.to_period("D") def time_datetime_field_year(self): diff --git a/asv_bench/benchmarks/index_cached_properties.py b/asv_bench/benchmarks/index_cached_properties.py index b3d8de39a858a..d21bbe15c4cc8 100644 --- a/asv_bench/benchmarks/index_cached_properties.py +++ b/asv_bench/benchmarks/index_cached_properties.py @@ -25,14 +25,14 @@ def setup(self, index_type): N = 10**5 if index_type == "MultiIndex": self.idx = pd.MultiIndex.from_product( - [pd.date_range("1/1/2000", freq="T", periods=N // 2), ["a", "b"]] + [pd.date_range("1/1/2000", freq="min", periods=N // 2), ["a", "b"]] ) elif index_type == "DatetimeIndex": - self.idx = pd.date_range("1/1/2000", freq="T", periods=N) + self.idx = pd.date_range("1/1/2000", freq="min", periods=N) elif index_type == "Int64Index": self.idx = pd.Index(range(N), dtype="int64") elif index_type == "PeriodIndex": - self.idx = pd.period_range("1/1/2000", freq="T", periods=N) + self.idx = pd.period_range("1/1/2000", freq="min", periods=N) elif index_type == "RangeIndex": self.idx = pd.RangeIndex(start=0, stop=N) elif index_type == "IntervalIndex": diff --git a/asv_bench/benchmarks/index_object.py b/asv_bench/benchmarks/index_object.py index bdc8a6a7aa1df..2d8014570466e 100644 --- a/asv_bench/benchmarks/index_object.py +++ b/asv_bench/benchmarks/index_object.py @@ -25,7 +25,7 @@ class SetOperations: def setup(self, index_structure, dtype, method): N = 10**5 - dates_left = date_range("1/1/2000", periods=N, freq="T") + dates_left = date_range("1/1/2000", periods=N, freq="min") fmt = "%Y-%m-%d %H:%M:%S" date_str_left = Index(dates_left.strftime(fmt)) int_left = Index(np.arange(N)) diff --git a/asv_bench/benchmarks/io/json.py b/asv_bench/benchmarks/io/json.py index 9eaffddd8b87f..bebf6ee993aba 100644 --- a/asv_bench/benchmarks/io/json.py +++ b/asv_bench/benchmarks/io/json.py @@ -290,7 +290,7 @@ def time_float_longint_str_lines(self): class ToJSONMem: def setup_cache(self): df = DataFrame([[1]]) - df2 = DataFrame(range(8), date_range("1/1/2000", periods=8, freq="T")) + df2 = DataFrame(range(8), date_range("1/1/2000", periods=8, freq="min")) frames = {"int": df, "float": df.astype(float), "datetime": df2} return frames diff --git a/asv_bench/benchmarks/join_merge.py b/asv_bench/benchmarks/join_merge.py index 4f325335829af..54bcdb0fa2843 100644 --- a/asv_bench/benchmarks/join_merge.py +++ b/asv_bench/benchmarks/join_merge.py @@ -212,7 +212,7 @@ class JoinNonUnique: # outer join of non-unique # GH 6329 def setup(self): - date_index = date_range("01-Jan-2013", "23-Jan-2013", freq="T") + date_index = date_range("01-Jan-2013", "23-Jan-2013", freq="min") daily_dates = date_index.to_period("D").to_timestamp("S", "S") self.fracofday = date_index.values - daily_dates.values self.fracofday = self.fracofday.astype("timedelta64[ns]") @@ -338,7 +338,7 @@ class MergeDatetime: def setup(self, units, tz): unit_left, unit_right = units N = 10_000 - keys = Series(date_range("2012-01-01", freq="T", periods=N, tz=tz)) + keys = Series(date_range("2012-01-01", freq="min", periods=N, tz=tz)) self.left = DataFrame( { "key": keys.sample(N * 10, replace=True).dt.as_unit(unit_left), diff --git a/asv_bench/benchmarks/sparse.py b/asv_bench/benchmarks/sparse.py index c8a9a9e6e9176..22a5511e4c678 100644 --- a/asv_bench/benchmarks/sparse.py +++ b/asv_bench/benchmarks/sparse.py @@ -22,7 +22,7 @@ class SparseSeriesToFrame: def setup(self): K = 50 N = 50001 - rng = date_range("1/1/2000", periods=N, freq="T") + rng = date_range("1/1/2000", periods=N, freq="min") self.series = {} for i in range(1, K): data = np.random.randn(N)[:-i] diff --git a/asv_bench/benchmarks/timeseries.py b/asv_bench/benchmarks/timeseries.py index 1253fefde2d5f..8c78a9c1723df 100644 --- a/asv_bench/benchmarks/timeseries.py +++ b/asv_bench/benchmarks/timeseries.py @@ -116,7 +116,7 @@ def time_infer_freq(self, freq): class TimeDatetimeConverter: def setup(self): N = 100000 - self.rng = date_range(start="1/1/2000", periods=N, freq="T") + self.rng = date_range(start="1/1/2000", periods=N, freq="min") def time_convert(self): DatetimeConverter.convert(self.rng, None, None) @@ -129,9 +129,9 @@ class Iteration: def setup(self, time_index): N = 10**6 if time_index is timedelta_range: - self.idx = time_index(start=0, freq="T", periods=N) + self.idx = time_index(start=0, freq="min", periods=N) else: - self.idx = time_index(start="20140101", freq="T", periods=N) + self.idx = time_index(start="20140101", freq="min", periods=N) self.exit = 10000 def time_iter(self, time_index): @@ -149,7 +149,7 @@ class ResampleDataFrame: param_names = ["method"] def setup(self, method): - rng = date_range(start="20130101", periods=100000, freq="50L") + rng = date_range(start="20130101", periods=100000, freq="50ms") df = DataFrame(np.random.randn(100000, 2), index=rng) self.resample = getattr(df.resample("1s"), method) @@ -163,8 +163,8 @@ class ResampleSeries: def setup(self, index, freq, method): indexes = { - "period": period_range(start="1/1/2000", end="1/1/2001", freq="T"), - "datetime": date_range(start="1/1/2000", end="1/1/2001", freq="T"), + "period": period_range(start="1/1/2000", end="1/1/2001", freq="min"), + "datetime": date_range(start="1/1/2000", end="1/1/2001", freq="min"), } idx = indexes[index] ts = Series(np.random.randn(len(idx)), index=idx) @@ -178,7 +178,7 @@ class ResampleDatetetime64: # GH 7754 def setup(self): rng3 = date_range( - start="2000-01-01 00:00:00", end="2000-01-01 10:00:00", freq="555000U" + start="2000-01-01 00:00:00", end="2000-01-01 10:00:00", freq="555000us" ) self.dt_ts = Series(5, rng3, dtype="datetime64[ns]") @@ -270,7 +270,7 @@ class DatetimeAccessor: def setup(self, tz): N = 100000 - self.series = Series(date_range(start="1/1/2000", periods=N, freq="T", tz=tz)) + self.series = Series(date_range(start="1/1/2000", periods=N, freq="min", tz=tz)) def time_dt_accessor(self, tz): self.series.dt diff --git a/asv_bench/benchmarks/tslibs/timestamp.py b/asv_bench/benchmarks/tslibs/timestamp.py index d7706a39dfae5..082220ee0dff2 100644 --- a/asv_bench/benchmarks/tslibs/timestamp.py +++ b/asv_bench/benchmarks/tslibs/timestamp.py @@ -136,10 +136,10 @@ def time_to_julian_date(self, tz): self.ts.to_julian_date() def time_floor(self, tz): - self.ts.floor("5T") + self.ts.floor("5min") def time_ceil(self, tz): - self.ts.ceil("5T") + self.ts.ceil("5min") class TimestampAcrossDst: diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index 1a891dca839e3..5def84b91705c 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -610,7 +610,7 @@ financial applications. See the :ref:`Time Series section `. .. ipython:: python - rng = pd.date_range("1/1/2012", periods=100, freq="S") + rng = pd.date_range("1/1/2012", periods=100, freq="s") ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng) ts.resample("5Min").sum() diff --git a/doc/source/user_guide/scale.rst b/doc/source/user_guide/scale.rst index bc49c7f958cb7..b262de5d71439 100644 --- a/doc/source/user_guide/scale.rst +++ b/doc/source/user_guide/scale.rst @@ -40,7 +40,7 @@ Suppose our raw dataset on disk has many columns. return df timeseries = [ - make_timeseries(freq="1T", seed=i).rename(columns=lambda x: f"{x}_{i}") + make_timeseries(freq="1min", seed=i).rename(columns=lambda x: f"{x}_{i}") for i in range(10) ] ts_wide = pd.concat(timeseries, axis=1) @@ -87,7 +87,7 @@ can store larger datasets in memory. .. ipython:: python :okwarning: - ts = make_timeseries(freq="30S", seed=0) + ts = make_timeseries(freq="30s", seed=0) ts.to_parquet("timeseries.parquet") ts = pd.read_parquet("timeseries.parquet") ts @@ -173,7 +173,7 @@ files. Each file in the directory represents a different year of the entire data pathlib.Path("data/timeseries").mkdir(exist_ok=True) for i, (start, end) in enumerate(zip(starts, ends)): - ts = make_timeseries(start=start, end=end, freq="1T", seed=i) + ts = make_timeseries(start=start, end=end, freq="1min", seed=i) ts.to_parquet(f"data/timeseries/ts-{i:0>2d}.parquet") diff --git a/doc/source/user_guide/timedeltas.rst b/doc/source/user_guide/timedeltas.rst index a6eb96f91a4bf..cd567f8442671 100644 --- a/doc/source/user_guide/timedeltas.rst +++ b/doc/source/user_guide/timedeltas.rst @@ -390,7 +390,7 @@ The ``freq`` parameter can passed a variety of :ref:`frequency aliases int: ... def periods_per_second(reso: int) -> int: ... diff --git a/pandas/_libs/tslibs/dtypes.pyx b/pandas/_libs/tslibs/dtypes.pyx index 19f4c83e6cecf..bafde9f3b237b 100644 --- a/pandas/_libs/tslibs/dtypes.pyx +++ b/pandas/_libs/tslibs/dtypes.pyx @@ -1,6 +1,9 @@ # period frequency constants corresponding to scikits timeseries # originals from enum import Enum +import warnings + +from pandas.util._exceptions import find_stack_level from pandas._libs.tslibs.np_datetime cimport ( NPY_DATETIMEUNIT, @@ -141,11 +144,11 @@ _period_code_map = { "B": PeriodDtypeCode.B, # Business days "D": PeriodDtypeCode.D, # Daily "H": PeriodDtypeCode.H, # Hourly - "T": PeriodDtypeCode.T, # Minutely - "S": PeriodDtypeCode.S, # Secondly - "L": PeriodDtypeCode.L, # Millisecondly - "U": PeriodDtypeCode.U, # Microsecondly - "N": PeriodDtypeCode.N, # Nanosecondly + "min": PeriodDtypeCode.T, # Minutely + "s": PeriodDtypeCode.S, # Secondly + "ms": PeriodDtypeCode.L, # Millisecondly + "us": PeriodDtypeCode.U, # Microsecondly + "ns": PeriodDtypeCode.N, # Nanosecondly } _reverse_period_code_map = { @@ -174,15 +177,29 @@ _attrname_to_abbrevs = { "month": "M", "day": "D", "hour": "H", - "minute": "T", - "second": "S", - "millisecond": "L", - "microsecond": "U", - "nanosecond": "N", + "minute": "min", + "second": "s", + "millisecond": "ms", + "microsecond": "us", + "nanosecond": "ns", } cdef dict attrname_to_abbrevs = _attrname_to_abbrevs cdef dict _abbrev_to_attrnames = {v: k for k, v in attrname_to_abbrevs.items()} +# Map deprecated resolution abbreviations to correct resolution abbreviations +DEPR_ABBREVS: dict[str, str]= { + "T": "min", + "t": "min", + "S": "s", + "L": "ms", + "l": "ms", + "U": "us", + "u": "us", + "N": "ns", + "n": "ns", +} +cdef dict c_DEPR_ABBREVS = DEPR_ABBREVS + class FreqGroup(Enum): # Mirrors c_FreqGroup in the .pxd file @@ -273,6 +290,15 @@ class Resolution(Enum): True """ try: + if freq in DEPR_ABBREVS: + warnings.warn( + f"\'{freq}\' is deprecated and will be removed in a future " + f"version. Please use \'{DEPR_ABBREVS.get(freq)}\' " + "instead of \'{freq}\'.", + FutureWarning, + stacklevel=find_stack_level(), + ) + freq = DEPR_ABBREVS[freq] attr_name = _abbrev_to_attrnames[freq] except KeyError: # For quarterly and yearly resolutions, we need to chop off @@ -283,6 +309,15 @@ class Resolution(Enum): if split_freq[1] not in _month_names: # i.e. we want e.g. "Q-DEC", not "Q-INVALID" raise + if split_freq[0] in DEPR_ABBREVS: + warnings.warn( + f"\'{split_freq[0]}\' is deprecated and will be removed in a " + f"future version. Please use \'{DEPR_ABBREVS.get(split_freq[0])}\' " + f"instead of \'{split_freq[0]}\'.", + FutureWarning, + stacklevel=find_stack_level(), + ) + split_freq[0] = DEPR_ABBREVS[split_freq[0]] attr_name = _abbrev_to_attrnames[split_freq[0]] return cls.from_attrname(attr_name) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 7d75fa3114d2b..bb497f2e17b93 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -1003,23 +1003,23 @@ timedelta}, default 'raise' >>> ts.round(freq='H') # hour Timestamp('2020-03-14 16:00:00') - >>> ts.round(freq='T') # minute + >>> ts.round(freq='min') # minute Timestamp('2020-03-14 15:33:00') - >>> ts.round(freq='S') # seconds + >>> ts.round(freq='s') # seconds Timestamp('2020-03-14 15:32:52') - >>> ts.round(freq='L') # milliseconds + >>> ts.round(freq='ms') # milliseconds Timestamp('2020-03-14 15:32:52.193000') - ``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes): + ``freq`` can also be a multiple of a single unit, like '5min' (i.e. 5 minutes): - >>> ts.round(freq='5T') + >>> ts.round(freq='5min') Timestamp('2020-03-14 15:35:00') - or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes): + or a combination of multiple units, like '1H30min' (i.e. 1 hour and 30 minutes): - >>> ts.round(freq='1H30T') + >>> ts.round(freq='1H30min') Timestamp('2020-03-14 15:00:00') Analogous for ``pd.NaT``: @@ -1092,23 +1092,23 @@ timedelta}, default 'raise' >>> ts.floor(freq='H') # hour Timestamp('2020-03-14 15:00:00') - >>> ts.floor(freq='T') # minute + >>> ts.floor(freq='min') # minute Timestamp('2020-03-14 15:32:00') - >>> ts.floor(freq='S') # seconds + >>> ts.floor(freq='s') # seconds Timestamp('2020-03-14 15:32:52') - >>> ts.floor(freq='N') # nanoseconds + >>> ts.floor(freq='ns') # nanoseconds Timestamp('2020-03-14 15:32:52.192548651') - ``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes): + ``freq`` can also be a multiple of a single unit, like '5min' (i.e. 5 minutes): - >>> ts.floor(freq='5T') + >>> ts.floor(freq='5min') Timestamp('2020-03-14 15:30:00') - or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes): + or a combination of multiple units, like '1H30min' (i.e. 1 hour and 30 minutes): - >>> ts.floor(freq='1H30T') + >>> ts.floor(freq='1H30min') Timestamp('2020-03-14 15:00:00') Analogous for ``pd.NaT``: @@ -1181,23 +1181,23 @@ timedelta}, default 'raise' >>> ts.ceil(freq='H') # hour Timestamp('2020-03-14 16:00:00') - >>> ts.ceil(freq='T') # minute + >>> ts.ceil(freq='min') # minute Timestamp('2020-03-14 15:33:00') - >>> ts.ceil(freq='S') # seconds + >>> ts.ceil(freq='s') # seconds Timestamp('2020-03-14 15:32:53') - >>> ts.ceil(freq='U') # microseconds + >>> ts.ceil(freq='us') # microseconds Timestamp('2020-03-14 15:32:52.192549') - ``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes): + ``freq`` can also be a multiple of a single unit, like '5min' (i.e. 5 minutes): - >>> ts.ceil(freq='5T') + >>> ts.ceil(freq='5min') Timestamp('2020-03-14 15:35:00') - or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes): + or a combination of multiple units, like '1H30min' (i.e. 1 hour and 30 minutes): - >>> ts.ceil(freq='1H30T') + >>> ts.ceil(freq='1H30min') Timestamp('2020-03-14 16:30:00') Analogous for ``pd.NaT``: diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index ac08f57844b9a..7c1187820ea13 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,5 +1,8 @@ import re import time +import warnings + +from pandas.util._exceptions import find_stack_level cimport cython from cpython.datetime cimport ( @@ -50,7 +53,10 @@ from pandas._libs.tslibs.ccalendar cimport ( get_lastbday, ) from pandas._libs.tslibs.conversion cimport localize_pydatetime -from pandas._libs.tslibs.dtypes cimport periods_per_day +from pandas._libs.tslibs.dtypes cimport ( + c_DEPR_ABBREVS, + periods_per_day, +) from pandas._libs.tslibs.nattype cimport ( NPY_NAT, c_NaT as NaT, @@ -621,10 +627,10 @@ cdef class BaseOffset: '2BH' >>> pd.offsets.Nano().freqstr - 'N' + 'ns' >>> pd.offsets.Nano(-3).freqstr - '-3N' + '-3ns' """ try: code = self.rule_code @@ -1191,7 +1197,7 @@ cdef class Minute(Tick): Timestamp('2022-12-09 14:50:00') """ _nanos_inc = 60 * 1_000_000_000 - _prefix = "T" + _prefix = "min" _period_dtype_code = PeriodDtypeCode.T _creso = NPY_DATETIMEUNIT.NPY_FR_m @@ -1227,28 +1233,28 @@ cdef class Second(Tick): Timestamp('2022-12-09 14:59:50') """ _nanos_inc = 1_000_000_000 - _prefix = "S" + _prefix = "s" _period_dtype_code = PeriodDtypeCode.S _creso = NPY_DATETIMEUNIT.NPY_FR_s cdef class Milli(Tick): _nanos_inc = 1_000_000 - _prefix = "L" + _prefix = "ms" _period_dtype_code = PeriodDtypeCode.L _creso = NPY_DATETIMEUNIT.NPY_FR_ms cdef class Micro(Tick): _nanos_inc = 1000 - _prefix = "U" + _prefix = "us" _period_dtype_code = PeriodDtypeCode.U _creso = NPY_DATETIMEUNIT.NPY_FR_us cdef class Nano(Tick): _nanos_inc = 1 - _prefix = "N" + _prefix = "ns" _period_dtype_code = PeriodDtypeCode.N _creso = NPY_DATETIMEUNIT.NPY_FR_ns @@ -4431,16 +4437,16 @@ prefix_mapping = { CustomBusinessHour, # 'CBH' MonthEnd, # 'M' MonthBegin, # 'MS' - Nano, # 'N' + Nano, # 'ns' SemiMonthEnd, # 'SM' SemiMonthBegin, # 'SMS' Week, # 'W' - Second, # 'S' - Minute, # 'T' - Micro, # 'U' + Second, # 's' + Minute, # 'min' + Micro, # 'us' QuarterEnd, # 'Q' QuarterBegin, # 'QS' - Milli, # 'L' + Milli, # 'ms' Hour, # 'H' Day, # 'D' WeekOfMonth, # 'WOM' @@ -4467,14 +4473,14 @@ _lite_rule_alias = { "BAS": "BAS-JAN", # BYearBegin(month=1), "BYS": "BAS-JAN", - "Min": "T", - "min": "T", - "ms": "L", - "us": "U", - "ns": "N", + "Min": "min", + "min": "min", + "ms": "ms", + "us": "us", + "ns": "ns", } -_dont_uppercase = {"MS", "ms"} +_dont_uppercase = {"MS", "ms", "s"} INVALID_FREQ_ERR_MSG = "Invalid frequency: {0}" @@ -4591,7 +4597,16 @@ cpdef to_offset(freq): if not stride: stride = 1 - if prefix in {"D", "H", "T", "S", "L", "U", "N"}: + if prefix in c_DEPR_ABBREVS: + warnings.warn( + f"\'{prefix}\' is deprecated and will be removed in a " + f"future version. Please use \'{c_DEPR_ABBREVS.get(prefix)}\' " + f"instead of \'{prefix}\'.", + FutureWarning, + stacklevel=find_stack_level(), + ) + prefix = c_DEPR_ABBREVS[prefix] + if prefix in {"D", "H", "min", "s", "ms", "us", "ns"}: # For these prefixes, we have something like "3H" or # "2.5T", so we can construct a Timedelta with the # matching unit and get our offset from delta_to_tick diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index ffa9a67542e21..2d9fe93c397cb 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1,6 +1,8 @@ import collections import warnings +from pandas.util._exceptions import find_stack_level + cimport cython from cpython.object cimport ( Py_EQ, @@ -41,6 +43,7 @@ from pandas._libs.tslibs.conversion cimport ( precision_from_unit, ) from pandas._libs.tslibs.dtypes cimport ( + c_DEPR_ABBREVS, get_supported_reso, is_supported_unit, npy_unit_to_abbrev, @@ -124,7 +127,6 @@ cdef dict timedelta_abbrevs = { "minute": "m", "min": "m", "minutes": "m", - "t": "m", "s": "s", "seconds": "s", "sec": "s", @@ -134,20 +136,17 @@ cdef dict timedelta_abbrevs = { "millisecond": "ms", "milli": "ms", "millis": "ms", - "l": "ms", "us": "us", "microseconds": "us", "microsecond": "us", "µs": "us", "micro": "us", "micros": "us", - "u": "us", "ns": "ns", "nanoseconds": "ns", "nano": "ns", "nanos": "ns", "nanosecond": "ns", - "n": "ns", } _no_input = object() @@ -725,6 +724,15 @@ cpdef inline str parse_timedelta_unit(str unit): return "ns" elif unit == "M": return unit + elif unit in c_DEPR_ABBREVS: + warnings.warn( + f"\'{unit}\' is deprecated and will be removed in a " + f"future version. Please use \'{c_DEPR_ABBREVS.get(unit)}\' " + f"instead of \'{unit}\'.", + FutureWarning, + stacklevel=find_stack_level(), + ) + unit = c_DEPR_ABBREVS[unit] try: return timedelta_abbrevs[unit.lower()] except KeyError: @@ -901,7 +909,7 @@ cdef int64_t parse_iso_format_string(str ts) except? -1: elif c == ".": # append any seconds if len(number): - r = timedelta_from_spec(number, "0", "S") + r = timedelta_from_spec(number, "0", "s") result += timedelta_as_neg(r, neg) unit, number = [], [] have_dot = 1 @@ -918,7 +926,7 @@ cdef int64_t parse_iso_format_string(str ts) except? -1: r = timedelta_from_spec(number, "0", dec_unit) result += timedelta_as_neg(r, neg) else: # seconds - r = timedelta_from_spec(number, "0", "S") + r = timedelta_from_spec(number, "0", "s") result += timedelta_as_neg(r, neg) else: raise ValueError(err_msg) @@ -1435,11 +1443,11 @@ cdef class _Timedelta(timedelta): * Days: 'D' * Hours: 'H' - * Minutes: 'T' - * Seconds: 'S' - * Milliseconds: 'L' - * Microseconds: 'U' - * Nanoseconds: 'N' + * Minutes: 'min' + * Seconds: 's' + * Milliseconds: 'ms' + * Microseconds: 'us' + * Nanoseconds: 'ns' Returns ------- @@ -1450,31 +1458,31 @@ cdef class _Timedelta(timedelta): -------- >>> td = pd.Timedelta('1 days 2 min 3 us 42 ns') >>> td.resolution_string - 'N' + 'ns' >>> td = pd.Timedelta('1 days 2 min 3 us') >>> td.resolution_string - 'U' + 'us' >>> td = pd.Timedelta('2 min 3 s') >>> td.resolution_string - 'S' + 's' >>> td = pd.Timedelta(36, unit='us') >>> td.resolution_string - 'U' + 'us' """ self._ensure_components() if self._ns: - return "N" + return "ns" elif self._us: - return "U" + return "us" elif self._ms: - return "L" + return "ms" elif self._s: - return "S" + return "s" elif self._m: - return "T" + return "min" elif self._h: return "H" else: @@ -1706,15 +1714,20 @@ class Timedelta(_Timedelta): Possible values: - * 'W', 'D', 'T', 'S', 'L', 'U', or 'N' - * 'days' or 'day' + * 'W', or 'D' + * 'days', or 'day' * 'hours', 'hour', 'hr', or 'h' * 'minutes', 'minute', 'min', or 'm' - * 'seconds', 'second', or 'sec' - * 'milliseconds', 'millisecond', 'millis', or 'milli' - * 'microseconds', 'microsecond', 'micros', or 'micro' + * 'seconds', 'second', 'sec', or 's' + * 'milliseconds', 'millisecond', 'millis', 'milli', or 'ms' + * 'microseconds', 'microsecond', 'micros', 'micro', or 'us' * 'nanoseconds', 'nanosecond', 'nanos', 'nano', or 'ns'. + .. deprecated:: 2.2.0 + + Values `T`, `S`, `L`, `U`, and `N` are deprecated in favour of the values + `min`, `s`, `ms`, `us`, and `ns`. + **kwargs Available kwargs: {days, seconds, microseconds, milliseconds, minutes, hours, weeks}. diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 844fc8f0ed187..944a2b0e97382 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1997,23 +1997,23 @@ timedelta}, default 'raise' >>> ts.round(freq='H') # hour Timestamp('2020-03-14 16:00:00') - >>> ts.round(freq='T') # minute + >>> ts.round(freq='min') # minute Timestamp('2020-03-14 15:33:00') - >>> ts.round(freq='S') # seconds + >>> ts.round(freq='s') # seconds Timestamp('2020-03-14 15:32:52') - >>> ts.round(freq='L') # milliseconds + >>> ts.round(freq='ms') # milliseconds Timestamp('2020-03-14 15:32:52.193000') - ``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes): + ``freq`` can also be a multiple of a single unit, like '5min' (i.e. 5 minutes): - >>> ts.round(freq='5T') + >>> ts.round(freq='5min') Timestamp('2020-03-14 15:35:00') - or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes): + or a combination of multiple units, like '1H30min' (i.e. 1 hour and 30 minutes): - >>> ts.round(freq='1H30T') + >>> ts.round(freq='1H30min') Timestamp('2020-03-14 15:00:00') Analogous for ``pd.NaT``: @@ -2088,23 +2088,23 @@ timedelta}, default 'raise' >>> ts.floor(freq='H') # hour Timestamp('2020-03-14 15:00:00') - >>> ts.floor(freq='T') # minute + >>> ts.floor(freq='min') # minute Timestamp('2020-03-14 15:32:00') - >>> ts.floor(freq='S') # seconds + >>> ts.floor(freq='s') # seconds Timestamp('2020-03-14 15:32:52') - >>> ts.floor(freq='N') # nanoseconds + >>> ts.floor(freq='ns') # nanoseconds Timestamp('2020-03-14 15:32:52.192548651') - ``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes): + ``freq`` can also be a multiple of a single unit, like '5min' (i.e. 5 minutes): - >>> ts.floor(freq='5T') + >>> ts.floor(freq='5min') Timestamp('2020-03-14 15:30:00') - or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes): + or a combination of multiple units, like '1H30min' (i.e. 1 hour and 30 minutes): - >>> ts.floor(freq='1H30T') + >>> ts.floor(freq='1H30min') Timestamp('2020-03-14 15:00:00') Analogous for ``pd.NaT``: @@ -2177,23 +2177,23 @@ timedelta}, default 'raise' >>> ts.ceil(freq='H') # hour Timestamp('2020-03-14 16:00:00') - >>> ts.ceil(freq='T') # minute + >>> ts.ceil(freq='min') # minute Timestamp('2020-03-14 15:33:00') - >>> ts.ceil(freq='S') # seconds + >>> ts.ceil(freq='s') # seconds Timestamp('2020-03-14 15:32:53') - >>> ts.ceil(freq='U') # microseconds + >>> ts.ceil(freq='us') # microseconds Timestamp('2020-03-14 15:32:52.192549') - ``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes): + ``freq`` can also be a multiple of a single unit, like '5min' (i.e. 5 minutes): - >>> ts.ceil(freq='5T') + >>> ts.ceil(freq='5min') Timestamp('2020-03-14 15:35:00') - or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes): + or a combination of multiple units, like '1H30min' (i.e. 1 hour and 30 minutes): - >>> ts.ceil(freq='1H30T') + >>> ts.ceil(freq='1H30min') Timestamp('2020-03-14 16:30:00') Analogous for ``pd.NaT``: diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 48ff769f6c737..b653f3f4e1eae 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -2462,11 +2462,11 @@ def _round_temporally( "W": "week", "D": "day", "H": "hour", - "T": "minute", - "S": "second", - "L": "millisecond", - "U": "microsecond", - "N": "nanosecond", + "min": "minute", + "s": "second", + "ms": "millisecond", + "us": "microsecond", + "ns": "nanosecond", } unit = pa_supported_unit.get(offset._prefix, None) if unit is None: diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index c3b8d1c0e79e8..dd46e9ebc547f 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -1813,7 +1813,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]: >>> rng DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00', '2018-01-01 12:01:00'], - dtype='datetime64[ns]', freq='T') + dtype='datetime64[ns]', freq='min') """ _round_example = """>>> rng.round('H') diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 8ad51e4a90027..dd2d7c0060392 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1589,7 +1589,7 @@ def isocalendar(self) -> DataFrame: Examples -------- >>> datetime_series = pd.Series( - ... pd.date_range("2000-01-01", periods=3, freq="T") + ... pd.date_range("2000-01-01", periods=3, freq="min") ... ) >>> datetime_series 0 2000-01-01 00:00:00 diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index a81609e1bb618..b7b81b8271106 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -854,7 +854,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]: -------- For Series: - >>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='S')) + >>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='s')) >>> ser 0 0 days 00:00:01 1 0 days 00:00:02 @@ -868,7 +868,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]: For TimedeltaIndex: - >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='S') + >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='s') >>> tdelta_idx TimedeltaIndex(['0 days 00:00:01', '0 days 00:00:02', '0 days 00:00:03'], dtype='timedelta64[ns]', freq=None) @@ -888,7 +888,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]: -------- For Series: - >>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='U')) + >>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='us')) >>> ser 0 0 days 00:00:00.000001 1 0 days 00:00:00.000002 @@ -902,7 +902,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]: For TimedeltaIndex: - >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='U') + >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='us') >>> tdelta_idx TimedeltaIndex(['0 days 00:00:00.000001', '0 days 00:00:00.000002', '0 days 00:00:00.000003'], @@ -923,7 +923,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]: -------- For Series: - >>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='N')) + >>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='ns')) >>> ser 0 0 days 00:00:00.000000001 1 0 days 00:00:00.000000002 @@ -937,7 +937,7 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]: For TimedeltaIndex: - >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='N') + >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='ns') >>> tdelta_idx TimedeltaIndex(['0 days 00:00:00.000000001', '0 days 00:00:00.000000002', '0 days 00:00:00.000000003'], diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 59939057d4b37..3b9cb6741910c 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -61,6 +61,8 @@ is_list_like, ) +from pandas.util import capitalize_first_letter + if not pa_version_under7p0: import pyarrow as pa @@ -1071,7 +1073,7 @@ def na_value(self) -> NaTType: def __eq__(self, other: object) -> bool: if isinstance(other, str): - return other in [self.name, self.name.title()] + return other in [self.name, capitalize_first_letter(self.name)] return super().__eq__(other) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a763d46e11939..baca4e0bc7b6b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -8791,7 +8791,7 @@ def asfreq( -------- Start by creating a series with 4 one minute timestamps. - >>> index = pd.date_range('1/1/2000', periods=4, freq='T') + >>> index = pd.date_range('1/1/2000', periods=4, freq='min') >>> series = pd.Series([0.0, None, 2.0, 3.0], index=index) >>> df = pd.DataFrame({{'s': series}}) >>> df @@ -8803,7 +8803,7 @@ def asfreq( Upsample the series into 30 second bins. - >>> df.asfreq(freq='30S') + >>> df.asfreq(freq='30s') s 2000-01-01 00:00:00 0.0 2000-01-01 00:00:30 NaN @@ -8815,7 +8815,7 @@ def asfreq( Upsample again, providing a ``fill value``. - >>> df.asfreq(freq='30S', fill_value=9.0) + >>> df.asfreq(freq='30s', fill_value=9.0) s 2000-01-01 00:00:00 0.0 2000-01-01 00:00:30 9.0 @@ -8827,7 +8827,7 @@ def asfreq( Upsample again, providing a ``method``. - >>> df.asfreq(freq='30S', method='bfill') + >>> df.asfreq(freq='30s', method='bfill') s 2000-01-01 00:00:00 0.0 2000-01-01 00:00:30 NaN @@ -9103,7 +9103,7 @@ def resample( -------- Start by creating a series with 9 one minute timestamps. - >>> index = pd.date_range('1/1/2000', periods=9, freq='T') + >>> index = pd.date_range('1/1/2000', periods=9, freq='min') >>> series = pd.Series(range(9), index=index) >>> series 2000-01-01 00:00:00 0 @@ -9115,16 +9115,16 @@ def resample( 2000-01-01 00:06:00 6 2000-01-01 00:07:00 7 2000-01-01 00:08:00 8 - Freq: T, dtype: int64 + Freq: min, dtype: int64 Downsample the series into 3 minute bins and sum the values of the timestamps falling into a bin. - >>> series.resample('3T').sum() + >>> series.resample('3min').sum() 2000-01-01 00:00:00 3 2000-01-01 00:03:00 12 2000-01-01 00:06:00 21 - Freq: 3T, dtype: int64 + Freq: 3min, dtype: int64 Downsample the series into 3 minute bins as above, but label each bin using the right edge instead of the left. Please note that the @@ -9136,64 +9136,64 @@ def resample( To include this value close the right side of the bin interval as illustrated in the example below this one. - >>> series.resample('3T', label='right').sum() + >>> series.resample('3min', label='right').sum() 2000-01-01 00:03:00 3 2000-01-01 00:06:00 12 2000-01-01 00:09:00 21 - Freq: 3T, dtype: int64 + Freq: 3min, dtype: int64 Downsample the series into 3 minute bins as above, but close the right side of the bin interval. - >>> series.resample('3T', label='right', closed='right').sum() + >>> series.resample('3min', label='right', closed='right').sum() 2000-01-01 00:00:00 0 2000-01-01 00:03:00 6 2000-01-01 00:06:00 15 2000-01-01 00:09:00 15 - Freq: 3T, dtype: int64 + Freq: 3min, dtype: int64 Upsample the series into 30 second bins. - >>> series.resample('30S').asfreq()[0:5] # Select first 5 rows + >>> series.resample('30s').asfreq()[0:5] # Select first 5 rows 2000-01-01 00:00:00 0.0 2000-01-01 00:00:30 NaN 2000-01-01 00:01:00 1.0 2000-01-01 00:01:30 NaN 2000-01-01 00:02:00 2.0 - Freq: 30S, dtype: float64 + Freq: 30s, dtype: float64 Upsample the series into 30 second bins and fill the ``NaN`` values using the ``ffill`` method. - >>> series.resample('30S').ffill()[0:5] + >>> series.resample('30s').ffill()[0:5] 2000-01-01 00:00:00 0 2000-01-01 00:00:30 0 2000-01-01 00:01:00 1 2000-01-01 00:01:30 1 2000-01-01 00:02:00 2 - Freq: 30S, dtype: int64 + Freq: 30s, dtype: int64 Upsample the series into 30 second bins and fill the ``NaN`` values using the ``bfill`` method. - >>> series.resample('30S').bfill()[0:5] + >>> series.resample('30s').bfill()[0:5] 2000-01-01 00:00:00 0 2000-01-01 00:00:30 1 2000-01-01 00:01:00 1 2000-01-01 00:01:30 2 2000-01-01 00:02:00 2 - Freq: 30S, dtype: int64 + Freq: 30s, dtype: int64 Pass a custom function via ``apply`` >>> def custom_resampler(arraylike): ... return np.sum(arraylike) + 5 ... - >>> series.resample('3T').apply(custom_resampler) + >>> series.resample('3min').apply(custom_resampler) 2000-01-01 00:00:00 8 2000-01-01 00:03:00 17 2000-01-01 00:06:00 26 - Freq: 3T, dtype: int64 + Freq: 3min, dtype: int64 For a Series with a PeriodIndex, the keyword `convention` can be used to control whether to use the start or end of `rule`. @@ -9313,7 +9313,7 @@ def resample( 2000-10-02 00:12:00 18 2000-10-02 00:19:00 21 2000-10-02 00:26:00 24 - Freq: 7T, dtype: int64 + Freq: 7min, dtype: int64 >>> ts.resample('17min').sum() 2000-10-01 23:14:00 0 @@ -9321,7 +9321,7 @@ def resample( 2000-10-01 23:48:00 21 2000-10-02 00:05:00 54 2000-10-02 00:22:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 >>> ts.resample('17min', origin='epoch').sum() 2000-10-01 23:18:00 0 @@ -9329,7 +9329,7 @@ def resample( 2000-10-01 23:52:00 27 2000-10-02 00:09:00 39 2000-10-02 00:26:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 >>> ts.resample('17W', origin='2000-01-01').sum() 2000-01-02 0 @@ -9346,14 +9346,14 @@ def resample( 2000-10-01 23:47:00 21 2000-10-02 00:04:00 54 2000-10-02 00:21:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 >>> ts.resample('17min', offset='23h30min').sum() 2000-10-01 23:30:00 9 2000-10-01 23:47:00 21 2000-10-02 00:04:00 54 2000-10-02 00:21:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 If you want to take the largest Timestamp as the end of the bins: @@ -9362,7 +9362,7 @@ def resample( 2000-10-01 23:52:00 18 2000-10-02 00:09:00 27 2000-10-02 00:26:00 63 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 In contrast with the `start_day`, you can use `end_day` to take the ceiling midnight of the largest Timestamp as the end of the bins and drop the bins @@ -9373,7 +9373,7 @@ def resample( 2000-10-01 23:55:00 15 2000-10-02 00:12:00 45 2000-10-02 00:29:00 45 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 """ from pandas.core.resample import get_resampler diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 49b47545d6297..68cca0f66a9f0 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -3550,7 +3550,7 @@ def resample(self, rule, *args, **kwargs): Examples -------- - >>> idx = pd.date_range('1/1/2000', periods=4, freq='T') + >>> idx = pd.date_range('1/1/2000', periods=4, freq='min') >>> df = pd.DataFrame(data=4 * [range(2)], ... index=idx, ... columns=['a', 'b']) @@ -3565,7 +3565,7 @@ def resample(self, rule, *args, **kwargs): Downsample the DataFrame into 3 minute bins and sum the values of the timestamps falling into a bin. - >>> df.groupby('a').resample('3T').sum() + >>> df.groupby('a').resample('3min').sum() a b a 0 2000-01-01 00:00:00 0 2 @@ -3574,7 +3574,7 @@ def resample(self, rule, *args, **kwargs): Upsample the series into 30 second bins. - >>> df.groupby('a').resample('30S').sum() + >>> df.groupby('a').resample('30s').sum() a b a 0 2000-01-01 00:00:00 0 1 @@ -3597,7 +3597,7 @@ def resample(self, rule, *args, **kwargs): Downsample the series into 3 minute bins as above, but close the right side of the bin interval. - >>> df.groupby('a').resample('3T', closed='right').sum() + >>> df.groupby('a').resample('3min', closed='right').sum() a b a 0 1999-12-31 23:57:00 0 1 @@ -3608,7 +3608,7 @@ def resample(self, rule, *args, **kwargs): the bin interval, but label each bin using the right edge instead of the left. - >>> df.groupby('a').resample('3T', closed='right', label='right').sum() + >>> df.groupby('a').resample('3min', closed='right', label='right').sum() a b a 0 2000-01-01 00:00:00 0 1 diff --git a/pandas/core/groupby/grouper.py b/pandas/core/groupby/grouper.py index 95cb114c1472a..add6c3ac4ec20 100644 --- a/pandas/core/groupby/grouper.py +++ b/pandas/core/groupby/grouper.py @@ -189,7 +189,7 @@ class Grouper: 2000-10-02 00:12:00 18 2000-10-02 00:19:00 21 2000-10-02 00:26:00 24 - Freq: 7T, dtype: int64 + Freq: 7min, dtype: int64 >>> ts.groupby(pd.Grouper(freq='17min')).sum() 2000-10-01 23:14:00 0 @@ -197,7 +197,7 @@ class Grouper: 2000-10-01 23:48:00 21 2000-10-02 00:05:00 54 2000-10-02 00:22:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 >>> ts.groupby(pd.Grouper(freq='17min', origin='epoch')).sum() 2000-10-01 23:18:00 0 @@ -205,7 +205,7 @@ class Grouper: 2000-10-01 23:52:00 27 2000-10-02 00:09:00 39 2000-10-02 00:26:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 >>> ts.groupby(pd.Grouper(freq='17W', origin='2000-01-01')).sum() 2000-01-02 0 @@ -222,14 +222,14 @@ class Grouper: 2000-10-01 23:47:00 21 2000-10-02 00:04:00 54 2000-10-02 00:21:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 >>> ts.groupby(pd.Grouper(freq='17min', offset='23h30min')).sum() 2000-10-01 23:30:00 9 2000-10-01 23:47:00 21 2000-10-02 00:04:00 54 2000-10-02 00:21:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 To replace the use of the deprecated `base` argument, you can now use `offset`, in this example it is equivalent to have `base=2`: @@ -240,7 +240,7 @@ class Grouper: 2000-10-01 23:50:00 36 2000-10-02 00:07:00 39 2000-10-02 00:24:00 24 - Freq: 17T, dtype: int64 + Freq: 17min, dtype: int64 """ sort: bool diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index d972983532e3c..5134c506b8c61 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -414,7 +414,7 @@ class TimedeltaProperties(Properties): Examples -------- >>> seconds_series = pd.Series( - ... pd.timedelta_range(start="1 second", periods=3, freq="S") + ... pd.timedelta_range(start="1 second", periods=3, freq="s") ... ) >>> seconds_series 0 0 days 00:00:01 @@ -528,7 +528,7 @@ class PeriodProperties(Properties): 1 2000-01-01 00:00:01 2 2000-01-01 00:00:02 3 2000-01-01 00:00:03 - dtype: period[S] + dtype: period[s] >>> seconds_series.dt.second 0 0 1 1 diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 9b8d1c870091d..e45cff0b0679f 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -296,7 +296,7 @@ def pipe( 2013-01-01 00:00:02 3 2013-01-01 00:00:03 4 2013-01-01 00:00:04 5 - Freq: S, dtype: int64 + Freq: s, dtype: int64 >>> r = s.resample('2s') @@ -304,7 +304,7 @@ def pipe( 2013-01-01 00:00:00 3 2013-01-01 00:00:02 7 2013-01-01 00:00:04 5 - Freq: 2S, dtype: int64 + Freq: 2s, dtype: int64 >>> r.agg(['sum', 'mean', 'max']) sum mean max @@ -605,7 +605,7 @@ def nearest(self, limit: int | None = None): 2018-01-01 00:30:00 2 2018-01-01 00:45:00 2 2018-01-01 01:00:00 2 - Freq: 15T, dtype: int64 + Freq: 15min, dtype: int64 Limit the number of upsampled values imputed by the nearest: @@ -615,7 +615,7 @@ def nearest(self, limit: int | None = None): 2018-01-01 00:30:00 NaN 2018-01-01 00:45:00 2.0 2018-01-01 01:00:00 2.0 - Freq: 15T, dtype: float64 + Freq: 15min, dtype: float64 """ return self._upsample("nearest", limit=limit) @@ -674,7 +674,7 @@ def bfill(self, limit: int | None = None): 2018-01-01 01:00:00 2 2018-01-01 01:30:00 3 2018-01-01 02:00:00 3 - Freq: 30T, dtype: int64 + Freq: 30min, dtype: int64 >>> s.resample('15min').bfill(limit=2) 2018-01-01 00:00:00 1.0 @@ -686,7 +686,7 @@ def bfill(self, limit: int | None = None): 2018-01-01 01:30:00 3.0 2018-01-01 01:45:00 3.0 2018-01-01 02:00:00 3.0 - Freq: 15T, dtype: float64 + Freq: 15min, dtype: float64 Resampling a DataFrame that has missing values: @@ -787,7 +787,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 2.0 2018-01-01 01:30:00 NaN 2018-01-01 02:00:00 3.0 - Freq: 30T, dtype: float64 + Freq: 30min, dtype: float64 >>> s.resample('30min').fillna("backfill") 2018-01-01 00:00:00 1 @@ -795,7 +795,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 2 2018-01-01 01:30:00 3 2018-01-01 02:00:00 3 - Freq: 30T, dtype: int64 + Freq: 30min, dtype: int64 >>> s.resample('15min').fillna("backfill", limit=2) 2018-01-01 00:00:00 1.0 @@ -807,7 +807,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:30:00 3.0 2018-01-01 01:45:00 3.0 2018-01-01 02:00:00 3.0 - Freq: 15T, dtype: float64 + Freq: 15min, dtype: float64 >>> s.resample('30min').fillna("pad") 2018-01-01 00:00:00 1 @@ -815,7 +815,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 2 2018-01-01 01:30:00 2 2018-01-01 02:00:00 3 - Freq: 30T, dtype: int64 + Freq: 30min, dtype: int64 >>> s.resample('30min').fillna("nearest") 2018-01-01 00:00:00 1 @@ -823,7 +823,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 2 2018-01-01 01:30:00 3 2018-01-01 02:00:00 3 - Freq: 30T, dtype: int64 + Freq: 30min, dtype: int64 Missing values present before the upsampling are not affected. @@ -841,7 +841,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 NaN 2018-01-01 01:30:00 3.0 2018-01-01 02:00:00 3.0 - Freq: 30T, dtype: float64 + Freq: 30min, dtype: float64 >>> sm.resample('30min').fillna('pad') 2018-01-01 00:00:00 1.0 @@ -849,7 +849,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 NaN 2018-01-01 01:30:00 NaN 2018-01-01 02:00:00 3.0 - Freq: 30T, dtype: float64 + Freq: 30min, dtype: float64 >>> sm.resample('30min').fillna('nearest') 2018-01-01 00:00:00 1.0 @@ -857,7 +857,7 @@ def fillna(self, method, limit: int | None = None): 2018-01-01 01:00:00 NaN 2018-01-01 01:30:00 3.0 2018-01-01 02:00:00 3.0 - Freq: 30T, dtype: float64 + Freq: 30min, dtype: float64 DataFrame resampling is done column-wise. All the same options are available. @@ -1018,7 +1018,7 @@ def interpolate( 2023-03-01 07:00:00 1 2023-03-01 07:00:02 2 2023-03-01 07:00:04 3 - Freq: 2S, dtype: int64 + Freq: 2s, dtype: int64 Downsample the dataframe to 2Hz by providing the period time of 500ms. @@ -1032,7 +1032,7 @@ def interpolate( 2023-03-01 07:00:03.000 1.0 2023-03-01 07:00:03.500 2.0 2023-03-01 07:00:04.000 3.0 - Freq: 500L, dtype: float64 + Freq: 500ms, dtype: float64 Internal reindexing with ``as_freq()`` prior to interpolation leads to an interpolated timeseries on the basis the reindexed timestamps (anchors). @@ -1051,7 +1051,7 @@ def interpolate( 2023-03-01 07:00:03.200 2.6 2023-03-01 07:00:03.600 2.8 2023-03-01 07:00:04.000 3.0 - Freq: 400L, dtype: float64 + Freq: 400ms, dtype: float64 Note that the series erroneously increases between two anchors ``07:00:00`` and ``07:00:02``. diff --git a/pandas/core/tools/timedeltas.py b/pandas/core/tools/timedeltas.py index 3f2f832c08dc6..a9abc0714baa3 100644 --- a/pandas/core/tools/timedeltas.py +++ b/pandas/core/tools/timedeltas.py @@ -7,7 +7,6 @@ TYPE_CHECKING, overload, ) -import warnings import numpy as np @@ -20,7 +19,6 @@ Timedelta, parse_timedelta_unit, ) -from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import is_list_like from pandas.core.dtypes.dtypes import ArrowDtype @@ -115,15 +113,17 @@ def to_timedelta( * 'D' / 'days' / 'day' * 'hours' / 'hour' / 'hr' / 'h' * 'm' / 'minute' / 'min' / 'minutes' / 'T' - * 'S' / 'seconds' / 'sec' / 'second' + * 's' / 'seconds' / 'sec' / 'second' / 'S' * 'ms' / 'milliseconds' / 'millisecond' / 'milli' / 'millis' / 'L' * 'us' / 'microseconds' / 'microsecond' / 'micro' / 'micros' / 'U' * 'ns' / 'nanoseconds' / 'nano' / 'nanos' / 'nanosecond' / 'N' Must not be specified when `arg` context strings and ``errors="raise"``. - .. deprecated:: 2.1.0 - Units 'T' and 'L' are deprecated and will be removed in a future version. + .. deprecated:: 2.2.0 + Units 'T', 'S', 'L', 'U' and 'N' are deprecated and will be removed + in a future version. Please use 'min', 's', 'ms', 'us', and 'ns' instead of + 'T', 'S', 'L', 'U' and 'N'. errors : {'ignore', 'raise', 'coerce'}, default 'raise' - If 'raise', then invalid parsing will raise an exception. @@ -176,13 +176,6 @@ def to_timedelta( TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq=None) """ - if unit in {"T", "t", "L", "l"}: - warnings.warn( - f"Unit '{unit}' is deprecated and will be removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(), - ) - if unit is not None: unit = parse_timedelta_unit(unit) diff --git a/pandas/plotting/_matplotlib/converter.py b/pandas/plotting/_matplotlib/converter.py index cd7823ba15e44..33aeaa6d81406 100644 --- a/pandas/plotting/_matplotlib/converter.py +++ b/pandas/plotting/_matplotlib/converter.py @@ -412,7 +412,7 @@ def __call__(self): ) interval = self._get_interval() - freq = f"{interval}L" + freq = f"{interval}ms" tz = self.tz.tzname(None) st = dmin.replace(tzinfo=None) ed = dmin.replace(tzinfo=None) diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index 7a079ae7795e6..2a34566d2f9f5 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -698,7 +698,7 @@ def test_sub_n_gt_1_offsets(self, offset, kwd_name, n): # datetime-like arrays pd.date_range("2016-01-01", periods=3, freq="H"), pd.date_range("2016-01-01", periods=3, tz="Europe/Brussels"), - pd.date_range("2016-01-01", periods=3, freq="S")._data, + pd.date_range("2016-01-01", periods=3, freq="s")._data, pd.date_range("2016-01-01", periods=3, tz="Asia/Tokyo")._data, # Miscellaneous invalid types 3.14, @@ -794,13 +794,13 @@ def test_parr_sub_td64array(self, box_with_array, tdi_freq, pi_freq): if pi_freq == "H": result = pi - td64obj - expected = (pi.to_timestamp("S") - tdi).to_period(pi_freq) + expected = (pi.to_timestamp("s") - tdi).to_period(pi_freq) expected = tm.box_expected(expected, xbox) tm.assert_equal(result, expected) # Subtract from scalar result = pi[0] - td64obj - expected = (pi[0].to_timestamp("S") - tdi).to_period(pi_freq) + expected = (pi[0].to_timestamp("s") - tdi).to_period(pi_freq) expected = tm.box_expected(expected, box) tm.assert_equal(result, expected) @@ -1048,7 +1048,7 @@ def test_parr_add_timedeltalike_minute_gt1(self, three_days, box_with_array): with pytest.raises(TypeError, match=msg): other - rng - @pytest.mark.parametrize("freqstr", ["5ns", "5us", "5ms", "5s", "5T", "5h", "5d"]) + @pytest.mark.parametrize("freqstr", ["5ns", "5us", "5ms", "5s", "5min", "5h", "5d"]) def test_parr_add_timedeltalike_tick_gt1(self, three_days, freqstr, box_with_array): # GH#23031 adding a time-delta-like offset to a PeriodArray that has # tick-like frequency with n != 1 diff --git a/pandas/tests/arrays/test_datetimelike.py b/pandas/tests/arrays/test_datetimelike.py index 9eee2e0bea687..ee1b26054ea5e 100644 --- a/pandas/tests/arrays/test_datetimelike.py +++ b/pandas/tests/arrays/test_datetimelike.py @@ -622,13 +622,13 @@ def test_round(self, arr1d): # GH#24064 dti = self.index_cls(arr1d) - result = dti.round(freq="2T") + result = dti.round(freq="2min") expected = dti - pd.Timedelta(minutes=1) expected = expected._with_freq(None) tm.assert_index_equal(result, expected) dta = dti._data - result = dta.round(freq="2T") + result = dta.round(freq="2min") expected = expected._data._with_freq(None) tm.assert_datetime_array_equal(result, expected) diff --git a/pandas/tests/copy_view/test_methods.py b/pandas/tests/copy_view/test_methods.py index fe1be2d8b6a0a..76b974330cbf1 100644 --- a/pandas/tests/copy_view/test_methods.py +++ b/pandas/tests/copy_view/test_methods.py @@ -1541,10 +1541,10 @@ def test_chained_where_mask(using_copy_on_write, func): def test_asfreq_noop(using_copy_on_write): df = DataFrame( {"a": [0.0, None, 2.0, 3.0]}, - index=date_range("1/1/2000", periods=4, freq="T"), + index=date_range("1/1/2000", periods=4, freq="min"), ) df_orig = df.copy() - df2 = df.asfreq(freq="T") + df2 = df.asfreq(freq="min") if using_copy_on_write: assert np.shares_memory(get_array(df2, "a"), get_array(df, "a")) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 471e456146178..da69d58066e22 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -94,10 +94,10 @@ def test_categorical_dtype(self): [ "period[D]", "period[3M]", - "period[U]", + "period[us]", "Period[D]", "Period[3M]", - "Period[U]", + "Period[us]", ], ) def test_period_dtype(self, dtype): diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index f57093c29b733..6562074eee634 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -467,8 +467,8 @@ def test_identity(self): assert PeriodDtype("period[3D]") == PeriodDtype("period[3D]") assert PeriodDtype("period[3D]") is not PeriodDtype("period[3D]") - assert PeriodDtype("period[1S1U]") == PeriodDtype("period[1000001U]") - assert PeriodDtype("period[1S1U]") is not PeriodDtype("period[1000001U]") + assert PeriodDtype("period[1s1us]") == PeriodDtype("period[1000001us]") + assert PeriodDtype("period[1s1us]") is not PeriodDtype("period[1000001us]") def test_compat(self, dtype): assert not is_datetime64_ns_dtype(dtype) @@ -505,15 +505,15 @@ def test_is_dtype(self, dtype): assert PeriodDtype.is_dtype("period[D]") assert PeriodDtype.is_dtype("period[3D]") assert PeriodDtype.is_dtype(PeriodDtype("3D")) - assert PeriodDtype.is_dtype("period[U]") - assert PeriodDtype.is_dtype("period[S]") - assert PeriodDtype.is_dtype(PeriodDtype("U")) - assert PeriodDtype.is_dtype(PeriodDtype("S")) + assert PeriodDtype.is_dtype("period[us]") + assert PeriodDtype.is_dtype("period[s]") + assert PeriodDtype.is_dtype(PeriodDtype("us")) + assert PeriodDtype.is_dtype(PeriodDtype("s")) assert not PeriodDtype.is_dtype("D") assert not PeriodDtype.is_dtype("3D") assert not PeriodDtype.is_dtype("U") - assert not PeriodDtype.is_dtype("S") + assert not PeriodDtype.is_dtype("s") assert not PeriodDtype.is_dtype("foo") assert not PeriodDtype.is_dtype(np.object_) assert not PeriodDtype.is_dtype(np.int64) @@ -728,7 +728,7 @@ def test_is_dtype(self, dtype): assert not IntervalDtype.is_dtype("D") assert not IntervalDtype.is_dtype("3D") - assert not IntervalDtype.is_dtype("U") + assert not IntervalDtype.is_dtype("us") assert not IntervalDtype.is_dtype("S") assert not IntervalDtype.is_dtype("foo") assert not IntervalDtype.is_dtype("IntervalA") diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index f9c420607812c..432c86ce3afd5 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -2497,7 +2497,7 @@ def test_dt_roundlike_unsupported_freq(method): @pytest.mark.xfail( pa_version_under7p0, reason="Methods not supported for pyarrow < 7.0" ) -@pytest.mark.parametrize("freq", ["D", "H", "T", "S", "L", "U", "N"]) +@pytest.mark.parametrize("freq", ["D", "H", "min", "s", "ms", "us", "ns"]) @pytest.mark.parametrize("method", ["ceil", "floor", "round"]) def test_dt_ceil_year_floor(freq, method): ser = pd.Series( diff --git a/pandas/tests/frame/methods/test_asfreq.py b/pandas/tests/frame/methods/test_asfreq.py index 2c5137db94c16..72652df2e1e58 100644 --- a/pandas/tests/frame/methods/test_asfreq.py +++ b/pandas/tests/frame/methods/test_asfreq.py @@ -76,7 +76,7 @@ def test_tz_aware_asfreq_smoke(self, tz, frame_or_series): ) # it works! - obj.asfreq("T") + obj.asfreq("min") def test_asfreq_normalize(self, frame_or_series): rng = date_range("1/1/2000 09:30", periods=20) @@ -170,7 +170,7 @@ def test_asfreq_fillvalue(self): # test for fill value during upsampling, related to issue 3715 # setup - rng = date_range("1/1/2016", periods=10, freq="2S") + rng = date_range("1/1/2016", periods=10, freq="2s") # Explicit cast to 'float' to avoid implicit cast when setting None ts = Series(np.arange(len(rng)), index=rng, dtype="float") df = DataFrame({"one": ts}) @@ -178,13 +178,13 @@ def test_asfreq_fillvalue(self): # insert pre-existing missing value df.loc["2016-01-01 00:00:08", "one"] = None - actual_df = df.asfreq(freq="1S", fill_value=9.0) - expected_df = df.asfreq(freq="1S").fillna(9.0) + actual_df = df.asfreq(freq="1s", fill_value=9.0) + expected_df = df.asfreq(freq="1s").fillna(9.0) expected_df.loc["2016-01-01 00:00:08", "one"] = None tm.assert_frame_equal(expected_df, actual_df) - expected_series = ts.asfreq(freq="1S").fillna(9.0) - actual_series = ts.asfreq(freq="1S", fill_value=9.0) + expected_series = ts.asfreq(freq="1s").fillna(9.0) + actual_series = ts.asfreq(freq="1s", fill_value=9.0) tm.assert_series_equal(expected_series, actual_series) def test_asfreq_with_date_object_index(self, frame_or_series): diff --git a/pandas/tests/frame/methods/test_equals.py b/pandas/tests/frame/methods/test_equals.py index 4028a26dfdc65..6fcf670f96ef0 100644 --- a/pandas/tests/frame/methods/test_equals.py +++ b/pandas/tests/frame/methods/test_equals.py @@ -35,7 +35,7 @@ def test_equals(self): np.random.default_rng(2).random(10), index=index, columns=["floats"] ) df1["text"] = "the sky is so blue. we could use more chocolate.".split() - df1["start"] = date_range("2000-1-1", periods=10, freq="T") + df1["start"] = date_range("2000-1-1", periods=10, freq="min") df1["end"] = date_range("2000-1-1", periods=10, freq="D") df1["diff"] = df1["end"] - df1["start"] # Explicitly cast to object, to avoid implicit cast when setting np.nan @@ -66,7 +66,7 @@ def test_equals(self): assert not df1.equals(different) # DatetimeIndex - index = date_range("2000-1-1", periods=10, freq="T") + index = date_range("2000-1-1", periods=10, freq="min") df1 = df1.set_index(index) df2 = df1.copy() assert df1.equals(df2) diff --git a/pandas/tests/frame/methods/test_join.py b/pandas/tests/frame/methods/test_join.py index 98f3926968ad0..2d4ac1d4a4444 100644 --- a/pandas/tests/frame/methods/test_join.py +++ b/pandas/tests/frame/methods/test_join.py @@ -553,13 +553,13 @@ def test_frame_join_tzaware(self): test1 = DataFrame( np.zeros((6, 3)), index=date_range( - "2012-11-15 00:00:00", periods=6, freq="100L", tz="US/Central" + "2012-11-15 00:00:00", periods=6, freq="100ms", tz="US/Central" ), ) test2 = DataFrame( np.zeros((3, 3)), index=date_range( - "2012-11-15 00:00:00", periods=3, freq="250L", tz="US/Central" + "2012-11-15 00:00:00", periods=3, freq="250ms", tz="US/Central" ), columns=range(3, 6), ) diff --git a/pandas/tests/frame/methods/test_shift.py b/pandas/tests/frame/methods/test_shift.py index 808f0cff2485c..9b2190dd763f8 100644 --- a/pandas/tests/frame/methods/test_shift.py +++ b/pandas/tests/frame/methods/test_shift.py @@ -75,8 +75,8 @@ def test_shift_mismatched_freq(self, frame_or_series): index=date_range("1/1/2000", periods=5, freq="H"), ) - result = ts.shift(1, freq="5T") - exp_index = ts.index.shift(1, freq="5T") + result = ts.shift(1, freq="5min") + exp_index = ts.index.shift(1, freq="5min") tm.assert_index_equal(result.index, exp_index) # GH#1063, multiple of same base diff --git a/pandas/tests/frame/methods/test_to_records.py b/pandas/tests/frame/methods/test_to_records.py index 8853d718270f4..e18f236d40804 100644 --- a/pandas/tests/frame/methods/test_to_records.py +++ b/pandas/tests/frame/methods/test_to_records.py @@ -512,7 +512,7 @@ def keys(self): @pytest.mark.parametrize("tz", ["UTC", "GMT", "US/Eastern"]) def test_to_records_datetimeindex_with_tz(self, tz): # GH#13937 - dr = date_range("2016-01-01", periods=10, freq="S", tz=tz) + dr = date_range("2016-01-01", periods=10, freq="s", tz=tz) df = DataFrame({"datetime": dr}, index=dr) diff --git a/pandas/tests/frame/methods/test_to_timestamp.py b/pandas/tests/frame/methods/test_to_timestamp.py index 2f73e3d58b516..e72b576fca833 100644 --- a/pandas/tests/frame/methods/test_to_timestamp.py +++ b/pandas/tests/frame/methods/test_to_timestamp.py @@ -99,7 +99,7 @@ def test_to_timestamp_columns(self): tm.assert_index_equal(result.columns, exp_index) delta = timedelta(hours=23, minutes=59) - result = df.to_timestamp("T", "end", axis=1) + result = df.to_timestamp("min", "end", axis=1) exp_index = _get_with_delta(delta) exp_index = exp_index + Timedelta(1, "m") - Timedelta(1, "ns") tm.assert_index_equal(result.columns, exp_index) @@ -110,8 +110,8 @@ def test_to_timestamp_columns(self): exp_index = exp_index + Timedelta(1, "s") - Timedelta(1, "ns") tm.assert_index_equal(result.columns, exp_index) - result1 = df.to_timestamp("5t", axis=1) - result2 = df.to_timestamp("t", axis=1) + result1 = df.to_timestamp("5min", axis=1) + result2 = df.to_timestamp("min", axis=1) expected = date_range("2001-01-01", "2009-01-01", freq="AS") assert isinstance(result1.columns, DatetimeIndex) assert isinstance(result2.columns, DatetimeIndex) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 63cddb7f192e6..009a053dd64d6 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2961,7 +2961,9 @@ def test_frame_datetime64_mixed_index_ctor_1681(self): def test_frame_timeseries_column(self): # GH19157 - dr = date_range(start="20130101T10:00:00", periods=3, freq="T", tz="US/Eastern") + dr = date_range( + start="20130101T10:00:00", periods=3, freq="min", tz="US/Eastern" + ) result = DataFrame(dr, columns=["timestamps"]) expected = DataFrame( { diff --git a/pandas/tests/generic/test_frame.py b/pandas/tests/generic/test_frame.py index 620d5055f5d3b..fc7aa9e7b2c46 100644 --- a/pandas/tests/generic/test_frame.py +++ b/pandas/tests/generic/test_frame.py @@ -87,7 +87,7 @@ def test_metadata_propagation_indiv_resample(self): np.random.default_rng(2).standard_normal((1000, 2)), index=date_range("20130101", periods=1000, freq="s"), ) - result = df.resample("1T") + result = df.resample("1min") tm.assert_metadata_equivalent(df, result) def test_metadata_propagation_indiv(self, monkeypatch): diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 4ea205ac13c47..3648961eb3808 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -111,13 +111,13 @@ def test_metadata_propagation_indiv_resample(self): index=date_range("20130101", periods=1000, freq="s"), name="foo", ) - result = ts.resample("1T").mean() + result = ts.resample("1min").mean() tm.assert_metadata_equivalent(ts, result) - result = ts.resample("1T").min() + result = ts.resample("1min").min() tm.assert_metadata_equivalent(ts, result) - result = ts.resample("1T").apply(lambda x: x.sum()) + result = ts.resample("1min").apply(lambda x: x.sum()) tm.assert_metadata_equivalent(ts, result) def test_metadata_propagation_indiv(self, monkeypatch): diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index cdfa80c8c7cb5..c01ca4922a84b 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -360,16 +360,16 @@ def test_agg_multiple_functions_same_name(): # GH 30880 df = DataFrame( np.random.default_rng(2).standard_normal((1000, 3)), - index=pd.date_range("1/1/2012", freq="S", periods=1000), + index=pd.date_range("1/1/2012", freq="s", periods=1000), columns=["A", "B", "C"], ) - result = df.resample("3T").agg( + result = df.resample("3min").agg( {"A": [partial(np.quantile, q=0.9999), partial(np.quantile, q=0.1111)]} ) - expected_index = pd.date_range("1/1/2012", freq="3T", periods=6) + expected_index = pd.date_range("1/1/2012", freq="3min", periods=6) expected_columns = MultiIndex.from_tuples([("A", "quantile"), ("A", "quantile")]) expected_values = np.array( - [df.resample("3T").A.quantile(q=q).values for q in [0.9999, 0.1111]] + [df.resample("3min").A.quantile(q=q).values for q in [0.9999, 0.1111]] ).T expected = DataFrame( expected_values, columns=expected_columns, index=expected_index @@ -382,13 +382,13 @@ def test_agg_multiple_functions_same_name_with_ohlc_present(): # ohlc expands dimensions, so different test to the above is required. df = DataFrame( np.random.default_rng(2).standard_normal((1000, 3)), - index=pd.date_range("1/1/2012", freq="S", periods=1000, name="dti"), + index=pd.date_range("1/1/2012", freq="s", periods=1000, name="dti"), columns=Index(["A", "B", "C"], name="alpha"), ) - result = df.resample("3T").agg( + result = df.resample("3min").agg( {"A": ["ohlc", partial(np.quantile, q=0.9999), partial(np.quantile, q=0.1111)]} ) - expected_index = pd.date_range("1/1/2012", freq="3T", periods=6, name="dti") + expected_index = pd.date_range("1/1/2012", freq="3min", periods=6, name="dti") expected_columns = MultiIndex.from_tuples( [ ("A", "ohlc", "open"), @@ -401,9 +401,11 @@ def test_agg_multiple_functions_same_name_with_ohlc_present(): names=["alpha", None, None], ) non_ohlc_expected_values = np.array( - [df.resample("3T").A.quantile(q=q).values for q in [0.9999, 0.1111]] + [df.resample("3min").A.quantile(q=q).values for q in [0.9999, 0.1111]] ).T - expected_values = np.hstack([df.resample("3T").A.ohlc(), non_ohlc_expected_values]) + expected_values = np.hstack( + [df.resample("3min").A.ohlc(), non_ohlc_expected_values] + ) expected = DataFrame( expected_values, columns=expected_columns, index=expected_index ) diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index f917f567e1ce3..865fda0ab54a2 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -118,7 +118,7 @@ def test_cython_agg_nothing_to_agg_with_dates(): { "a": np.random.default_rng(2).integers(0, 5, 50), "b": ["foo", "bar"] * 25, - "dates": pd.date_range("now", periods=50, freq="T"), + "dates": pd.date_range("now", periods=50, freq="min"), } ) msg = "Cannot use numeric_only=True with SeriesGroupBy.mean and non-numeric dtypes" diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 06b473e40ad11..f2d21c10f7a15 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1150,7 +1150,7 @@ def test_groupby_multiindex_categorical_datetime(): { "key1": Categorical(list("abcbabcba")), "key2": Categorical( - list(pd.date_range("2018-06-01 00", freq="1T", periods=3)) * 3 + list(pd.date_range("2018-06-01 00", freq="1min", periods=3)) * 3 ), "values": np.arange(9), } @@ -1160,7 +1160,7 @@ def test_groupby_multiindex_categorical_datetime(): idx = MultiIndex.from_product( [ Categorical(["a", "b", "c"]), - Categorical(pd.date_range("2018-06-01 00", freq="1T", periods=3)), + Categorical(pd.date_range("2018-06-01 00", freq="1min", periods=3)), ], names=["key1", "key2"], ) diff --git a/pandas/tests/groupby/test_counting.py b/pandas/tests/groupby/test_counting.py index 6c27344ce3110..5022e9629f155 100644 --- a/pandas/tests/groupby/test_counting.py +++ b/pandas/tests/groupby/test_counting.py @@ -265,7 +265,7 @@ def test_groupby_timedelta_cython_count(): def test_count(): n = 1 << 15 - dr = date_range("2015-08-30", periods=n // 10, freq="T") + dr = date_range("2015-08-30", periods=n // 10, freq="min") df = DataFrame( { diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 772ce90b1e611..c0ac94c09e1ea 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -3141,13 +3141,13 @@ def test_groupby_with_Time_Grouper(): expected_output = DataFrame( { - "time2": date_range("2016-08-31 22:08:00", periods=13, freq="1T"), + "time2": date_range("2016-08-31 22:08:00", periods=13, freq="1min"), "quant": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "quant2": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], } ) - df = test_data.groupby(Grouper(key="time2", freq="1T")).count().reset_index() + df = test_data.groupby(Grouper(key="time2", freq="1min")).count().reset_index() tm.assert_frame_equal(df, expected_output) diff --git a/pandas/tests/groupby/test_quantile.py b/pandas/tests/groupby/test_quantile.py index 165d72bf3e878..efe7b171d630d 100644 --- a/pandas/tests/groupby/test_quantile.py +++ b/pandas/tests/groupby/test_quantile.py @@ -420,7 +420,7 @@ def test_timestamp_groupby_quantile(): df = DataFrame( { "timestamp": pd.date_range( - start="2020-04-19 00:00:00", freq="1T", periods=100, tz="UTC" + start="2020-04-19 00:00:00", freq="1min", periods=100, tz="UTC" ).floor("1H"), "category": list(range(1, 101)), "value": list(range(101, 201)), diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index 527e7c6081970..c9fe011f7063b 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -753,7 +753,7 @@ def test_timezone_info(self): def test_datetime_count(self): df = DataFrame( - {"a": [1, 2, 3] * 2, "dates": date_range("now", periods=6, freq="T")} + {"a": [1, 2, 3] * 2, "dates": date_range("now", periods=6, freq="min")} ) result = df.groupby("a").dates.count() expected = Series([2, 2, 2], index=Index([1, 2, 3], name="a"), name="dates") diff --git a/pandas/tests/indexes/conftest.py b/pandas/tests/indexes/conftest.py index 458a37c994091..fe397e2c7c88e 100644 --- a/pandas/tests/indexes/conftest.py +++ b/pandas/tests/indexes/conftest.py @@ -25,7 +25,7 @@ def sort(request): return request.param -@pytest.fixture(params=["D", "3D", "-3D", "H", "2H", "-2H", "T", "2T", "S", "-3S"]) +@pytest.fixture(params=["D", "3D", "-3D", "H", "2H", "-2H", "min", "2min", "s", "-3s"]) def freq_sample(request): """ Valid values for 'freq' parameter used to create date_range and diff --git a/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py b/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py index e5da06cb005f6..c38e24232f181 100644 --- a/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py +++ b/pandas/tests/indexes/datetimelike_/test_drop_duplicates.py @@ -68,7 +68,7 @@ def test_drop_duplicates(self, keep, expected, index, idx): class TestDropDuplicatesPeriodIndex(DropDuplicates): - @pytest.fixture(params=["D", "3D", "H", "2H", "T", "2T", "S", "3S"]) + @pytest.fixture(params=["D", "3D", "H", "2H", "min", "2min", "s", "3s"]) def freq(self, request): return request.param diff --git a/pandas/tests/indexes/datetimes/methods/test_shift.py b/pandas/tests/indexes/datetimes/methods/test_shift.py index 65bdfc9053e5e..e8661fafc3bb7 100644 --- a/pandas/tests/indexes/datetimes/methods/test_shift.py +++ b/pandas/tests/indexes/datetimes/methods/test_shift.py @@ -96,7 +96,7 @@ def test_dti_shift_localized(self, tzstr): dr = date_range("2011/1/1", "2012/1/1", freq="W-FRI") dr_tz = dr.tz_localize(tzstr) - result = dr_tz.shift(1, "10T") + result = dr_tz.shift(1, "10min") assert result.tz == dr_tz.tz def test_dti_shift_across_dst(self): diff --git a/pandas/tests/indexes/datetimes/methods/test_to_period.py b/pandas/tests/indexes/datetimes/methods/test_to_period.py index 14de6c5907d03..2d762710168ab 100644 --- a/pandas/tests/indexes/datetimes/methods/test_to_period.py +++ b/pandas/tests/indexes/datetimes/methods/test_to_period.py @@ -119,10 +119,10 @@ def test_to_period_millisecond(self): with tm.assert_produces_warning(UserWarning): # warning that timezone info will be lost - period = index.to_period(freq="L") + period = index.to_period(freq="ms") assert 2 == len(period) - assert period[0] == Period("2007-01-01 10:11:12.123Z", "L") - assert period[1] == Period("2007-01-01 10:11:13.789Z", "L") + assert period[0] == Period("2007-01-01 10:11:12.123Z", "ms") + assert period[1] == Period("2007-01-01 10:11:13.789Z", "ms") def test_to_period_microsecond(self): index = DatetimeIndex( @@ -134,10 +134,10 @@ def test_to_period_microsecond(self): with tm.assert_produces_warning(UserWarning): # warning that timezone info will be lost - period = index.to_period(freq="U") + period = index.to_period(freq="us") assert 2 == len(period) - assert period[0] == Period("2007-01-01 10:11:12.123456Z", "U") - assert period[1] == Period("2007-01-01 10:11:13.789123Z", "U") + assert period[0] == Period("2007-01-01 10:11:12.123456Z", "us") + assert period[1] == Period("2007-01-01 10:11:13.789123Z", "us") @pytest.mark.parametrize( "tz", diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 733c14f33567a..c8f5c5d561339 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1036,7 +1036,7 @@ def test_constructor_int64_nocopy(self): assert (index.asi8[50:100] != -1).all() @pytest.mark.parametrize( - "freq", ["M", "Q", "A", "D", "B", "BH", "T", "S", "L", "U", "H", "N", "C"] + "freq", ["M", "Q", "A", "D", "B", "BH", "min", "s", "ms", "us", "H", "ns", "C"] ) def test_from_freq_recreate_from_data(self, freq): org = date_range(start="2001/02/01 09:00", freq=freq, periods=1) diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 2e2e33e2fb366..d5500a19f2bb6 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -123,7 +123,7 @@ def test_date_range_timestamp_equiv_preserve_frequency(self): class TestDateRanges: - @pytest.mark.parametrize("freq", ["N", "U", "L", "T", "S", "H", "D"]) + @pytest.mark.parametrize("freq", ["ns", "us", "ms", "min", "s", "H", "D"]) def test_date_range_edges(self, freq): # GH#13672 td = Timedelta(f"1{freq}") @@ -761,13 +761,13 @@ def test_freq_divides_end_in_nanos(self): expected_1 = DatetimeIndex( ["2005-01-12 10:00:00", "2005-01-12 15:45:00"], dtype="datetime64[ns]", - freq="345T", + freq="345min", tz=None, ) expected_2 = DatetimeIndex( ["2005-01-13 10:00:00", "2005-01-13 15:45:00"], dtype="datetime64[ns]", - freq="345T", + freq="345min", tz=None, ) tm.assert_index_equal(result_1, expected_1) @@ -836,6 +836,25 @@ def test_freq_dateoffset_with_relateivedelta_nanos(self): ) tm.assert_index_equal(result, expected) + @pytest.mark.parametrize( + "freq,freq_depr", + [ + ("min", "T"), + ("s", "S"), + ("ms", "L"), + ("us", "U"), + ("ns", "N"), + ], + ) + def test_frequencies_T_S_L_U_N_deprecated(self, freq, freq_depr): + # GH#52536 + msg = f"'{freq_depr}' is deprecated and will be removed in a future version." + + expected = date_range("1/1/2000", periods=4, freq=freq) + with tm.assert_produces_warning(FutureWarning, match=msg): + result = date_range("1/1/2000", periods=4, freq=freq_depr) + tm.assert_index_equal(result, expected) + class TestDateRangeTZ: """Tests for date_range with timezones""" diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index aa4954ff0ba85..f44cbbf560584 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -56,10 +56,10 @@ def test_time_overflow_for_32bit_machines(self): # overflow. periods = np.int_(1000) - idx1 = date_range(start="2000", periods=periods, freq="S") + idx1 = date_range(start="2000", periods=periods, freq="s") assert len(idx1) == periods - idx2 = date_range(end="2000", periods=periods, freq="S") + idx2 = date_range(end="2000", periods=periods, freq="s") assert len(idx2) == periods def test_nat(self): @@ -148,8 +148,8 @@ def test_groupby_function_tuple_1677(self): assert isinstance(result.index[0], tuple) def assert_index_parameters(self, index): - assert index.freq == "40960N" - assert index.inferred_freq == "40960N" + assert index.freq == "40960ns" + assert index.inferred_freq == "40960ns" def test_ns_index(self): nsamples = 400 diff --git a/pandas/tests/indexes/datetimes/test_formats.py b/pandas/tests/indexes/datetimes/test_formats.py index cb3e0179bf46c..502cb0407bfcd 100644 --- a/pandas/tests/indexes/datetimes/test_formats.py +++ b/pandas/tests/indexes/datetimes/test_formats.py @@ -73,17 +73,17 @@ def test_dti_repr_short(self): [ ( ["2012-01-01 00:00:00"], - "60T", + "60min", ( "DatetimeIndex(['2012-01-01 00:00:00'], " - "dtype='datetime64[ns]', freq='60T')" + "dtype='datetime64[ns]', freq='60min')" ), ), ( ["2012-01-01 00:00:00", "2012-01-01 01:00:00"], - "60T", + "60min", "DatetimeIndex(['2012-01-01 00:00:00', '2012-01-01 01:00:00'], " - "dtype='datetime64[ns]', freq='60T')", + "dtype='datetime64[ns]', freq='60min')", ), ( ["2012-01-01"], diff --git a/pandas/tests/indexes/datetimes/test_indexing.py b/pandas/tests/indexes/datetimes/test_indexing.py index 8e1b41095e056..bfecc5d064b11 100644 --- a/pandas/tests/indexes/datetimes/test_indexing.py +++ b/pandas/tests/indexes/datetimes/test_indexing.py @@ -426,7 +426,7 @@ def test_get_loc_time_obj2(self): step = 24 * 3600 for n in ns: - idx = date_range("2014-11-26", periods=n, freq="S") + idx = date_range("2014-11-26", periods=n, freq="s") ts = pd.Series(np.random.default_rng(2).standard_normal(n), index=idx) locs = np.arange(start, n, step, dtype=np.intp) diff --git a/pandas/tests/indexes/datetimes/test_npfuncs.py b/pandas/tests/indexes/datetimes/test_npfuncs.py index 301466c0da41c..6c3e44c2a5db1 100644 --- a/pandas/tests/indexes/datetimes/test_npfuncs.py +++ b/pandas/tests/indexes/datetimes/test_npfuncs.py @@ -7,7 +7,7 @@ class TestSplit: def test_split_non_utc(self): # GH#14042 - indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10) + indices = date_range("2016-01-01 00:00:00+0200", freq="s", periods=10) result = np.split(indices, indices_or_sections=[])[0] expected = indices._with_freq(None) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index d6ef4198fad2e..c782121505642 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -25,10 +25,10 @@ class TestDatetimeIndexOps: ("M", "day"), ("D", "day"), ("H", "hour"), - ("T", "minute"), - ("S", "second"), - ("L", "millisecond"), - ("U", "microsecond"), + ("min", "minute"), + ("s", "second"), + ("ms", "millisecond"), + ("us", "microsecond"), ], ) def test_resolution(self, request, tz_naive_fixture, freq, expected): diff --git a/pandas/tests/indexes/datetimes/test_partial_slicing.py b/pandas/tests/indexes/datetimes/test_partial_slicing.py index 7978e596e6ee5..0ecccd7da3a5c 100644 --- a/pandas/tests/indexes/datetimes/test_partial_slicing.py +++ b/pandas/tests/indexes/datetimes/test_partial_slicing.py @@ -204,7 +204,7 @@ def test_partial_slice_daily(self): s["2004-12-31 00"] def test_partial_slice_hourly(self): - rng = date_range(freq="T", start=datetime(2005, 1, 1, 20, 0, 0), periods=500) + rng = date_range(freq="min", start=datetime(2005, 1, 1, 20, 0, 0), periods=500) s = Series(np.arange(len(rng)), index=rng) result = s["2005-1-1"] @@ -218,7 +218,7 @@ def test_partial_slice_hourly(self): s["2004-12-31 00:15"] def test_partial_slice_minutely(self): - rng = date_range(freq="S", start=datetime(2005, 1, 1, 23, 59, 0), periods=500) + rng = date_range(freq="s", start=datetime(2005, 1, 1, 23, 59, 0), periods=500) s = Series(np.arange(len(rng)), index=rng) result = s["2005-1-1 23:59"] @@ -336,7 +336,7 @@ def test_partial_slicing_with_multiindex(self): "TICKER": ["ABC", "MNP", "XYZ", "XYZ"], "val": [1, 2, 3, 4], }, - index=date_range("2013-06-19 09:30:00", periods=4, freq="5T"), + index=date_range("2013-06-19 09:30:00", periods=4, freq="5min"), ) df_multi = df.set_index(["ACCOUNT", "TICKER"], append=True) diff --git a/pandas/tests/indexes/datetimes/test_scalar_compat.py b/pandas/tests/indexes/datetimes/test_scalar_compat.py index f07a9dce5f6ae..1c5b6adf0b527 100644 --- a/pandas/tests/indexes/datetimes/test_scalar_compat.py +++ b/pandas/tests/indexes/datetimes/test_scalar_compat.py @@ -175,7 +175,7 @@ def test_no_rounding_occurs(self, tz_naive_fixture): ] ) - tm.assert_index_equal(rng.round(freq="2T"), expected_rng) + tm.assert_index_equal(rng.round(freq="2min"), expected_rng) @pytest.mark.parametrize( "test_input, rounder, freq, expected", @@ -196,8 +196,8 @@ def test_no_rounding_occurs(self, tz_naive_fixture): ), (["1823-01-01 00:00:01"], "floor", "1s", ["1823-01-01 00:00:01"]), (["1823-01-01 00:00:01"], "ceil", "1s", ["1823-01-01 00:00:01"]), - (["2018-01-01 00:15:00"], "ceil", "15T", ["2018-01-01 00:15:00"]), - (["2018-01-01 00:15:00"], "floor", "15T", ["2018-01-01 00:15:00"]), + (["2018-01-01 00:15:00"], "ceil", "15min", ["2018-01-01 00:15:00"]), + (["2018-01-01 00:15:00"], "floor", "15min", ["2018-01-01 00:15:00"]), (["1823-01-01 03:00:00"], "ceil", "3H", ["1823-01-01 03:00:00"]), (["1823-01-01 03:00:00"], "floor", "3H", ["1823-01-01 03:00:00"]), ( @@ -333,14 +333,14 @@ def test_hour(self): tm.assert_index_equal(r1, r2) def test_minute(self): - dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="T") + dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="min") r1 = pd.Index([x.to_julian_date() for x in dr]) r2 = dr.to_julian_date() assert isinstance(r2, pd.Index) and r2.dtype == np.float64 tm.assert_index_equal(r1, r2) def test_second(self): - dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="S") + dr = date_range(start=Timestamp("2000-02-27"), periods=5, freq="s") r1 = pd.Index([x.to_julian_date() for x in dr]) r2 = dr.to_julian_date() assert isinstance(r2, pd.Index) and r2.dtype == np.float64 diff --git a/pandas/tests/indexes/datetimes/test_setops.py b/pandas/tests/indexes/datetimes/test_setops.py index adf7acfa59e0c..2e7b38abf4212 100644 --- a/pandas/tests/indexes/datetimes/test_setops.py +++ b/pandas/tests/indexes/datetimes/test_setops.py @@ -269,7 +269,7 @@ def test_intersection(self, tz, sort): # parametrize over both anchored and non-anchored freqs, as they # have different code paths - @pytest.mark.parametrize("freq", ["T", "B"]) + @pytest.mark.parametrize("freq", ["min", "B"]) def test_intersection_empty(self, tz_aware_fixture, freq): # empty same freq GH2129 tz = tz_aware_fixture @@ -283,7 +283,7 @@ def test_intersection_empty(self, tz_aware_fixture, freq): assert result.freq == rng.freq # no overlap GH#33604 - check_freq = freq != "T" # We don't preserve freq on non-anchored offsets + check_freq = freq != "min" # We don't preserve freq on non-anchored offsets result = rng[:3].intersection(rng[-3:]) tm.assert_index_equal(result, rng[:0]) if check_freq: diff --git a/pandas/tests/indexes/datetimes/test_timezones.py b/pandas/tests/indexes/datetimes/test_timezones.py index 09b06ecd5630d..e9cc69aea0ed5 100644 --- a/pandas/tests/indexes/datetimes/test_timezones.py +++ b/pandas/tests/indexes/datetimes/test_timezones.py @@ -192,7 +192,7 @@ def test_dti_tz_convert_hour_overflow_dst_timestamps(self, tz): expected = Index([9, 9, 9], dtype=np.int32) tm.assert_index_equal(ut.hour, expected) - @pytest.mark.parametrize("freq, n", [("H", 1), ("T", 60), ("S", 3600)]) + @pytest.mark.parametrize("freq, n", [("H", 1), ("min", 60), ("s", 3600)]) def test_dti_tz_convert_trans_pos_plus_1__bug(self, freq, n): # Regression test for tslib.tz_convert(vals, tz1, tz2). # See https://github.com/pandas-dev/pandas/issues/4496 for details. @@ -204,7 +204,7 @@ def test_dti_tz_convert_trans_pos_plus_1__bug(self, freq, n): tm.assert_index_equal(idx.hour, Index(expected, dtype=np.int32)) def test_dti_tz_convert_dst(self): - for freq, n in [("H", 1), ("T", 60), ("S", 3600)]: + for freq, n in [("H", 1), ("min", 60), ("s", 3600)]: # Start DST idx = date_range( "2014-03-08 23:00", "2014-03-09 09:00", freq=freq, tz="UTC" @@ -281,8 +281,8 @@ def test_tz_convert_roundtrip(self, tz_aware_fixture): idx3 = date_range(start="2014-01-01", end="2014-03-01", freq="H", tz="UTC") exp3 = date_range(start="2014-01-01", end="2014-03-01", freq="H") - idx4 = date_range(start="2014-08-01", end="2014-10-31", freq="T", tz="UTC") - exp4 = date_range(start="2014-08-01", end="2014-10-31", freq="T") + idx4 = date_range(start="2014-08-01", end="2014-10-31", freq="min", tz="UTC") + exp4 = date_range(start="2014-08-01", end="2014-10-31", freq="min") for idx, expected in [(idx1, exp1), (idx2, exp2), (idx3, exp3), (idx4, exp4)]: converted = idx.tz_convert(tz) @@ -440,11 +440,11 @@ def test_dti_tz_localize_pass_dates_to_utc(self, tzstr): @pytest.mark.parametrize("prefix", ["", "dateutil/"]) def test_dti_tz_localize(self, prefix): tzstr = prefix + "US/Eastern" - dti = date_range(start="1/1/2005", end="1/1/2005 0:00:30.256", freq="L") + dti = date_range(start="1/1/2005", end="1/1/2005 0:00:30.256", freq="ms") dti2 = dti.tz_localize(tzstr) dti_utc = date_range( - start="1/1/2005 05:00", end="1/1/2005 5:00:30.256", freq="L", tz="utc" + start="1/1/2005 05:00", end="1/1/2005 5:00:30.256", freq="ms", tz="utc" ) tm.assert_numpy_array_equal(dti2.values, dti_utc.values) @@ -452,11 +452,11 @@ def test_dti_tz_localize(self, prefix): dti3 = dti2.tz_convert(prefix + "US/Pacific") tm.assert_numpy_array_equal(dti3.values, dti_utc.values) - dti = date_range(start="11/6/2011 1:59", end="11/6/2011 2:00", freq="L") + dti = date_range(start="11/6/2011 1:59", end="11/6/2011 2:00", freq="ms") with pytest.raises(pytz.AmbiguousTimeError, match="Cannot infer dst time"): dti.tz_localize(tzstr) - dti = date_range(start="3/13/2011 1:59", end="3/13/2011 2:00", freq="L") + dti = date_range(start="3/13/2011 1:59", end="3/13/2011 2:00", freq="ms") with pytest.raises(pytz.NonExistentTimeError, match="2011-03-13 02:00:00"): dti.tz_localize(tzstr) @@ -474,14 +474,14 @@ def test_dti_tz_localize_utc_conversion(self, tz): # 1) check for DST ambiguities # 2) convert to UTC - rng = date_range("3/10/2012", "3/11/2012", freq="30T") + rng = date_range("3/10/2012", "3/11/2012", freq="30min") converted = rng.tz_localize(tz) expected_naive = rng + pd.offsets.Hour(5) tm.assert_numpy_array_equal(converted.asi8, expected_naive.asi8) # DST ambiguity, this should fail - rng = date_range("3/11/2012", "3/12/2012", freq="30T") + rng = date_range("3/11/2012", "3/12/2012", freq="30min") # Is this really how it should fail?? with pytest.raises(pytz.NonExistentTimeError, match="2012-03-11 02:00:00"): rng.tz_localize(tz) @@ -490,7 +490,7 @@ def test_dti_tz_localize_roundtrip(self, tz_aware_fixture): # note: this tz tests that a tz-naive index can be localized # and de-localized successfully, when there are no DST transitions # in the range. - idx = date_range(start="2014-06-01", end="2014-08-30", freq="15T") + idx = date_range(start="2014-06-01", end="2014-08-30", freq="15min") tz = tz_aware_fixture localized = idx.tz_localize(tz) # can't localize a tz-aware object @@ -879,7 +879,7 @@ def test_dti_tz_conversion_freq(self, tz_naive_fixture): # GH25241 t3 = DatetimeIndex(["2019-01-01 10:00"], freq="H") assert t3.tz_localize(tz=tz_naive_fixture).freq == t3.freq - t4 = DatetimeIndex(["2019-01-02 12:00"], tz="UTC", freq="T") + t4 = DatetimeIndex(["2019-01-02 12:00"], tz="UTC", freq="min") assert t4.tz_convert(tz="UTC").freq == t4.freq def test_drop_dst_boundary(self): diff --git a/pandas/tests/indexes/period/methods/test_asfreq.py b/pandas/tests/indexes/period/methods/test_asfreq.py index 4f5cfbade4d84..89ea4fb6472d0 100644 --- a/pandas/tests/indexes/period/methods/test_asfreq.py +++ b/pandas/tests/indexes/period/methods/test_asfreq.py @@ -16,57 +16,57 @@ def test_asfreq(self): pi4 = period_range(freq="D", start="1/1/2001", end="1/1/2001") pi5 = period_range(freq="H", start="1/1/2001", end="1/1/2001 00:00") pi6 = period_range(freq="Min", start="1/1/2001", end="1/1/2001 00:00") - pi7 = period_range(freq="S", start="1/1/2001", end="1/1/2001 00:00:00") + pi7 = period_range(freq="s", start="1/1/2001", end="1/1/2001 00:00:00") - assert pi1.asfreq("Q", "S") == pi2 + assert pi1.asfreq("Q", "s") == pi2 assert pi1.asfreq("Q", "s") == pi2 assert pi1.asfreq("M", "start") == pi3 assert pi1.asfreq("D", "StarT") == pi4 assert pi1.asfreq("H", "beGIN") == pi5 - assert pi1.asfreq("Min", "S") == pi6 - assert pi1.asfreq("S", "S") == pi7 - - assert pi2.asfreq("A", "S") == pi1 - assert pi2.asfreq("M", "S") == pi3 - assert pi2.asfreq("D", "S") == pi4 - assert pi2.asfreq("H", "S") == pi5 - assert pi2.asfreq("Min", "S") == pi6 - assert pi2.asfreq("S", "S") == pi7 - - assert pi3.asfreq("A", "S") == pi1 - assert pi3.asfreq("Q", "S") == pi2 - assert pi3.asfreq("D", "S") == pi4 - assert pi3.asfreq("H", "S") == pi5 - assert pi3.asfreq("Min", "S") == pi6 - assert pi3.asfreq("S", "S") == pi7 - - assert pi4.asfreq("A", "S") == pi1 - assert pi4.asfreq("Q", "S") == pi2 - assert pi4.asfreq("M", "S") == pi3 - assert pi4.asfreq("H", "S") == pi5 - assert pi4.asfreq("Min", "S") == pi6 - assert pi4.asfreq("S", "S") == pi7 - - assert pi5.asfreq("A", "S") == pi1 - assert pi5.asfreq("Q", "S") == pi2 - assert pi5.asfreq("M", "S") == pi3 - assert pi5.asfreq("D", "S") == pi4 - assert pi5.asfreq("Min", "S") == pi6 - assert pi5.asfreq("S", "S") == pi7 - - assert pi6.asfreq("A", "S") == pi1 - assert pi6.asfreq("Q", "S") == pi2 - assert pi6.asfreq("M", "S") == pi3 - assert pi6.asfreq("D", "S") == pi4 - assert pi6.asfreq("H", "S") == pi5 - assert pi6.asfreq("S", "S") == pi7 - - assert pi7.asfreq("A", "S") == pi1 - assert pi7.asfreq("Q", "S") == pi2 - assert pi7.asfreq("M", "S") == pi3 - assert pi7.asfreq("D", "S") == pi4 - assert pi7.asfreq("H", "S") == pi5 - assert pi7.asfreq("Min", "S") == pi6 + assert pi1.asfreq("Min", "s") == pi6 + assert pi1.asfreq("s", "s") == pi7 + + assert pi2.asfreq("A", "s") == pi1 + assert pi2.asfreq("M", "s") == pi3 + assert pi2.asfreq("D", "s") == pi4 + assert pi2.asfreq("H", "s") == pi5 + assert pi2.asfreq("Min", "s") == pi6 + assert pi2.asfreq("s", "s") == pi7 + + assert pi3.asfreq("A", "s") == pi1 + assert pi3.asfreq("Q", "s") == pi2 + assert pi3.asfreq("D", "s") == pi4 + assert pi3.asfreq("H", "s") == pi5 + assert pi3.asfreq("Min", "s") == pi6 + assert pi3.asfreq("s", "s") == pi7 + + assert pi4.asfreq("A", "s") == pi1 + assert pi4.asfreq("Q", "s") == pi2 + assert pi4.asfreq("M", "s") == pi3 + assert pi4.asfreq("H", "s") == pi5 + assert pi4.asfreq("Min", "s") == pi6 + assert pi4.asfreq("s", "s") == pi7 + + assert pi5.asfreq("A", "s") == pi1 + assert pi5.asfreq("Q", "s") == pi2 + assert pi5.asfreq("M", "s") == pi3 + assert pi5.asfreq("D", "s") == pi4 + assert pi5.asfreq("Min", "s") == pi6 + assert pi5.asfreq("s", "s") == pi7 + + assert pi6.asfreq("A", "s") == pi1 + assert pi6.asfreq("Q", "s") == pi2 + assert pi6.asfreq("M", "s") == pi3 + assert pi6.asfreq("D", "s") == pi4 + assert pi6.asfreq("H", "s") == pi5 + assert pi6.asfreq("s", "s") == pi7 + + assert pi7.asfreq("A", "s") == pi1 + assert pi7.asfreq("Q", "s") == pi2 + assert pi7.asfreq("M", "s") == pi3 + assert pi7.asfreq("D", "s") == pi4 + assert pi7.asfreq("H", "s") == pi5 + assert pi7.asfreq("Min", "s") == pi6 msg = "How must be one of S or E" with pytest.raises(ValueError, match=msg): diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index 7d4d681659ab6..a3d5dc63ad7c8 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -110,16 +110,18 @@ def test_constructor_U(self): def test_constructor_nano(self): idx = period_range( - start=Period(ordinal=1, freq="N"), end=Period(ordinal=4, freq="N"), freq="N" + start=Period(ordinal=1, freq="ns"), + end=Period(ordinal=4, freq="ns"), + freq="ns", ) exp = PeriodIndex( [ - Period(ordinal=1, freq="N"), - Period(ordinal=2, freq="N"), - Period(ordinal=3, freq="N"), - Period(ordinal=4, freq="N"), + Period(ordinal=1, freq="ns"), + Period(ordinal=2, freq="ns"), + Period(ordinal=3, freq="ns"), + Period(ordinal=4, freq="ns"), ], - freq="N", + freq="ns", ) tm.assert_index_equal(idx, exp) @@ -144,7 +146,7 @@ def test_constructor_corner(self): def test_constructor_with_without_freq(self): # GH53687 - start = Period("2002-01-01 00:00", freq="30T") + start = Period("2002-01-01 00:00", freq="30min") exp = period_range(start=start, periods=5, freq=start.freq) result = period_range(start=start, periods=5) tm.assert_index_equal(exp, result) @@ -413,7 +415,7 @@ def test_constructor_freq_mult(self): with pytest.raises(ValueError, match=msg): period_range("2011-01", periods=3, freq="0M") - @pytest.mark.parametrize("freq", ["A", "M", "D", "T", "S"]) + @pytest.mark.parametrize("freq", ["A", "M", "D", "min", "s"]) @pytest.mark.parametrize("mult", [1, 2, 3, 4, 5]) def test_constructor_freq_mult_dti_compat(self, mult, freq): freqstr = str(mult) + freq @@ -456,7 +458,7 @@ def test_constructor(self): pi = period_range(freq="Min", start="1/1/2001", end="1/1/2001 23:59") assert len(pi) == 24 * 60 - pi = period_range(freq="S", start="1/1/2001", end="1/1/2001 23:59:59") + pi = period_range(freq="s", start="1/1/2001", end="1/1/2001 23:59:59") assert len(pi) == 24 * 60 * 60 with tm.assert_produces_warning(FutureWarning, match=msg): @@ -506,7 +508,7 @@ def test_constructor(self): Period("2006-12-31", ("w", 1)) @pytest.mark.parametrize( - "freq", ["M", "Q", "A", "D", "B", "T", "S", "L", "U", "N", "H"] + "freq", ["M", "Q", "A", "D", "B", "min", "s", "ms", "us", "ns", "H"] ) @pytest.mark.filterwarnings( r"ignore:Period with BDay freq is deprecated:FutureWarning" diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index c0c6f3c977ceb..109a4a41e2841 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -174,8 +174,8 @@ def test_getitem_list_periods(self): @pytest.mark.arm_slow def test_getitem_seconds(self): # GH#6716 - didx = date_range(start="2013/01/01 09:00:00", freq="S", periods=4000) - pidx = period_range(start="2013/01/01 09:00:00", freq="S", periods=4000) + didx = date_range(start="2013/01/01 09:00:00", freq="s", periods=4000) + pidx = period_range(start="2013/01/01 09:00:00", freq="s", periods=4000) for idx in [didx, pidx]: # getitem against index should raise ValueError @@ -579,7 +579,7 @@ def test_where_invalid_dtypes(self): result = pi.where(mask, tdi) tm.assert_index_equal(result, expected) - dti = i2.to_timestamp("S") + dti = i2.to_timestamp("s") expected = pd.Index([dti[0], dti[1]] + tail, dtype=object) assert expected[0] is NaT result = pi.where(mask, dti) diff --git a/pandas/tests/indexes/period/test_partial_slicing.py b/pandas/tests/indexes/period/test_partial_slicing.py index e52866abbe234..3a272f53091b5 100644 --- a/pandas/tests/indexes/period/test_partial_slicing.py +++ b/pandas/tests/indexes/period/test_partial_slicing.py @@ -84,7 +84,7 @@ def test_range_slice_day(self, make_range): @pytest.mark.parametrize("make_range", [date_range, period_range]) def test_range_slice_seconds(self, make_range): # GH#6716 - idx = make_range(start="2013/01/01 09:00:00", freq="S", periods=4000) + idx = make_range(start="2013/01/01 09:00:00", freq="s", periods=4000) msg = "slice indices must be integers or None or have an __index__ method" # slices against index should raise IndexError diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 6d8ae1793d5ec..7191175f16f73 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -164,7 +164,7 @@ def test_period_index_length(self): period_range(freq="H", start="12/31/2001", end="1/1/2002 23:00"), period_range(freq="Min", start="12/31/2001", end="1/1/2002 00:20"), period_range( - freq="S", start="12/31/2001 00:00:00", end="12/31/2001 00:05:00" + freq="s", start="12/31/2001 00:00:00", end="12/31/2001 00:05:00" ), period_range(end=Period("2006-12-31", "W"), periods=10), ], diff --git a/pandas/tests/indexes/period/test_resolution.py b/pandas/tests/indexes/period/test_resolution.py index 7ecbde75cfa47..6c876b4f9366f 100644 --- a/pandas/tests/indexes/period/test_resolution.py +++ b/pandas/tests/indexes/period/test_resolution.py @@ -12,10 +12,10 @@ class TestResolution: ("M", "month"), ("D", "day"), ("H", "hour"), - ("T", "minute"), - ("S", "second"), - ("L", "millisecond"), - ("U", "microsecond"), + ("min", "minute"), + ("s", "second"), + ("ms", "millisecond"), + ("us", "microsecond"), ], ) def test_resolution(self, freq, expected): diff --git a/pandas/tests/indexes/period/test_setops.py b/pandas/tests/indexes/period/test_setops.py index af89d712b5565..dd05210e417b0 100644 --- a/pandas/tests/indexes/period/test_setops.py +++ b/pandas/tests/indexes/period/test_setops.py @@ -62,10 +62,10 @@ def test_union(self, sort): ) rng5 = PeriodIndex( - ["2000-01-01 09:01", "2000-01-01 09:03", "2000-01-01 09:05"], freq="T" + ["2000-01-01 09:01", "2000-01-01 09:03", "2000-01-01 09:05"], freq="min" ) other5 = PeriodIndex( - ["2000-01-01 09:01", "2000-01-01 09:05", "2000-01-01 09:08"], freq="T" + ["2000-01-01 09:01", "2000-01-01 09:05", "2000-01-01 09:08"], freq="min" ) expected5 = PeriodIndex( [ @@ -74,7 +74,7 @@ def test_union(self, sort): "2000-01-01 09:05", "2000-01-01 09:08", ], - freq="T", + freq="min", ) rng6 = period_range("2000-01-01", freq="M", periods=7) @@ -240,7 +240,7 @@ def test_intersection_cases(self, sort): assert result.freq == "D" # empty same freq - rng = date_range("6/1/2000", "6/15/2000", freq="T") + rng = date_range("6/1/2000", "6/15/2000", freq="min") result = rng[0:0].intersection(rng) assert len(result) == 0 @@ -274,10 +274,10 @@ def test_difference(self, sort): expected4 = rng4 rng5 = PeriodIndex( - ["2000-01-01 09:03", "2000-01-01 09:01", "2000-01-01 09:05"], freq="T" + ["2000-01-01 09:03", "2000-01-01 09:01", "2000-01-01 09:05"], freq="min" ) - other5 = PeriodIndex(["2000-01-01 09:01", "2000-01-01 09:05"], freq="T") - expected5 = PeriodIndex(["2000-01-01 09:03"], freq="T") + other5 = PeriodIndex(["2000-01-01 09:01", "2000-01-01 09:05"], freq="min") + expected5 = PeriodIndex(["2000-01-01 09:03"], freq="min") period_rng = [ "2000-02-01", diff --git a/pandas/tests/indexes/period/test_tools.py b/pandas/tests/indexes/period/test_tools.py index 13509bd58b4b8..18668fd357fd8 100644 --- a/pandas/tests/indexes/period/test_tools.py +++ b/pandas/tests/indexes/period/test_tools.py @@ -21,11 +21,11 @@ class TestPeriodRepresentation: ("D", "1970-01-01"), ("B", "1970-01-01"), ("H", "1970-01-01"), - ("T", "1970-01-01"), - ("S", "1970-01-01"), - ("L", "1970-01-01"), - ("U", "1970-01-01"), - ("N", "1970-01-01"), + ("min", "1970-01-01"), + ("s", "1970-01-01"), + ("ms", "1970-01-01"), + ("us", "1970-01-01"), + ("ns", "1970-01-01"), ("M", "1970-01"), ("A", 1970), ], diff --git a/pandas/tests/indexes/timedeltas/methods/test_shift.py b/pandas/tests/indexes/timedeltas/methods/test_shift.py index f49af73f9f499..e33b8de3e6594 100644 --- a/pandas/tests/indexes/timedeltas/methods/test_shift.py +++ b/pandas/tests/indexes/timedeltas/methods/test_shift.py @@ -29,11 +29,11 @@ def test_tdi_shift_hours(self): def test_tdi_shift_minutes(self): # GH#9903 idx = TimedeltaIndex(["5 hours", "6 hours", "9 hours"], name="xxx") - tm.assert_index_equal(idx.shift(0, freq="T"), idx) + tm.assert_index_equal(idx.shift(0, freq="min"), idx) exp = TimedeltaIndex(["05:03:00", "06:03:00", "9:03:00"], name="xxx") - tm.assert_index_equal(idx.shift(3, freq="T"), exp) + tm.assert_index_equal(idx.shift(3, freq="min"), exp) exp = TimedeltaIndex(["04:57:00", "05:57:00", "8:57:00"], name="xxx") - tm.assert_index_equal(idx.shift(-3, freq="T"), exp) + tm.assert_index_equal(idx.shift(-3, freq="min"), exp) def test_tdi_shift_int(self): # GH#8083 diff --git a/pandas/tests/indexes/timedeltas/test_scalar_compat.py b/pandas/tests/indexes/timedeltas/test_scalar_compat.py index 9f470b40d1f58..22e50a974d9e1 100644 --- a/pandas/tests/indexes/timedeltas/test_scalar_compat.py +++ b/pandas/tests/indexes/timedeltas/test_scalar_compat.py @@ -104,23 +104,23 @@ def test_round(self): # note that negative times round DOWN! so don't give whole numbers for freq, s1, s2 in [ - ("N", t1, t2), - ("U", t1, t2), + ("ns", t1, t2), + ("us", t1, t2), ( - "L", + "ms", t1a, TimedeltaIndex( ["-1 days +00:00:00", "-2 days +23:58:58", "-2 days +23:57:56"] ), ), ( - "S", + "s", t1a, TimedeltaIndex( ["-1 days +00:00:00", "-2 days +23:58:58", "-2 days +23:57:56"] ), ), - ("12T", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])), + ("12min", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])), ("H", t1c, TimedeltaIndex(["-1 days", "-1 days", "-1 days"])), ("d", t1c, TimedeltaIndex([-1, -1, -1], unit="D")), ]: diff --git a/pandas/tests/indexes/timedeltas/test_timedelta_range.py b/pandas/tests/indexes/timedeltas/test_timedelta_range.py index 72bdc6da47d94..d0593b3230959 100644 --- a/pandas/tests/indexes/timedeltas/test_timedelta_range.py +++ b/pandas/tests/indexes/timedeltas/test_timedelta_range.py @@ -47,12 +47,19 @@ def test_timedelta_range(self): [ ("T", "minute"), ("t", "minute"), + ("S", "second"), ("L", "millisecond"), ("l", "millisecond"), + ("U", "microsecond"), + ("u", "microsecond"), + ("N", "nanosecond"), + ("n", "nanosecond"), ], ) - def test_timedelta_units_T_L_deprecated(self, depr_unit, unit): - depr_msg = f"Unit '{depr_unit}' is deprecated." + def test_timedelta_units_T_S_L_U_N_deprecated(self, depr_unit, unit): + depr_msg = ( + f"'{depr_unit}' is deprecated and will be removed in a future version." + ) expected = to_timedelta(np.arange(5), unit=unit) with tm.assert_produces_warning(FutureWarning, match=depr_msg): @@ -60,7 +67,7 @@ def test_timedelta_units_T_L_deprecated(self, depr_unit, unit): tm.assert_index_equal(result, expected) @pytest.mark.parametrize( - "periods, freq", [(3, "2D"), (5, "D"), (6, "19H12T"), (7, "16H"), (9, "12H")] + "periods, freq", [(3, "2D"), (5, "D"), (6, "19H12min"), (7, "16H"), (9, "12H")] ) def test_linspace_behavior(self, periods, freq): # GH 20976 diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index b7108896f01ed..597bc2975268e 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -1353,7 +1353,7 @@ def test_period_can_hold_element(self, element): with tm.assert_produces_warning(FutureWarning): self.check_series_setitem(elem, pi, False) - dti = pi.to_timestamp("S")[:-1] + dti = pi.to_timestamp("s")[:-1] elem = element(dti) with tm.assert_produces_warning(FutureWarning): self.check_series_setitem(elem, pi, False) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 8341dda1597bb..a2c6429f342da 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -3291,7 +3291,7 @@ def test_dates_display(self): assert result[1].strip() == "NaT" assert result[4].strip() == "2013-01-01 09:00:00.000004" - x = Series(date_range("20130101 09:00:00", periods=5, freq="N")) + x = Series(date_range("20130101 09:00:00", periods=5, freq="ns")) x.iloc[1] = np.nan result = fmt.Datetime64Formatter(x).get_result() assert result[0].strip() == "2013-01-01 09:00:00.000000000" @@ -3342,7 +3342,7 @@ def test_period_format_and_strftime_default(self): assert per.strftime(None)[1] is np.nan # ...except for NaTs # Same test with nanoseconds freq - per = pd.period_range("2003-01-01 12:01:01.123456789", periods=2, freq="n") + per = pd.period_range("2003-01-01 12:01:01.123456789", periods=2, freq="ns") formatted = per.format() assert (formatted == per.strftime(None)).all() assert formatted[0] == "2003-01-01 12:01:01.123456789" @@ -3352,19 +3352,19 @@ def test_period_custom(self): # GH#46252 custom formatting directives %l (ms) and %u (us) # 3 digits - per = pd.period_range("2003-01-01 12:01:01.123", periods=2, freq="l") + per = pd.period_range("2003-01-01 12:01:01.123", periods=2, freq="ms") formatted = per.format(date_format="%y %I:%M:%S (ms=%l us=%u ns=%n)") assert formatted[0] == "03 12:01:01 (ms=123 us=123000 ns=123000000)" assert formatted[1] == "03 12:01:01 (ms=124 us=124000 ns=124000000)" # 6 digits - per = pd.period_range("2003-01-01 12:01:01.123456", periods=2, freq="u") + per = pd.period_range("2003-01-01 12:01:01.123456", periods=2, freq="us") formatted = per.format(date_format="%y %I:%M:%S (ms=%l us=%u ns=%n)") assert formatted[0] == "03 12:01:01 (ms=123 us=123456 ns=123456000)" assert formatted[1] == "03 12:01:01 (ms=123 us=123457 ns=123457000)" # 9 digits - per = pd.period_range("2003-01-01 12:01:01.123456789", periods=2, freq="n") + per = pd.period_range("2003-01-01 12:01:01.123456789", periods=2, freq="ns") formatted = per.format(date_format="%y %I:%M:%S (ms=%l us=%u ns=%n)") assert formatted[0] == "03 12:01:01 (ms=123 us=123456 ns=123456789)" assert formatted[1] == "03 12:01:01 (ms=123 us=123456 ns=123456790)" diff --git a/pandas/tests/io/generate_legacy_storage_files.py b/pandas/tests/io/generate_legacy_storage_files.py index 974a2174cb03b..9643cf3258e64 100644 --- a/pandas/tests/io/generate_legacy_storage_files.py +++ b/pandas/tests/io/generate_legacy_storage_files.py @@ -142,7 +142,7 @@ def create_data(): "period": period_range("2013-01-01", freq="M", periods=10), "float": Index(np.arange(10, dtype=np.float64)), "uint": Index(np.arange(10, dtype=np.uint64)), - "timedelta": timedelta_range("00:00:00", freq="30T", periods=10), + "timedelta": timedelta_range("00:00:00", freq="30min", periods=10), } index["range"] = RangeIndex(10) diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py index 0ee53572877a5..fc2edc7559a48 100644 --- a/pandas/tests/io/json/test_json_table_schema.py +++ b/pandas/tests/io/json/test_json_table_schema.py @@ -32,7 +32,7 @@ def df_schema(): "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], "C": pd.date_range("2016-01-01", freq="d", periods=4), - "D": pd.timedelta_range("1H", periods=4, freq="T"), + "D": pd.timedelta_range("1H", periods=4, freq="min"), }, index=pd.Index(range(4), name="idx"), ) @@ -45,7 +45,7 @@ def df_table(): "A": [1, 2, 3, 4], "B": ["a", "b", "c", "c"], "C": pd.date_range("2016-01-01", freq="d", periods=4), - "D": pd.timedelta_range("1H", periods=4, freq="T"), + "D": pd.timedelta_range("1H", periods=4, freq="min"), "E": pd.Series(pd.Categorical(["a", "b", "c", "c"])), "F": pd.Series(pd.Categorical(["a", "b", "c", "c"], ordered=True)), "G": [1.0, 2.0, 3, 4.0], @@ -695,7 +695,7 @@ def test_read_json_table_orient(self, index_nm, vals, recwarn): @pytest.mark.parametrize("index_nm", [None, "idx", "index"]) @pytest.mark.parametrize( "vals", - [{"timedeltas": pd.timedelta_range("1H", periods=4, freq="T")}], + [{"timedeltas": pd.timedelta_range("1H", periods=4, freq="min")}], ) def test_read_json_table_orient_raises(self, index_nm, vals, recwarn): df = DataFrame(vals, index=pd.Index(range(4), name=index_nm)) diff --git a/pandas/tests/io/pytables/test_select.py b/pandas/tests/io/pytables/test_select.py index 2f2349fe1168b..e387b1b607f63 100644 --- a/pandas/tests/io/pytables/test_select.py +++ b/pandas/tests/io/pytables/test_select.py @@ -64,7 +64,7 @@ def test_select_with_dups(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), columns=["A", "A", "B", "B"] ) - df.index = date_range("20130101 9:30", periods=10, freq="T") + df.index = date_range("20130101 9:30", periods=10, freq="min") with ensure_clean_store(setup_path) as store: store.append("df", df) @@ -95,7 +95,7 @@ def test_select_with_dups(setup_path): ], axis=1, ) - df.index = date_range("20130101 9:30", periods=10, freq="T") + df.index = date_range("20130101 9:30", periods=10, freq="min") with ensure_clean_store(setup_path) as store: store.append("df", df) @@ -397,7 +397,7 @@ def test_select_iterator_complete_8014(setup_path): # no iterator with ensure_clean_store(setup_path) as store: - expected = tm.makeTimeDataFrame(100064, "S") + expected = tm.makeTimeDataFrame(100064, "s") _maybe_remove(store, "df") store.append("df", expected) @@ -428,7 +428,7 @@ def test_select_iterator_complete_8014(setup_path): # with iterator, full range with ensure_clean_store(setup_path) as store: - expected = tm.makeTimeDataFrame(100064, "S") + expected = tm.makeTimeDataFrame(100064, "s") _maybe_remove(store, "df") store.append("df", expected) @@ -466,7 +466,7 @@ def test_select_iterator_non_complete_8014(setup_path): # with iterator, non complete range with ensure_clean_store(setup_path) as store: - expected = tm.makeTimeDataFrame(100064, "S") + expected = tm.makeTimeDataFrame(100064, "s") _maybe_remove(store, "df") store.append("df", expected) @@ -496,7 +496,7 @@ def test_select_iterator_non_complete_8014(setup_path): # with iterator, empty where with ensure_clean_store(setup_path) as store: - expected = tm.makeTimeDataFrame(100064, "S") + expected = tm.makeTimeDataFrame(100064, "s") _maybe_remove(store, "df") store.append("df", expected) @@ -516,7 +516,7 @@ def test_select_iterator_many_empty_frames(setup_path): # with iterator, range limited to the first chunk with ensure_clean_store(setup_path) as store: - expected = tm.makeTimeDataFrame(100000, "S") + expected = tm.makeTimeDataFrame(100000, "s") _maybe_remove(store, "df") store.append("df", expected) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 9182e4c4e7674..1ab8aa086ff6e 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -979,7 +979,7 @@ def test_timestamp_nanoseconds(self, pa): ver = "2.6" else: ver = "2.0" - df = pd.DataFrame({"a": pd.date_range("2017-01-01", freq="1n", periods=10)}) + df = pd.DataFrame({"a": pd.date_range("2017-01-01", freq="1ns", periods=10)}) check_round_trip(df, pa, write_kwargs={"version": ver}) def test_timezone_aware_index(self, request, pa, timezone_aware_date_list): diff --git a/pandas/tests/plotting/test_converter.py b/pandas/tests/plotting/test_converter.py index 56d7900e2907d..0108079f1110f 100644 --- a/pandas/tests/plotting/test_converter.py +++ b/pandas/tests/plotting/test_converter.py @@ -255,7 +255,7 @@ def test_time_formatter(self, time, format_expected): result = converter.TimeFormatter(None)(time) assert result == format_expected - @pytest.mark.parametrize("freq", ("B", "L", "S")) + @pytest.mark.parametrize("freq", ("B", "ms", "s")) def test_dateindex_conversion(self, freq, dtc): rtol = 10**-9 dateindex = tm.makeDateIndex(k=10, freq=freq) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index b3ae25ac9168f..c2626c2aa30c7 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -86,7 +86,7 @@ def test_frame_inferred(self): def test_frame_inferred_n_gt_1(self): # N > 1 - idx = date_range("2008-1-1 00:15:00", freq="15T", periods=10) + idx = date_range("2008-1-1 00:15:00", freq="15min", periods=10) idx = DatetimeIndex(idx.values, freq=None) df = DataFrame( np.random.default_rng(2).standard_normal((len(idx), 3)), index=idx @@ -116,7 +116,7 @@ def test_nonnumeric_exclude_error(self): with pytest.raises(TypeError, match=msg): df["A"].plot() - @pytest.mark.parametrize("freq", ["S", "T", "H", "D", "W", "M", "Q", "A"]) + @pytest.mark.parametrize("freq", ["s", "min", "H", "D", "W", "M", "Q", "A"]) def test_tsplot_period(self, freq): idx = period_range("12/31/1999", freq=freq, periods=100) ser = Series(np.random.default_rng(2).standard_normal(len(idx)), idx) @@ -124,7 +124,7 @@ def test_tsplot_period(self, freq): _check_plot_works(ser.plot, ax=ax) @pytest.mark.parametrize( - "freq", ["S", "T", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] + "freq", ["s", "min", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] ) def test_tsplot_datetime(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -186,14 +186,14 @@ def check_format_of_first_point(ax, expected_string): daily.plot(ax=ax) check_format_of_first_point(ax, "t = 2014-01-01 y = 1.000000") - @pytest.mark.parametrize("freq", ["S", "T", "H", "D", "W", "M", "Q", "A"]) + @pytest.mark.parametrize("freq", ["s", "min", "H", "D", "W", "M", "Q", "A"]) def test_line_plot_period_series(self, freq): idx = period_range("12/31/1999", freq=freq, periods=100) ser = Series(np.random.default_rng(2).standard_normal(len(idx)), idx) _check_plot_works(ser.plot, ser.index.freq) @pytest.mark.parametrize( - "frqncy", ["1S", "3S", "5T", "7H", "4D", "8W", "11M", "3A"] + "frqncy", ["1s", "3s", "5min", "7H", "4D", "8W", "11M", "3A"] ) def test_line_plot_period_mlt_series(self, frqncy): # test period index line plot for series with multiples (`mlt`) of the @@ -203,14 +203,14 @@ def test_line_plot_period_mlt_series(self, frqncy): _check_plot_works(s.plot, s.index.freq.rule_code) @pytest.mark.parametrize( - "freq", ["S", "T", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] + "freq", ["s", "min", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] ) def test_line_plot_datetime_series(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) ser = Series(np.random.default_rng(2).standard_normal(len(idx)), idx) _check_plot_works(ser.plot, ser.index.freq.rule_code) - @pytest.mark.parametrize("freq", ["S", "T", "H", "D", "W", "M", "Q", "A"]) + @pytest.mark.parametrize("freq", ["s", "min", "H", "D", "W", "M", "Q", "A"]) def test_line_plot_period_frame(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) df = DataFrame( @@ -221,7 +221,7 @@ def test_line_plot_period_frame(self, freq): _check_plot_works(df.plot, df.index.freq) @pytest.mark.parametrize( - "frqncy", ["1S", "3S", "5T", "7H", "4D", "8W", "11M", "3A"] + "frqncy", ["1s", "3s", "5min", "7H", "4D", "8W", "11M", "3A"] ) def test_line_plot_period_mlt_frame(self, frqncy): # test period index line plot for DataFrames with multiples (`mlt`) @@ -238,7 +238,7 @@ def test_line_plot_period_mlt_frame(self, frqncy): @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") @pytest.mark.parametrize( - "freq", ["S", "T", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] + "freq", ["s", "min", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] ) def test_line_plot_datetime_frame(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -251,7 +251,7 @@ def test_line_plot_datetime_frame(self, freq): _check_plot_works(df.plot, freq) @pytest.mark.parametrize( - "freq", ["S", "T", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] + "freq", ["s", "min", "H", "D", "W", "M", "Q-DEC", "A", "1B30Min"] ) def test_line_plot_inferred_freq(self, freq): idx = date_range("12/31/1999", freq=freq, periods=100) @@ -288,7 +288,7 @@ def test_plot_multiple_inferred_freq(self): def test_uhf(self): import pandas.plotting._matplotlib.converter as conv - idx = date_range("2012-6-22 21:59:51.960928", freq="L", periods=500) + idx = date_range("2012-6-22 21:59:51.960928", freq="ms", periods=500) df = DataFrame( np.random.default_rng(2).standard_normal((len(idx), 2)), index=idx ) @@ -306,7 +306,7 @@ def test_uhf(self): assert xp == rs def test_irreg_hf(self): - idx = date_range("2012-6-22 21:59:51", freq="S", periods=10) + idx = date_range("2012-6-22 21:59:51", freq="s", periods=10) df = DataFrame( np.random.default_rng(2).standard_normal((len(idx), 2)), index=idx ) @@ -320,7 +320,7 @@ def test_irreg_hf(self): assert (np.fabs(diffs[1:] - [sec, sec * 2, sec]) < 1e-8).all() def test_irreg_hf_object(self): - idx = date_range("2012-6-22 21:59:51", freq="S", periods=10) + idx = date_range("2012-6-22 21:59:51", freq="s", periods=10) df2 = DataFrame( np.random.default_rng(2).standard_normal((len(idx), 2)), index=idx ) @@ -815,7 +815,7 @@ def test_mixed_freq_alignment(self): ts_data = np.random.default_rng(2).standard_normal(12) ts = Series(ts_data, index=ts_ind) - ts2 = ts.asfreq("T").interpolate() + ts2 = ts.asfreq("min").interpolate() _, ax = mpl.pyplot.subplots() ax = ts.plot(ax=ax) @@ -838,7 +838,7 @@ def test_mixed_freq_lf_first(self): mpl.pyplot.close(ax.get_figure()) def test_mixed_freq_lf_first_hourly(self): - idxh = date_range("1/1/1999", periods=240, freq="T") + idxh = date_range("1/1/1999", periods=240, freq="min") idxl = date_range("1/1/1999", periods=4, freq="H") high = Series(np.random.default_rng(2).standard_normal(len(idxh)), idxh) low = Series(np.random.default_rng(2).standard_normal(len(idxl)), idxl) @@ -846,7 +846,7 @@ def test_mixed_freq_lf_first_hourly(self): low.plot(ax=ax) high.plot(ax=ax) for line in ax.get_lines(): - assert PeriodIndex(data=line.get_xdata()).freq == "T" + assert PeriodIndex(data=line.get_xdata()).freq == "min" @pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning") def test_mixed_freq_irreg_period(self): @@ -1058,8 +1058,8 @@ def test_from_resampling_area_line_mixed_high_to_low(self, kind1, kind2): def test_mixed_freq_second_millisecond(self): # GH 7772, GH 7760 - idxh = date_range("2014-07-01 09:00", freq="S", periods=50) - idxl = date_range("2014-07-01 09:00", freq="100L", periods=500) + idxh = date_range("2014-07-01 09:00", freq="s", periods=50) + idxl = date_range("2014-07-01 09:00", freq="100ms", periods=500) high = Series(np.random.default_rng(2).standard_normal(len(idxh)), idxh) low = Series(np.random.default_rng(2).standard_normal(len(idxl)), idxl) # high to low @@ -1068,12 +1068,12 @@ def test_mixed_freq_second_millisecond(self): low.plot(ax=ax) assert len(ax.get_lines()) == 2 for line in ax.get_lines(): - assert PeriodIndex(data=line.get_xdata()).freq == "L" + assert PeriodIndex(data=line.get_xdata()).freq == "ms" def test_mixed_freq_second_millisecond_low_to_high(self): # GH 7772, GH 7760 - idxh = date_range("2014-07-01 09:00", freq="S", periods=50) - idxl = date_range("2014-07-01 09:00", freq="100L", periods=500) + idxh = date_range("2014-07-01 09:00", freq="s", periods=50) + idxl = date_range("2014-07-01 09:00", freq="100ms", periods=500) high = Series(np.random.default_rng(2).standard_normal(len(idxh)), idxh) low = Series(np.random.default_rng(2).standard_normal(len(idxl)), idxl) # low to high @@ -1082,7 +1082,7 @@ def test_mixed_freq_second_millisecond_low_to_high(self): high.plot(ax=ax) assert len(ax.get_lines()) == 2 for line in ax.get_lines(): - assert PeriodIndex(data=line.get_xdata()).freq == "L" + assert PeriodIndex(data=line.get_xdata()).freq == "ms" def test_irreg_dtypes(self): # date diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 55d78c516b6f3..3cea39fa75ece 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -41,7 +41,7 @@ def test_dt64_mean(self, tz_naive_fixture, box): assert obj.mean(skipna=False) is pd.NaT @pytest.mark.parametrize("box", [Series, pd.Index, PeriodArray]) - @pytest.mark.parametrize("freq", ["S", "H", "D", "W", "B"]) + @pytest.mark.parametrize("freq", ["s", "H", "D", "W", "B"]) def test_period_mean(self, box, freq): # GH#24757 dti = pd.date_range("2001-01-01", periods=11) diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 7a76a21a6c579..c39268f3b9477 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -83,8 +83,8 @@ def test_asfreq_fill_value(series, create_index): def test_resample_interpolate(frame): # GH#12925 df = frame - result = df.resample("1T").asfreq().interpolate() - expected = df.resample("1T").interpolate() + result = df.resample("1min").asfreq().interpolate() + expected = df.resample("1min").interpolate() tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index dbda751e82113..66ecb93385a87 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -82,7 +82,7 @@ def test_custom_grouper(index, unit): arr = [1] + [5] * 2592 idx = dti[0:-1:5] idx = idx.append(dti[-1:]) - idx = DatetimeIndex(idx, freq="5T").as_unit(unit) + idx = DatetimeIndex(idx, freq="5min").as_unit(unit) expect = Series(arr, index=idx) # GH2763 - return input dtype if we can @@ -140,21 +140,21 @@ def test_resample_integerarray(unit): # GH 25580, resample on IntegerArray ts = Series( range(9), - index=date_range("1/1/2000", periods=9, freq="T").as_unit(unit), + index=date_range("1/1/2000", periods=9, freq="min").as_unit(unit), dtype="Int64", ) - result = ts.resample("3T").sum() + result = ts.resample("3min").sum() expected = Series( [3, 12, 21], - index=date_range("1/1/2000", periods=3, freq="3T").as_unit(unit), + index=date_range("1/1/2000", periods=3, freq="3min").as_unit(unit), dtype="Int64", ) tm.assert_series_equal(result, expected) - result = ts.resample("3T").mean() + result = ts.resample("3min").mean() expected = Series( [1, 4, 7], - index=date_range("1/1/2000", periods=3, freq="3T").as_unit(unit), + index=date_range("1/1/2000", periods=3, freq="3min").as_unit(unit), dtype="Float64", ) tm.assert_series_equal(result, expected) @@ -493,7 +493,7 @@ def test_resample_how_method(unit): ), ) expected.index = expected.index.as_unit(unit) - tm.assert_series_equal(s.resample("10S").mean(), expected) + tm.assert_series_equal(s.resample("10s").mean(), expected) def test_resample_extra_index_point(unit): @@ -508,16 +508,16 @@ def test_resample_extra_index_point(unit): def test_upsample_with_limit(unit): - rng = date_range("1/1/2000", periods=3, freq="5t").as_unit(unit) + rng = date_range("1/1/2000", periods=3, freq="5min").as_unit(unit) ts = Series(np.random.default_rng(2).standard_normal(len(rng)), rng) - result = ts.resample("t").ffill(limit=2) + result = ts.resample("min").ffill(limit=2) expected = ts.reindex(result.index, method="ffill", limit=2) tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("freq", ["5D", "10H", "5Min", "10S"]) -@pytest.mark.parametrize("rule", ["Y", "3M", "15D", "30H", "15Min", "30S"]) +@pytest.mark.parametrize("freq", ["5D", "10H", "5Min", "10s"]) +@pytest.mark.parametrize("rule", ["Y", "3M", "15D", "30H", "15Min", "30s"]) def test_nearest_upsample_with_limit(tz_aware_fixture, freq, rule, unit): # GH 33939 rng = date_range("1/1/2000", periods=3, freq=freq, tz=tz_aware_fixture).as_unit( @@ -560,10 +560,10 @@ def test_resample_ohlc_result(unit): index = index.union(date_range("4-15-2000", "5-15-2000", freq="h").as_unit(unit)) s = Series(range(len(index)), index=index) - a = s.loc[:"4-15-2000"].resample("30T").ohlc() + a = s.loc[:"4-15-2000"].resample("30min").ohlc() assert isinstance(a, DataFrame) - b = s.loc[:"4-14-2000"].resample("30T").ohlc() + b = s.loc[:"4-14-2000"].resample("30min").ohlc() assert isinstance(b, DataFrame) @@ -744,7 +744,7 @@ def test_resample_axis1(unit): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("freq", ["t", "5t", "15t", "30t", "4h", "12h"]) +@pytest.mark.parametrize("freq", ["min", "5min", "15min", "30min", "4h", "12h"]) def test_resample_anchored_ticks(freq, unit): # If a fixed delta (5 minute, 4 hour) evenly divides a day, we should # "anchor" the origin at midnight so we get regular intervals rather @@ -1030,7 +1030,7 @@ def _create_series(values, timestamps, freq="D"): def test_resample_daily_anchored(unit): - rng = date_range("1/1/2000 0:00:00", periods=10000, freq="T").as_unit(unit) + rng = date_range("1/1/2000 0:00:00", periods=10000, freq="min").as_unit(unit) ts = Series(np.random.default_rng(2).standard_normal(len(rng)), index=rng) ts[:2] = np.nan # so results are the same @@ -1140,12 +1140,12 @@ def test_nanosecond_resample_error(): # Resampling using pd.tseries.offsets.Nano as period start = 1443707890427 exp_start = 1443707890400 - indx = date_range(start=pd.to_datetime(start), periods=10, freq="100n") + indx = date_range(start=pd.to_datetime(start), periods=10, freq="100ns") ts = Series(range(len(indx)), index=indx) r = ts.resample(pd.tseries.offsets.Nano(100)) result = r.agg("mean") - exp_indx = date_range(start=pd.to_datetime(exp_start), periods=10, freq="100n") + exp_indx = date_range(start=pd.to_datetime(exp_start), periods=10, freq="100ns") exp = Series(range(len(exp_indx)), index=exp_indx, dtype=float) tm.assert_series_equal(result, exp) @@ -1214,25 +1214,25 @@ def test_resample_anchored_multiday(label, sec): # # See: https://github.com/pandas-dev/pandas/issues/8683 - index1 = date_range("2014-10-14 23:06:23.206", periods=3, freq="400L") - index2 = date_range("2014-10-15 23:00:00", periods=2, freq="2200L") + index1 = date_range("2014-10-14 23:06:23.206", periods=3, freq="400ms") + index2 = date_range("2014-10-15 23:00:00", periods=2, freq="2200ms") index = index1.union(index2) s = Series(np.random.default_rng(2).standard_normal(5), index=index) # Ensure left closing works - result = s.resample("2200L", label=label).mean() + result = s.resample("2200ms", label=label).mean() assert result.index[-1] == Timestamp(f"2014-10-15 23:00:{sec}00") def test_corner_cases(unit): # miscellaneous test coverage - rng = date_range("1/1/2000", periods=12, freq="t").as_unit(unit) + rng = date_range("1/1/2000", periods=12, freq="min").as_unit(unit) ts = Series(np.random.default_rng(2).standard_normal(len(rng)), index=rng) - result = ts.resample("5t", closed="right", label="left").mean() - ex_index = date_range("1999-12-31 23:55", periods=4, freq="5t").as_unit(unit) + result = ts.resample("5min", closed="right", label="left").mean() + ex_index = date_range("1999-12-31 23:55", periods=4, freq="5min").as_unit(unit) tm.assert_index_equal(result.index, ex_index) @@ -1302,12 +1302,12 @@ def test_resample_median_bug_1688(dtype): dtype=dtype, ) - result = df.resample("T").apply(lambda x: x.mean()) - exp = df.asfreq("T") + result = df.resample("min").apply(lambda x: x.mean()) + exp = df.asfreq("min") tm.assert_frame_equal(result, exp) - result = df.resample("T").median() - exp = df.asfreq("T") + result = df.resample("min").median() + exp = df.asfreq("min") tm.assert_frame_equal(result, exp) @@ -1354,12 +1354,12 @@ def test_resample_consistency(unit): # GH 6418 # resample with bfill / limit / reindex consistency - i30 = date_range("2002-02-02", periods=4, freq="30T").as_unit(unit) + i30 = date_range("2002-02-02", periods=4, freq="30min").as_unit(unit) s = Series(np.arange(4.0), index=i30) s.iloc[2] = np.nan # Upsample by factor 3 with reindex() and resample() methods: - i10 = date_range(i30[0], i30[-1], freq="10T").as_unit(unit) + i10 = date_range(i30[0], i30[-1], freq="10min").as_unit(unit) s10 = s.reindex(index=i10, method="bfill") s10_2 = s.reindex(index=i10, method="bfill", limit=2) @@ -1493,11 +1493,13 @@ def test_resample_group_info(n, k, unit): # use a fixed seed to always have the same uniques prng = np.random.default_rng(2) - dr = date_range(start="2015-08-27", periods=n // 10, freq="T").as_unit(unit) + dr = date_range(start="2015-08-27", periods=n // 10, freq="min").as_unit(unit) ts = Series(prng.integers(0, n // k, n).astype("int64"), index=prng.choice(dr, n)) - left = ts.resample("30T").nunique() - ix = date_range(start=ts.index.min(), end=ts.index.max(), freq="30T").as_unit(unit) + left = ts.resample("30min").nunique() + ix = date_range(start=ts.index.min(), end=ts.index.max(), freq="30min").as_unit( + unit + ) vals = ts.values bins = np.searchsorted(ix.values, ts.index, side="right") @@ -1516,14 +1518,16 @@ def test_resample_group_info(n, k, unit): def test_resample_size(unit): n = 10000 - dr = date_range("2015-09-19", periods=n, freq="T").as_unit(unit) + dr = date_range("2015-09-19", periods=n, freq="min").as_unit(unit) ts = Series( np.random.default_rng(2).standard_normal(n), index=np.random.default_rng(2).choice(dr, n), ) - left = ts.resample("7T").size() - ix = date_range(start=left.index.min(), end=ts.index.max(), freq="7T").as_unit(unit) + left = ts.resample("7min").size() + ix = date_range(start=left.index.min(), end=ts.index.max(), freq="7min").as_unit( + unit + ) bins = np.searchsorted(ix.values, ts.index.values, side="right") val = np.bincount(bins, minlength=len(ix) + 1)[1:].astype("int64", copy=False) @@ -1828,13 +1832,13 @@ def f(data, add_arg): @pytest.mark.parametrize( "n1, freq1, n2, freq2", [ - (30, "S", 0.5, "Min"), - (60, "S", 1, "Min"), - (3600, "S", 1, "H"), + (30, "s", 0.5, "Min"), + (60, "s", 1, "Min"), + (3600, "s", 1, "H"), (60, "Min", 1, "H"), - (21600, "S", 0.25, "D"), - (86400, "S", 1, "D"), - (43200, "S", 0.5, "D"), + (21600, "s", 0.25, "D"), + (86400, "s", 1, "D"), + (43200, "s", 0.5, "D"), (1440, "Min", 1, "D"), (12, "H", 0.5, "D"), (24, "H", 1, "D"), diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index 7559a85de7a6b..bc0c1984cf2f3 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -219,13 +219,13 @@ def test_resample_basic(self): ) s[10:30] = np.nan index = PeriodIndex( - [Period("2013-01-01 00:00", "T"), Period("2013-01-01 00:01", "T")], + [Period("2013-01-01 00:00", "min"), Period("2013-01-01 00:01", "min")], name="idx", ) expected = Series([34.5, 79.5], index=index) - result = s.to_period().resample("T", kind="period").mean() + result = s.to_period().resample("min", kind="period").mean() tm.assert_series_equal(result, expected) - result2 = s.resample("T", kind="period").mean() + result2 = s.resample("min", kind="period").mean() tm.assert_series_equal(result2, expected) @pytest.mark.parametrize( @@ -325,11 +325,11 @@ def test_with_local_timezone_dateutil(self): def test_resample_nonexistent_time_bin_edge(self): # GH 19375 - index = date_range("2017-03-12", "2017-03-12 1:45:00", freq="15T") + index = date_range("2017-03-12", "2017-03-12 1:45:00", freq="15min") s = Series(np.zeros(len(index)), index=index) expected = s.tz_localize("US/Pacific") - expected.index = pd.DatetimeIndex(expected.index, freq="900S") - result = expected.resample("900S").mean() + expected.index = pd.DatetimeIndex(expected.index, freq="900s") + result = expected.resample("900s").mean() tm.assert_series_equal(result, expected) # GH 23742 @@ -350,10 +350,13 @@ def test_resample_nonexistent_time_bin_edge(self): def test_resample_ambiguous_time_bin_edge(self): # GH 10117 idx = date_range( - "2014-10-25 22:00:00", "2014-10-26 00:30:00", freq="30T", tz="Europe/London" + "2014-10-25 22:00:00", + "2014-10-26 00:30:00", + freq="30min", + tz="Europe/London", ) expected = Series(np.zeros(len(idx)), index=idx) - result = expected.resample("30T").mean() + result = expected.resample("30min").mean() tm.assert_series_equal(result, expected) def test_fill_method_and_how_upsample(self): @@ -438,7 +441,7 @@ def test_cant_fill_missing_dups(self): @pytest.mark.parametrize("freq", ["5min"]) @pytest.mark.parametrize("kind", ["period", None, "timestamp"]) def test_resample_5minute(self, freq, kind): - rng = period_range("1/1/2000", "1/5/2000", freq="T") + rng = period_range("1/1/2000", "1/5/2000", freq="min") ts = Series(np.random.default_rng(2).standard_normal(len(rng)), index=rng) expected = ts.to_timestamp().resample(freq).mean() if kind != "timestamp": @@ -505,7 +508,7 @@ def test_resample_tz_localized(self): # #2245 idx = date_range( - "2001-09-20 15:59", "2001-09-20 16:00", freq="T", tz="Australia/Sydney" + "2001-09-20 15:59", "2001-09-20 16:00", freq="min", tz="Australia/Sydney" ) s = Series([1, 2], index=idx) @@ -653,7 +656,7 @@ def test_default_right_closed_label(self, from_freq, to_freq): @pytest.mark.parametrize( "from_freq, to_freq", - [("D", "MS"), ("Q", "AS"), ("M", "QS"), ("H", "D"), ("T", "H")], + [("D", "MS"), ("Q", "AS"), ("M", "QS"), ("H", "D"), ("min", "H")], ) def test_default_left_closed_label(self, from_freq, to_freq): idx = date_range(start="8/15/2012", periods=100, freq=from_freq) @@ -800,7 +803,7 @@ def test_upsampling_ohlc(self, freq, period_mult, kind): ) def test_resample_with_nat(self, periods, values, freq, expected_values): # GH 13224 - index = PeriodIndex(periods, freq="S") + index = PeriodIndex(periods, freq="s") frame = DataFrame(values, index=index) expected_index = period_range( @@ -812,7 +815,7 @@ def test_resample_with_nat(self, periods, values, freq, expected_values): def test_resample_with_only_nat(self): # GH 13224 - pi = PeriodIndex([pd.NaT] * 3, freq="S") + pi = PeriodIndex([pd.NaT] * 3, freq="s") frame = DataFrame([2, 3, 5], index=pi, columns=["a"]) expected_index = PeriodIndex(data=[], freq=pi.freq) expected = DataFrame(index=expected_index, columns=["a"], dtype="float64") @@ -893,3 +896,22 @@ def test_sum_min_count(self): [3.0, np.nan], index=PeriodIndex(["2018Q1", "2018Q2"], freq="Q-DEC") ) tm.assert_series_equal(result, expected) + + def test_resample_t_l_deprecated(self): + # GH 52536 + msg_t = "'T' is deprecated and will be removed in a future version." + msg_l = "'L' is deprecated and will be removed in a future version." + + with tm.assert_produces_warning(FutureWarning, match=msg_l): + rng_l = period_range( + "2020-01-01 00:00:00 00:00", "2020-01-01 00:00:00 00:01", freq="L" + ) + ser = Series(np.arange(len(rng_l)), index=rng_l) + + rng = period_range( + "2020-01-01 00:00:00 00:00", "2020-01-01 00:00:00 00:01", freq="min" + ) + expected = Series([29999.5, 60000.0], index=rng) + with tm.assert_produces_warning(FutureWarning, match=msg_t): + result = ser.resample("T").mean() + tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 1cfcf555355b5..1b20a7b99d1d7 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -171,7 +171,7 @@ def test_attribute_access(test_frame): def test_api_compat_before_use(attr): # make sure that we are setting the binner # on these attributes - rng = date_range("1/1/2012", periods=100, freq="S") + rng = date_range("1/1/2012", periods=100, freq="s") ts = Series(np.arange(len(rng)), index=rng) rs = ts.resample("30s") @@ -201,7 +201,7 @@ def tests_raises_on_nuisance(test_frame): def test_downsample_but_actually_upsampling(): # this is reindex / asfreq - rng = date_range("1/1/2012", periods=100, freq="S") + rng = date_range("1/1/2012", periods=100, freq="s") ts = Series(np.arange(len(rng), dtype="int64"), index=rng) result = ts.resample("20s").asfreq() expected = Series( @@ -216,7 +216,7 @@ def test_combined_up_downsampling_of_irregular(): # ts2.resample('2s').mean().ffill() # preserve these semantics - rng = date_range("1/1/2012", periods=100, freq="S") + rng = date_range("1/1/2012", periods=100, freq="s") ts = Series(np.arange(len(rng)), index=rng) ts2 = ts.iloc[[0, 1, 2, 3, 5, 7, 11, 15, 16, 25, 30]] @@ -260,7 +260,7 @@ def test_combined_up_downsampling_of_irregular(): "2012-01-01 00:00:30", ], dtype="datetime64[ns]", - freq="2S", + freq="2s", ), ) tm.assert_series_equal(result, expected) @@ -294,7 +294,7 @@ def test_transform_frame(on): def test_fillna(): # need to upsample here - rng = date_range("1/1/2012", periods=10, freq="2S") + rng = date_range("1/1/2012", periods=10, freq="2s") ts = Series(np.arange(len(rng), dtype="int64"), index=rng) r = ts.resample("s") @@ -344,11 +344,11 @@ def test_agg_consistency(): # similar aggregations with and w/o selection list df = DataFrame( np.random.default_rng(2).standard_normal((1000, 3)), - index=date_range("1/1/2012", freq="S", periods=1000), + index=date_range("1/1/2012", freq="s", periods=1000), columns=["A", "B", "C"], ) - r = df.resample("3T") + r = df.resample("3min") msg = r"Column\(s\) \['r1', 'r2'\] do not exist" with pytest.raises(KeyError, match=msg): @@ -359,11 +359,11 @@ def test_agg_consistency_int_str_column_mix(): # GH#39025 df = DataFrame( np.random.default_rng(2).standard_normal((1000, 2)), - index=date_range("1/1/2012", freq="S", periods=1000), + index=date_range("1/1/2012", freq="s", periods=1000), columns=[1, "a"], ) - r = df.resample("3T") + r = df.resample("3min") msg = r"Column\(s\) \[2, 'b'\] do not exist" with pytest.raises(KeyError, match=msg): @@ -650,7 +650,7 @@ def test_try_aggregate_non_existing_column(): # Error as we don't have 'z' column msg = r"Column\(s\) \['z'\] do not exist" with pytest.raises(KeyError, match=msg): - df.resample("30T").agg({"x": ["mean"], "y": ["median"], "z": ["sum"]}) + df.resample("30min").agg({"x": ["mean"], "y": ["median"], "z": ["sum"]}) def test_agg_list_like_func_with_args(): diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 62b0bc2012af1..6f4f1154907dc 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -184,7 +184,7 @@ def test_groupby_with_origin(): def test_nearest(): # GH 17496 # Resample nearest - index = date_range("1/1/2000", periods=3, freq="T") + index = date_range("1/1/2000", periods=3, freq="min") result = Series(range(3), index=index).resample("20s").nearest() expected = Series( @@ -200,7 +200,7 @@ def test_nearest(): "2000-01-01 00:02:00", ], dtype="datetime64[ns]", - freq="20S", + freq="20s", ), ) tm.assert_series_equal(result, expected) @@ -321,7 +321,7 @@ def weighted_quantile(series, weights, q): cutoff = cumsum.iloc[-1] * q return series[cumsum >= cutoff].iloc[0] - times = date_range("2017-6-23 18:00", periods=8, freq="15T", tz="UTC") + times = date_range("2017-6-23 18:00", periods=8, freq="15min", tz="UTC") data = Series([1.0, 1, 1, 1, 1, 2, 2, 0], index=times) weights = Series([160.0, 91, 65, 43, 24, 10, 1, 0], index=times) diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index 8c06f1e8a1e38..d7fdbc4fe5f08 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -305,10 +305,10 @@ def test_repr(): ) def test_upsample_sum(method, method_args, expected_values): s = Series(1, index=date_range("2017", periods=2, freq="H")) - resampled = s.resample("30T") + resampled = s.resample("30min") index = pd.DatetimeIndex( ["2017-01-01T00:00:00", "2017-01-01T00:30:00", "2017-01-01T01:00:00"], - freq="30T", + freq="30min", ) result = methodcaller(method, **method_args)(resampled) expected = Series(expected_values, index=index) diff --git a/pandas/tests/resample/test_timedelta.py b/pandas/tests/resample/test_timedelta.py index a119a911e5fbe..79b13673e70c6 100644 --- a/pandas/tests/resample/test_timedelta.py +++ b/pandas/tests/resample/test_timedelta.py @@ -14,10 +14,10 @@ def test_asfreq_bug(): df = DataFrame(data=[1, 3], index=[timedelta(), timedelta(minutes=3)]) - result = df.resample("1T").asfreq() + result = df.resample("1min").asfreq() expected = DataFrame( data=[1, np.nan, np.nan, 3], - index=timedelta_range("0 day", periods=4, freq="1T"), + index=timedelta_range("0 day", periods=4, freq="1min"), ) tm.assert_frame_equal(result, expected) @@ -28,19 +28,19 @@ def test_resample_with_nat(): result = DataFrame({"value": [2, 3, 5]}, index).resample("1s").mean() expected = DataFrame( {"value": [2.5, np.nan, 5.0]}, - index=timedelta_range("0 day", periods=3, freq="1S"), + index=timedelta_range("0 day", periods=3, freq="1s"), ) tm.assert_frame_equal(result, expected) def test_resample_as_freq_with_subperiod(): # GH 13022 - index = timedelta_range("00:00:00", "00:10:00", freq="5T") + index = timedelta_range("00:00:00", "00:10:00", freq="5min") df = DataFrame(data={"value": [1, 5, 10]}, index=index) - result = df.resample("2T").asfreq() + result = df.resample("2min").asfreq() expected_data = {"value": [1, np.nan, np.nan, np.nan, np.nan, 10]} expected = DataFrame( - data=expected_data, index=timedelta_range("00:00:00", "00:10:00", freq="2T") + data=expected_data, index=timedelta_range("00:00:00", "00:10:00", freq="2min") ) tm.assert_frame_equal(result, expected) @@ -71,9 +71,9 @@ def test_resample_single_period_timedelta(): def test_resample_timedelta_idempotency(): # GH 12072 - index = timedelta_range("0", periods=9, freq="10L") + index = timedelta_range("0", periods=9, freq="10ms") series = Series(range(9), index=index) - result = series.resample("10L").mean() + result = series.resample("10ms").mean() expected = series.astype(float) tm.assert_series_equal(result, expected) @@ -128,13 +128,13 @@ def test_resample_timedelta_values(): @pytest.mark.parametrize( "start, end, freq, resample_freq", [ - ("8H", "21h59min50s", "10S", "3H"), # GH 30353 example + ("8H", "21h59min50s", "10s", "3H"), # GH 30353 example ("3H", "22H", "1H", "5H"), ("527D", "5006D", "3D", "10D"), ("1D", "10D", "1D", "2D"), # GH 13022 example # tests that worked before GH 33498: - ("8H", "21h59min50s", "10S", "2H"), - ("0H", "21h59min50s", "10S", "3H"), + ("8H", "21h59min50s", "10s", "2H"), + ("0H", "21h59min50s", "10s", "3H"), ("10D", "85D", "D", "2D"), ], ) @@ -155,7 +155,7 @@ def test_resample_with_timedelta_yields_no_empty_groups(duplicates): # GH 10603 df = DataFrame( np.random.default_rng(2).normal(size=(10000, 4)), - index=timedelta_range(start="0s", periods=10000, freq="3906250n"), + index=timedelta_range(start="0s", periods=10000, freq="3906250ns"), ) if duplicates: # case with non-unique columns @@ -196,11 +196,11 @@ def test_resample_closed_right(): # GH#45414 idx = pd.Index([pd.Timedelta(seconds=120 + i * 30) for i in range(10)]) ser = Series(range(10), index=idx) - result = ser.resample("T", closed="right", label="right").sum() + result = ser.resample("min", closed="right", label="right").sum() expected = Series( [0, 3, 7, 11, 15, 9], index=pd.TimedeltaIndex( - [pd.Timedelta(seconds=120 + i * 60) for i in range(6)], freq="T" + [pd.Timedelta(seconds=120 + i * 60) for i in range(6)], freq="min" ), ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index a06fc5eede55c..2f50a19189987 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -112,7 +112,7 @@ def test_concat_datetime_timezone(self): def test_concat_datetimeindex_freq(self): # GH 3232 # Monotonic index result - dr = date_range("01-Jan-2013", periods=100, freq="50L", tz="UTC") + dr = date_range("01-Jan-2013", periods=100, freq="50ms", tz="UTC") data = list(range(100)) expected = DataFrame(data, index=dr) result = concat([expected[:50], expected[50:]]) diff --git a/pandas/tests/scalar/interval/test_interval.py b/pandas/tests/scalar/interval/test_interval.py index 192aaacbac2b5..a02dbf0a0413f 100644 --- a/pandas/tests/scalar/interval/test_interval.py +++ b/pandas/tests/scalar/interval/test_interval.py @@ -81,7 +81,7 @@ def test_hash(self, interval): (Timedelta("0 days"), Timedelta("5 days"), Timedelta("5 days")), (Timedelta("10 days"), Timedelta("10 days"), Timedelta("0 days")), (Timedelta("1H10min"), Timedelta("5H5min"), Timedelta("3H55min")), - (Timedelta("5S"), Timedelta("1H"), Timedelta("59min55S")), + (Timedelta("5s"), Timedelta("1H"), Timedelta("59min55s")), ], ) def test_length(self, left, right, expected): diff --git a/pandas/tests/scalar/period/test_asfreq.py b/pandas/tests/scalar/period/test_asfreq.py index f6c1675766210..00285148a3c90 100644 --- a/pandas/tests/scalar/period/test_asfreq.py +++ b/pandas/tests/scalar/period/test_asfreq.py @@ -50,13 +50,13 @@ def test_to_timestamp_out_of_bounds(self): def test_asfreq_corner(self): val = Period(freq="A", year=2007) - result1 = val.asfreq("5t") - result2 = val.asfreq("t") - expected = Period("2007-12-31 23:59", freq="t") + result1 = val.asfreq("5min") + result2 = val.asfreq("min") + expected = Period("2007-12-31 23:59", freq="min") assert result1.ordinal == expected.ordinal - assert result1.freqstr == "5T" + assert result1.freqstr == "5min" assert result2.ordinal == expected.ordinal - assert result2.freqstr == "T" + assert result2.freqstr == "min" def test_conv_annual(self): # frequency conversion tests: from Annual Frequency @@ -87,10 +87,10 @@ def test_conv_annual(self): freq="Min", year=2007, month=12, day=31, hour=23, minute=59 ) ival_A_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_A_to_S_end = Period( - freq="S", year=2007, month=12, day=31, hour=23, minute=59, second=59 + freq="s", year=2007, month=12, day=31, hour=23, minute=59, second=59 ) ival_AJAN_to_D_end = Period(freq="D", year=2007, month=1, day=31) @@ -100,33 +100,37 @@ def test_conv_annual(self): ival_ANOV_to_D_end = Period(freq="D", year=2007, month=11, day=30) ival_ANOV_to_D_start = Period(freq="D", year=2006, month=12, day=1) - assert ival_A.asfreq("Q", "S") == ival_A_to_Q_start + assert ival_A.asfreq("Q", "s") == ival_A_to_Q_start assert ival_A.asfreq("Q", "e") == ival_A_to_Q_end assert ival_A.asfreq("M", "s") == ival_A_to_M_start assert ival_A.asfreq("M", "E") == ival_A_to_M_end - assert ival_A.asfreq("W", "S") == ival_A_to_W_start + assert ival_A.asfreq("W", "s") == ival_A_to_W_start assert ival_A.asfreq("W", "E") == ival_A_to_W_end with tm.assert_produces_warning(FutureWarning, match=bday_msg): - assert ival_A.asfreq("B", "S") == ival_A_to_B_start + assert ival_A.asfreq("B", "s") == ival_A_to_B_start assert ival_A.asfreq("B", "E") == ival_A_to_B_end - assert ival_A.asfreq("D", "S") == ival_A_to_D_start + assert ival_A.asfreq("D", "s") == ival_A_to_D_start assert ival_A.asfreq("D", "E") == ival_A_to_D_end - assert ival_A.asfreq("H", "S") == ival_A_to_H_start + assert ival_A.asfreq("H", "s") == ival_A_to_H_start assert ival_A.asfreq("H", "E") == ival_A_to_H_end - assert ival_A.asfreq("min", "S") == ival_A_to_T_start + assert ival_A.asfreq("min", "s") == ival_A_to_T_start assert ival_A.asfreq("min", "E") == ival_A_to_T_end - assert ival_A.asfreq("T", "S") == ival_A_to_T_start - assert ival_A.asfreq("T", "E") == ival_A_to_T_end - assert ival_A.asfreq("S", "S") == ival_A_to_S_start - assert ival_A.asfreq("S", "E") == ival_A_to_S_end - - assert ival_AJAN.asfreq("D", "S") == ival_AJAN_to_D_start + msg = "'T' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + assert ival_A.asfreq("T", "s") == ival_A_to_T_start + assert ival_A.asfreq("T", "E") == ival_A_to_T_end + msg = "'S' is deprecated and will be removed in a future version." + with tm.assert_produces_warning(FutureWarning, match=msg): + assert ival_A.asfreq("S", "S") == ival_A_to_S_start + assert ival_A.asfreq("S", "E") == ival_A_to_S_end + + assert ival_AJAN.asfreq("D", "s") == ival_AJAN_to_D_start assert ival_AJAN.asfreq("D", "E") == ival_AJAN_to_D_end - assert ival_AJUN.asfreq("D", "S") == ival_AJUN_to_D_start + assert ival_AJUN.asfreq("D", "s") == ival_AJUN_to_D_start assert ival_AJUN.asfreq("D", "E") == ival_AJUN_to_D_end - assert ival_ANOV.asfreq("D", "S") == ival_ANOV_to_D_start + assert ival_ANOV.asfreq("D", "s") == ival_ANOV_to_D_start assert ival_ANOV.asfreq("D", "E") == ival_ANOV_to_D_end assert ival_A.asfreq("A") == ival_A @@ -159,10 +163,10 @@ def test_conv_quarterly(self): freq="Min", year=2007, month=3, day=31, hour=23, minute=59 ) ival_Q_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_Q_to_S_end = Period( - freq="S", year=2007, month=3, day=31, hour=23, minute=59, second=59 + freq="s", year=2007, month=3, day=31, hour=23, minute=59, second=59 ) ival_QEJAN_to_D_start = Period(freq="D", year=2006, month=2, day=1) @@ -174,25 +178,25 @@ def test_conv_quarterly(self): assert ival_Q.asfreq("A") == ival_Q_to_A assert ival_Q_end_of_year.asfreq("A") == ival_Q_to_A - assert ival_Q.asfreq("M", "S") == ival_Q_to_M_start + assert ival_Q.asfreq("M", "s") == ival_Q_to_M_start assert ival_Q.asfreq("M", "E") == ival_Q_to_M_end - assert ival_Q.asfreq("W", "S") == ival_Q_to_W_start + assert ival_Q.asfreq("W", "s") == ival_Q_to_W_start assert ival_Q.asfreq("W", "E") == ival_Q_to_W_end with tm.assert_produces_warning(FutureWarning, match=bday_msg): - assert ival_Q.asfreq("B", "S") == ival_Q_to_B_start + assert ival_Q.asfreq("B", "s") == ival_Q_to_B_start assert ival_Q.asfreq("B", "E") == ival_Q_to_B_end - assert ival_Q.asfreq("D", "S") == ival_Q_to_D_start + assert ival_Q.asfreq("D", "s") == ival_Q_to_D_start assert ival_Q.asfreq("D", "E") == ival_Q_to_D_end - assert ival_Q.asfreq("H", "S") == ival_Q_to_H_start + assert ival_Q.asfreq("H", "s") == ival_Q_to_H_start assert ival_Q.asfreq("H", "E") == ival_Q_to_H_end - assert ival_Q.asfreq("Min", "S") == ival_Q_to_T_start + assert ival_Q.asfreq("Min", "s") == ival_Q_to_T_start assert ival_Q.asfreq("Min", "E") == ival_Q_to_T_end - assert ival_Q.asfreq("S", "S") == ival_Q_to_S_start - assert ival_Q.asfreq("S", "E") == ival_Q_to_S_end + assert ival_Q.asfreq("s", "s") == ival_Q_to_S_start + assert ival_Q.asfreq("s", "E") == ival_Q_to_S_end - assert ival_QEJAN.asfreq("D", "S") == ival_QEJAN_to_D_start + assert ival_QEJAN.asfreq("D", "s") == ival_QEJAN_to_D_start assert ival_QEJAN.asfreq("D", "E") == ival_QEJAN_to_D_end - assert ival_QEJUN.asfreq("D", "S") == ival_QEJUN_to_D_start + assert ival_QEJUN.asfreq("D", "s") == ival_QEJUN_to_D_start assert ival_QEJUN.asfreq("D", "E") == ival_QEJUN_to_D_end assert ival_Q.asfreq("Q") == ival_Q @@ -221,10 +225,10 @@ def test_conv_monthly(self): freq="Min", year=2007, month=1, day=31, hour=23, minute=59 ) ival_M_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_M_to_S_end = Period( - freq="S", year=2007, month=1, day=31, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=31, hour=23, minute=59, second=59 ) assert ival_M.asfreq("A") == ival_M_to_A @@ -232,19 +236,19 @@ def test_conv_monthly(self): assert ival_M.asfreq("Q") == ival_M_to_Q assert ival_M_end_of_quarter.asfreq("Q") == ival_M_to_Q - assert ival_M.asfreq("W", "S") == ival_M_to_W_start + assert ival_M.asfreq("W", "s") == ival_M_to_W_start assert ival_M.asfreq("W", "E") == ival_M_to_W_end with tm.assert_produces_warning(FutureWarning, match=bday_msg): - assert ival_M.asfreq("B", "S") == ival_M_to_B_start + assert ival_M.asfreq("B", "s") == ival_M_to_B_start assert ival_M.asfreq("B", "E") == ival_M_to_B_end - assert ival_M.asfreq("D", "S") == ival_M_to_D_start + assert ival_M.asfreq("D", "s") == ival_M_to_D_start assert ival_M.asfreq("D", "E") == ival_M_to_D_end - assert ival_M.asfreq("H", "S") == ival_M_to_H_start + assert ival_M.asfreq("H", "s") == ival_M_to_H_start assert ival_M.asfreq("H", "E") == ival_M_to_H_end - assert ival_M.asfreq("Min", "S") == ival_M_to_T_start + assert ival_M.asfreq("Min", "s") == ival_M_to_T_start assert ival_M.asfreq("Min", "E") == ival_M_to_T_end - assert ival_M.asfreq("S", "S") == ival_M_to_S_start - assert ival_M.asfreq("S", "E") == ival_M_to_S_end + assert ival_M.asfreq("s", "s") == ival_M_to_S_start + assert ival_M.asfreq("s", "E") == ival_M_to_S_end assert ival_M.asfreq("M") == ival_M @@ -311,10 +315,10 @@ def test_conv_weekly(self): freq="Min", year=2007, month=1, day=7, hour=23, minute=59 ) ival_W_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_W_to_S_end = Period( - freq="S", year=2007, month=1, day=7, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=7, hour=23, minute=59, second=59 ) assert ival_W.asfreq("A") == ival_W_to_A @@ -327,33 +331,33 @@ def test_conv_weekly(self): assert ival_W_end_of_month.asfreq("M") == ival_W_to_M_end_of_month with tm.assert_produces_warning(FutureWarning, match=bday_msg): - assert ival_W.asfreq("B", "S") == ival_W_to_B_start + assert ival_W.asfreq("B", "s") == ival_W_to_B_start assert ival_W.asfreq("B", "E") == ival_W_to_B_end - assert ival_W.asfreq("D", "S") == ival_W_to_D_start + assert ival_W.asfreq("D", "s") == ival_W_to_D_start assert ival_W.asfreq("D", "E") == ival_W_to_D_end - assert ival_WSUN.asfreq("D", "S") == ival_WSUN_to_D_start + assert ival_WSUN.asfreq("D", "s") == ival_WSUN_to_D_start assert ival_WSUN.asfreq("D", "E") == ival_WSUN_to_D_end - assert ival_WSAT.asfreq("D", "S") == ival_WSAT_to_D_start + assert ival_WSAT.asfreq("D", "s") == ival_WSAT_to_D_start assert ival_WSAT.asfreq("D", "E") == ival_WSAT_to_D_end - assert ival_WFRI.asfreq("D", "S") == ival_WFRI_to_D_start + assert ival_WFRI.asfreq("D", "s") == ival_WFRI_to_D_start assert ival_WFRI.asfreq("D", "E") == ival_WFRI_to_D_end - assert ival_WTHU.asfreq("D", "S") == ival_WTHU_to_D_start + assert ival_WTHU.asfreq("D", "s") == ival_WTHU_to_D_start assert ival_WTHU.asfreq("D", "E") == ival_WTHU_to_D_end - assert ival_WWED.asfreq("D", "S") == ival_WWED_to_D_start + assert ival_WWED.asfreq("D", "s") == ival_WWED_to_D_start assert ival_WWED.asfreq("D", "E") == ival_WWED_to_D_end - assert ival_WTUE.asfreq("D", "S") == ival_WTUE_to_D_start + assert ival_WTUE.asfreq("D", "s") == ival_WTUE_to_D_start assert ival_WTUE.asfreq("D", "E") == ival_WTUE_to_D_end - assert ival_WMON.asfreq("D", "S") == ival_WMON_to_D_start + assert ival_WMON.asfreq("D", "s") == ival_WMON_to_D_start assert ival_WMON.asfreq("D", "E") == ival_WMON_to_D_end - assert ival_W.asfreq("H", "S") == ival_W_to_H_start + assert ival_W.asfreq("H", "s") == ival_W_to_H_start assert ival_W.asfreq("H", "E") == ival_W_to_H_end - assert ival_W.asfreq("Min", "S") == ival_W_to_T_start + assert ival_W.asfreq("Min", "s") == ival_W_to_T_start assert ival_W.asfreq("Min", "E") == ival_W_to_T_end - assert ival_W.asfreq("S", "S") == ival_W_to_S_start - assert ival_W.asfreq("S", "E") == ival_W_to_S_end + assert ival_W.asfreq("s", "s") == ival_W_to_S_start + assert ival_W.asfreq("s", "E") == ival_W_to_S_end assert ival_W.asfreq("W") == ival_W @@ -404,10 +408,10 @@ def test_conv_business(self): freq="Min", year=2007, month=1, day=1, hour=23, minute=59 ) ival_B_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_B_to_S_end = Period( - freq="S", year=2007, month=1, day=1, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=1, hour=23, minute=59, second=59 ) assert ival_B.asfreq("A") == ival_B_to_A @@ -421,12 +425,12 @@ def test_conv_business(self): assert ival_B.asfreq("D") == ival_B_to_D - assert ival_B.asfreq("H", "S") == ival_B_to_H_start + assert ival_B.asfreq("H", "s") == ival_B_to_H_start assert ival_B.asfreq("H", "E") == ival_B_to_H_end - assert ival_B.asfreq("Min", "S") == ival_B_to_T_start + assert ival_B.asfreq("Min", "s") == ival_B_to_T_start assert ival_B.asfreq("Min", "E") == ival_B_to_T_end - assert ival_B.asfreq("S", "S") == ival_B_to_S_start - assert ival_B.asfreq("S", "E") == ival_B_to_S_end + assert ival_B.asfreq("s", "s") == ival_B_to_S_start + assert ival_B.asfreq("s", "E") == ival_B_to_S_end with tm.assert_produces_warning(FutureWarning, match=bday_msg): assert ival_B.asfreq("B") == ival_B @@ -470,10 +474,10 @@ def test_conv_daily(self): freq="Min", year=2007, month=1, day=1, hour=23, minute=59 ) ival_D_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_D_to_S_end = Period( - freq="S", year=2007, month=1, day=1, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=1, hour=23, minute=59, second=59 ) assert ival_D.asfreq("A") == ival_D_to_A @@ -494,17 +498,17 @@ def test_conv_daily(self): with tm.assert_produces_warning(FutureWarning, match=bday_msg): assert ival_D_friday.asfreq("B") == ival_B_friday - assert ival_D_saturday.asfreq("B", "S") == ival_B_friday + assert ival_D_saturday.asfreq("B", "s") == ival_B_friday assert ival_D_saturday.asfreq("B", "E") == ival_B_monday - assert ival_D_sunday.asfreq("B", "S") == ival_B_friday + assert ival_D_sunday.asfreq("B", "s") == ival_B_friday assert ival_D_sunday.asfreq("B", "E") == ival_B_monday - assert ival_D.asfreq("H", "S") == ival_D_to_H_start + assert ival_D.asfreq("H", "s") == ival_D_to_H_start assert ival_D.asfreq("H", "E") == ival_D_to_H_end - assert ival_D.asfreq("Min", "S") == ival_D_to_T_start + assert ival_D.asfreq("Min", "s") == ival_D_to_T_start assert ival_D.asfreq("Min", "E") == ival_D_to_T_end - assert ival_D.asfreq("S", "S") == ival_D_to_S_start - assert ival_D.asfreq("S", "E") == ival_D_to_S_end + assert ival_D.asfreq("s", "s") == ival_D_to_S_start + assert ival_D.asfreq("s", "E") == ival_D_to_S_end assert ival_D.asfreq("D") == ival_D @@ -534,10 +538,10 @@ def test_conv_hourly(self): freq="Min", year=2007, month=1, day=1, hour=0, minute=59 ) ival_H_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_H_to_S_end = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=59, second=59 + freq="s", year=2007, month=1, day=1, hour=0, minute=59, second=59 ) assert ival_H.asfreq("A") == ival_H_to_A @@ -554,10 +558,10 @@ def test_conv_hourly(self): assert ival_H.asfreq("B") == ival_H_to_B assert ival_H_end_of_bus.asfreq("B") == ival_H_to_B - assert ival_H.asfreq("Min", "S") == ival_H_to_T_start + assert ival_H.asfreq("Min", "s") == ival_H_to_T_start assert ival_H.asfreq("Min", "E") == ival_H_to_T_end - assert ival_H.asfreq("S", "S") == ival_H_to_S_start - assert ival_H.asfreq("S", "E") == ival_H_to_S_end + assert ival_H.asfreq("s", "s") == ival_H_to_S_start + assert ival_H.asfreq("s", "E") == ival_H_to_S_end assert ival_H.asfreq("H") == ival_H @@ -597,10 +601,10 @@ def test_conv_minutely(self): ival_T_to_H = Period(freq="H", year=2007, month=1, day=1, hour=0) ival_T_to_S_start = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0 ) ival_T_to_S_end = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=59 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=59 ) assert ival_T.asfreq("A") == ival_T_to_A @@ -619,38 +623,38 @@ def test_conv_minutely(self): assert ival_T.asfreq("H") == ival_T_to_H assert ival_T_end_of_hour.asfreq("H") == ival_T_to_H - assert ival_T.asfreq("S", "S") == ival_T_to_S_start - assert ival_T.asfreq("S", "E") == ival_T_to_S_end + assert ival_T.asfreq("s", "s") == ival_T_to_S_start + assert ival_T.asfreq("s", "E") == ival_T_to_S_end assert ival_T.asfreq("Min") == ival_T def test_conv_secondly(self): # frequency conversion tests: from Secondly Frequency" - ival_S = Period(freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=0) + ival_S = Period(freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=0) ival_S_end_of_year = Period( - freq="S", year=2007, month=12, day=31, hour=23, minute=59, second=59 + freq="s", year=2007, month=12, day=31, hour=23, minute=59, second=59 ) ival_S_end_of_quarter = Period( - freq="S", year=2007, month=3, day=31, hour=23, minute=59, second=59 + freq="s", year=2007, month=3, day=31, hour=23, minute=59, second=59 ) ival_S_end_of_month = Period( - freq="S", year=2007, month=1, day=31, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=31, hour=23, minute=59, second=59 ) ival_S_end_of_week = Period( - freq="S", year=2007, month=1, day=7, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=7, hour=23, minute=59, second=59 ) ival_S_end_of_day = Period( - freq="S", year=2007, month=1, day=1, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=1, hour=23, minute=59, second=59 ) ival_S_end_of_bus = Period( - freq="S", year=2007, month=1, day=1, hour=23, minute=59, second=59 + freq="s", year=2007, month=1, day=1, hour=23, minute=59, second=59 ) ival_S_end_of_hour = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=59, second=59 + freq="s", year=2007, month=1, day=1, hour=0, minute=59, second=59 ) ival_S_end_of_minute = Period( - freq="S", year=2007, month=1, day=1, hour=0, minute=0, second=59 + freq="s", year=2007, month=1, day=1, hour=0, minute=0, second=59 ) ival_S_to_A = Period(freq="A", year=2007) @@ -681,12 +685,12 @@ def test_conv_secondly(self): assert ival_S.asfreq("Min") == ival_S_to_T assert ival_S_end_of_minute.asfreq("Min") == ival_S_to_T - assert ival_S.asfreq("S") == ival_S + assert ival_S.asfreq("s") == ival_S def test_conv_microsecond(self): # GH#31475 Avoid floating point errors dropping the start_time to # before the beginning of the Period - per = Period("2020-01-30 15:57:27.576166", freq="U") + per = Period("2020-01-30 15:57:27.576166", freq="us") assert per.ordinal == 1580399847576166 start = per.start_time @@ -733,7 +737,7 @@ def test_asfreq_mult(self): assert result.freq == expected.freq # ordinal will not change for freq in ["A", offsets.YearEnd()]: - result = p.asfreq(freq, how="S") + result = p.asfreq(freq, how="s") expected = Period("2007", freq="A") assert result == expected @@ -749,7 +753,7 @@ def test_asfreq_mult(self): assert result.ordinal == expected.ordinal assert result.freq == expected.freq for freq in ["2M", offsets.MonthEnd(2)]: - result = p.asfreq(freq, how="S") + result = p.asfreq(freq, how="s") expected = Period("2007-01", freq="2M") assert result == expected @@ -765,7 +769,7 @@ def test_asfreq_mult(self): assert result.ordinal == expected.ordinal assert result.freq == expected.freq for freq in ["2M", offsets.MonthEnd(2)]: - result = p.asfreq(freq, how="S") + result = p.asfreq(freq, how="s") expected = Period("2007-01", freq="2M") assert result == expected diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index b1fb657bb2051..a152da15fe71f 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -102,17 +102,17 @@ def test_construction(self): assert i1 == i3 i1 = Period("2007-01-01 09:00:00.001") - expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq="L") + expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq="ms") assert i1 == expected - expected = Period("2007-01-01 09:00:00.001", freq="L") + expected = Period("2007-01-01 09:00:00.001", freq="ms") assert i1 == expected i1 = Period("2007-01-01 09:00:00.00101") - expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq="U") + expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq="us") assert i1 == expected - expected = Period("2007-01-01 09:00:00.00101", freq="U") + expected = Period("2007-01-01 09:00:00.00101", freq="us") assert i1 == expected msg = "Must supply freq for ordinal value" @@ -282,17 +282,17 @@ def test_period_constructor_offsets(self): assert i1 == i5 i1 = Period("2007-01-01 09:00:00.001") - expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq="L") + expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1000), freq="ms") assert i1 == expected - expected = Period("2007-01-01 09:00:00.001", freq="L") + expected = Period("2007-01-01 09:00:00.001", freq="ms") assert i1 == expected i1 = Period("2007-01-01 09:00:00.00101") - expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq="U") + expected = Period(datetime(2007, 1, 1, 9, 0, 0, 1010), freq="us") assert i1 == expected - expected = Period("2007-01-01 09:00:00.00101", freq="U") + expected = Period("2007-01-01 09:00:00.00101", freq="us") assert i1 == expected def test_invalid_arguments(self): @@ -346,21 +346,21 @@ def test_constructor_infer_freq(self): assert p.freq == "H" p = Period("2007-01-01 07:10") - assert p.freq == "T" + assert p.freq == "min" p = Period("2007-01-01 07:10:15") - assert p.freq == "S" + assert p.freq == "s" p = Period("2007-01-01 07:10:15.123") - assert p.freq == "L" + assert p.freq == "ms" # We see that there are 6 digits after the decimal, so get microsecond # even though they are all zeros. p = Period("2007-01-01 07:10:15.123000") - assert p.freq == "U" + assert p.freq == "us" p = Period("2007-01-01 07:10:15.123400") - assert p.freq == "U" + assert p.freq == "us" def test_multiples(self): result1 = Period("1989", freq="2A") @@ -638,7 +638,7 @@ def test_to_timestamp(self): assert end_ts == p.to_timestamp("D", how=a) assert end_ts == p.to_timestamp("3D", how=a) - from_lst = ["A", "Q", "M", "W", "B", "D", "H", "Min", "S"] + from_lst = ["A", "Q", "M", "W", "B", "D", "H", "Min", "s"] def _ex(p): if p.freq == "B": @@ -664,10 +664,10 @@ def _ex(p): result = p.to_timestamp("3H", how="end") assert result == expected - result = p.to_timestamp("T", how="end") + result = p.to_timestamp("min", how="end") expected = Timestamp(1986, 1, 1) - Timedelta(1, "ns") assert result == expected - result = p.to_timestamp("2T", how="end") + result = p.to_timestamp("2min", how="end") assert result == expected result = p.to_timestamp(how="end") @@ -677,13 +677,13 @@ def _ex(p): expected = datetime(1985, 1, 1) result = p.to_timestamp("H", how="start") assert result == expected - result = p.to_timestamp("T", how="start") + result = p.to_timestamp("min", how="start") assert result == expected - result = p.to_timestamp("S", how="start") + result = p.to_timestamp("s", how="start") assert result == expected result = p.to_timestamp("3H", how="start") assert result == expected - result = p.to_timestamp("5S", how="start") + result = p.to_timestamp("5s", how="start") assert result == expected def test_to_timestamp_business_end(self): @@ -724,16 +724,16 @@ def test_to_timestamp_microsecond(self, ts, expected, freq): ("2000-12-15", None, "2000-12-15", "D"), ( "2000-12-15 13:45:26.123456789", - "N", + "ns", "2000-12-15 13:45:26.123456789", - "N", + "ns", ), - ("2000-12-15 13:45:26.123456789", "U", "2000-12-15 13:45:26.123456", "U"), - ("2000-12-15 13:45:26.123456", None, "2000-12-15 13:45:26.123456", "U"), - ("2000-12-15 13:45:26.123456789", "L", "2000-12-15 13:45:26.123", "L"), - ("2000-12-15 13:45:26.123", None, "2000-12-15 13:45:26.123", "L"), - ("2000-12-15 13:45:26", "S", "2000-12-15 13:45:26", "S"), - ("2000-12-15 13:45:26", "T", "2000-12-15 13:45", "T"), + ("2000-12-15 13:45:26.123456789", "us", "2000-12-15 13:45:26.123456", "us"), + ("2000-12-15 13:45:26.123456", None, "2000-12-15 13:45:26.123456", "us"), + ("2000-12-15 13:45:26.123456789", "ms", "2000-12-15 13:45:26.123", "ms"), + ("2000-12-15 13:45:26.123", None, "2000-12-15 13:45:26.123", "ms"), + ("2000-12-15 13:45:26", "s", "2000-12-15 13:45:26", "s"), + ("2000-12-15 13:45:26", "min", "2000-12-15 13:45", "min"), ("2000-12-15 13:45:26", "H", "2000-12-15 13:00", "H"), ("2000-12-15", "Y", "2000", "A-DEC"), ("2000-12-15", "Q", "2000Q4", "Q-DEC"), @@ -757,7 +757,7 @@ def test_repr_nat(self): def test_strftime(self): # GH#3363 - p = Period("2000-1-1 12:34:12", freq="S") + p = Period("2000-1-1 12:34:12", freq="s") res = p.strftime("%Y-%m-%d %H:%M:%S") assert res == "2000-01-01 12:34:12" assert isinstance(res, str) @@ -801,7 +801,7 @@ def test_quarterly_negative_ordinals(self): def test_freq_str(self): i1 = Period("1982", freq="Min") assert i1.freq == offsets.Minute() - assert i1.freqstr == "T" + assert i1.freqstr == "min" @pytest.mark.filterwarnings( "ignore:Period with BDay freq is deprecated:FutureWarning" @@ -812,11 +812,11 @@ def test_period_deprecated_freq(self): "B": ["BUS", "BUSINESS", "BUSINESSLY", "WEEKDAY", "bus"], "D": ["DAY", "DLY", "DAILY", "Day", "Dly", "Daily"], "H": ["HR", "HOUR", "HRLY", "HOURLY", "hr", "Hour", "HRly"], - "T": ["minute", "MINUTE", "MINUTELY", "minutely"], - "S": ["sec", "SEC", "SECOND", "SECONDLY", "second"], - "L": ["MILLISECOND", "MILLISECONDLY", "millisecond"], - "U": ["MICROSECOND", "MICROSECONDLY", "microsecond"], - "N": ["NANOSECOND", "NANOSECONDLY", "nanosecond"], + "min": ["minute", "MINUTE", "MINUTELY", "minutely"], + "s": ["sec", "SEC", "SECOND", "SECONDLY", "second"], + "ms": ["MILLISECOND", "MILLISECONDLY", "millisecond"], + "us": ["MICROSECOND", "MICROSECONDLY", "microsecond"], + "ns": ["NANOSECOND", "NANOSECONDLY", "nanosecond"], } msg = INVALID_FREQ_ERR_MSG @@ -858,13 +858,13 @@ def test_outer_bounds_start_and_end_time(self, bound, offset, period_property): def test_inner_bounds_start_and_end_time(self, bound, offset, period_property): # GH #13346 period = TestPeriodProperties._period_constructor(bound, -offset) - expected = period.to_timestamp().round(freq="S") - assert getattr(period, period_property).round(freq="S") == expected - expected = (bound - offset * Timedelta(1, unit="S")).floor("S") - assert getattr(period, period_property).floor("S") == expected + expected = period.to_timestamp().round(freq="s") + assert getattr(period, period_property).round(freq="s") == expected + expected = (bound - offset * Timedelta(1, unit="s")).floor("s") + assert getattr(period, period_property).floor("s") == expected def test_start_time(self): - freq_lst = ["A", "Q", "M", "D", "H", "T", "S"] + freq_lst = ["A", "Q", "M", "D", "H", "min", "s"] xp = datetime(2012, 1, 1) for f in freq_lst: p = Period("2012", freq=f) @@ -1592,7 +1592,7 @@ def test_small_year_parsing(): def test_negone_ordinals(): - freqs = ["A", "M", "Q", "D", "H", "T", "S"] + freqs = ["A", "M", "Q", "D", "H", "min", "s"] period = Period(ordinal=-1, freq="D") for freq in freqs: diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index 701cfdf157d26..f1d8acf47b29a 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -511,7 +511,6 @@ def test_nat_converters(self): "seconds", "sec", "second", - "S", "Seconds", "Sec", "Second", @@ -576,28 +575,35 @@ def test_unit_parser(self, unit, np_unit, wrapper): dtype="m8[ns]", ) # TODO(2.0): the desired output dtype may have non-nano resolution - result = to_timedelta(wrapper(range(5)), unit=unit) - tm.assert_index_equal(result, expected) - result = TimedeltaIndex(wrapper(range(5)), unit=unit) - tm.assert_index_equal(result, expected) - - str_repr = [f"{x}{unit}" for x in np.arange(5)] - result = to_timedelta(wrapper(str_repr)) - tm.assert_index_equal(result, expected) - result = to_timedelta(wrapper(str_repr)) - tm.assert_index_equal(result, expected) - - # scalar - expected = Timedelta(np.timedelta64(2, np_unit).astype("timedelta64[ns]")) - result = to_timedelta(2, unit=unit) - assert result == expected - result = Timedelta(2, unit=unit) - assert result == expected + msg = f"'{unit}' is deprecated and will be removed in a future version." - result = to_timedelta(f"2{unit}") - assert result == expected - result = Timedelta(f"2{unit}") - assert result == expected + if (unit, np_unit) in (("u", "us"), ("U", "us"), ("n", "ns"), ("N", "ns")): + warn = FutureWarning + else: + warn = None + with tm.assert_produces_warning(warn, match=msg): + result = to_timedelta(wrapper(range(5)), unit=unit) + tm.assert_index_equal(result, expected) + result = TimedeltaIndex(wrapper(range(5)), unit=unit) + tm.assert_index_equal(result, expected) + + str_repr = [f"{x}{unit}" for x in np.arange(5)] + result = to_timedelta(wrapper(str_repr)) + tm.assert_index_equal(result, expected) + result = to_timedelta(wrapper(str_repr)) + tm.assert_index_equal(result, expected) + + # scalar + expected = Timedelta(np.timedelta64(2, np_unit).astype("timedelta64[ns]")) + result = to_timedelta(2, unit=unit) + assert result == expected + result = Timedelta(2, unit=unit) + assert result == expected + + result = to_timedelta(f"2{unit}") + assert result == expected + result = Timedelta(f"2{unit}") + assert result == expected @pytest.mark.parametrize("unit", ["Y", "y", "M"]) def test_unit_m_y_raises(self, unit): @@ -647,25 +653,25 @@ def test_to_numpy_alias(self): [ # This first case has s1, s2 being the same as t1,t2 below ( - "N", + "ns", Timedelta("1 days 02:34:56.789123456"), Timedelta("-1 days 02:34:56.789123456"), ), ( - "U", + "us", Timedelta("1 days 02:34:56.789123000"), Timedelta("-1 days 02:34:56.789123000"), ), ( - "L", + "ms", Timedelta("1 days 02:34:56.789000000"), Timedelta("-1 days 02:34:56.789000000"), ), - ("S", Timedelta("1 days 02:34:57"), Timedelta("-1 days 02:34:57")), - ("2S", Timedelta("1 days 02:34:56"), Timedelta("-1 days 02:34:56")), - ("5S", Timedelta("1 days 02:34:55"), Timedelta("-1 days 02:34:55")), - ("T", Timedelta("1 days 02:35:00"), Timedelta("-1 days 02:35:00")), - ("12T", Timedelta("1 days 02:36:00"), Timedelta("-1 days 02:36:00")), + ("s", Timedelta("1 days 02:34:57"), Timedelta("-1 days 02:34:57")), + ("2s", Timedelta("1 days 02:34:56"), Timedelta("-1 days 02:34:56")), + ("5s", Timedelta("1 days 02:34:55"), Timedelta("-1 days 02:34:55")), + ("min", Timedelta("1 days 02:35:00"), Timedelta("-1 days 02:35:00")), + ("12min", Timedelta("1 days 02:36:00"), Timedelta("-1 days 02:36:00")), ("H", Timedelta("1 days 03:00:00"), Timedelta("-1 days 03:00:00")), ("d", Timedelta("1 days"), Timedelta("-1 days")), ], @@ -976,21 +982,21 @@ def test_implementation_limits(self): def test_total_seconds_precision(self): # GH 19458 - assert Timedelta("30S").total_seconds() == 30.0 + assert Timedelta("30s").total_seconds() == 30.0 assert Timedelta("0").total_seconds() == 0.0 - assert Timedelta("-2S").total_seconds() == -2.0 - assert Timedelta("5.324S").total_seconds() == 5.324 - assert (Timedelta("30S").total_seconds() - 30.0) < 1e-20 - assert (30.0 - Timedelta("30S").total_seconds()) < 1e-20 + assert Timedelta("-2s").total_seconds() == -2.0 + assert Timedelta("5.324s").total_seconds() == 5.324 + assert (Timedelta("30s").total_seconds() - 30.0) < 1e-20 + assert (30.0 - Timedelta("30s").total_seconds()) < 1e-20 def test_resolution_string(self): assert Timedelta(days=1).resolution_string == "D" assert Timedelta(days=1, hours=6).resolution_string == "H" - assert Timedelta(days=1, minutes=6).resolution_string == "T" - assert Timedelta(days=1, seconds=6).resolution_string == "S" - assert Timedelta(days=1, milliseconds=6).resolution_string == "L" - assert Timedelta(days=1, microseconds=6).resolution_string == "U" - assert Timedelta(days=1, nanoseconds=6).resolution_string == "N" + assert Timedelta(days=1, minutes=6).resolution_string == "min" + assert Timedelta(days=1, seconds=6).resolution_string == "s" + assert Timedelta(days=1, milliseconds=6).resolution_string == "ms" + assert Timedelta(days=1, microseconds=6).resolution_string == "us" + assert Timedelta(days=1, nanoseconds=6).resolution_string == "ns" def test_resolution_deprecated(self): # GH#21344 @@ -1007,8 +1013,8 @@ def test_resolution_deprecated(self): @pytest.mark.parametrize( "value, expected", [ - (Timedelta("10S"), True), - (Timedelta("-10S"), True), + (Timedelta("10s"), True), + (Timedelta("-10s"), True), (Timedelta(10, unit="ns"), True), (Timedelta(0, unit="ns"), False), (Timedelta(-10, unit="ns"), True), @@ -1032,3 +1038,23 @@ def test_timedelta_attribute_precision(): result += td.nanoseconds expected = td._value assert result == expected + + +@pytest.mark.parametrize( + "unit,unit_depr", + [ + ("min", "T"), + ("s", "S"), + ("ms", "L"), + ("ns", "N"), + ("us", "U"), + ], +) +def test_units_t_l_u_n_deprecated(unit, unit_depr): + # GH 52536 + msg = f"'{unit_depr}' is deprecated and will be removed in a future version." + + expected = Timedelta(1, unit=unit) + with tm.assert_produces_warning(FutureWarning, match=msg): + result = Timedelta(1, unit=unit_depr) + tm.assert_equal(result, expected) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 0a43db87674af..e501bd93bc1c6 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -46,7 +46,7 @@ def test_round_division_by_zero_raises(self): ("20130104 12:00:00", "D", "20130105"), ("2000-01-05 05:09:15.13", "D", "2000-01-05 00:00:00"), ("2000-01-05 05:09:15.13", "H", "2000-01-05 05:00:00"), - ("2000-01-05 05:09:15.13", "S", "2000-01-05 05:09:15"), + ("2000-01-05 05:09:15.13", "s", "2000-01-05 05:09:15"), ], ) def test_round_frequencies(self, timestamp, freq, expected): @@ -137,10 +137,10 @@ def test_ceil_floor_edge(self, test_input, rounder, freq, expected): "test_input, freq, expected", [ ("2018-01-01 00:02:06", "2s", "2018-01-01 00:02:06"), - ("2018-01-01 00:02:00", "2T", "2018-01-01 00:02:00"), - ("2018-01-01 00:04:00", "4T", "2018-01-01 00:04:00"), - ("2018-01-01 00:15:00", "15T", "2018-01-01 00:15:00"), - ("2018-01-01 00:20:00", "20T", "2018-01-01 00:20:00"), + ("2018-01-01 00:02:00", "2min", "2018-01-01 00:02:00"), + ("2018-01-01 00:04:00", "4min", "2018-01-01 00:04:00"), + ("2018-01-01 00:15:00", "15min", "2018-01-01 00:15:00"), + ("2018-01-01 00:20:00", "20min", "2018-01-01 00:20:00"), ("2018-01-01 03:00:00", "3H", "2018-01-01 03:00:00"), ], ) diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index dd810a31c25af..c7f9e7da4f398 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -253,7 +253,7 @@ def test_dt_accessor_limited_display_api(self): tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods))) # tzaware - ser = Series(date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx") + ser = Series(date_range("2015-01-01", "2016-01-01", freq="min"), name="xxx") ser = ser.dt.tz_localize("UTC").dt.tz_convert("America/Chicago") results = get_dir(ser) tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods))) @@ -270,11 +270,11 @@ def test_dt_accessor_limited_display_api(self): def test_dt_accessor_ambiguous_freq_conversions(self): # GH#11295 # ambiguous time error on the conversions - ser = Series(date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx") + ser = Series(date_range("2015-01-01", "2016-01-01", freq="min"), name="xxx") ser = ser.dt.tz_localize("UTC").dt.tz_convert("America/Chicago") exp_values = date_range( - "2015-01-01", "2016-01-01", freq="T", tz="UTC" + "2015-01-01", "2016-01-01", freq="min", tz="UTC" ).tz_convert("America/Chicago") # freq not preserved by tz_localize above exp_values = exp_values._with_freq(None) @@ -385,7 +385,7 @@ def test_dt_round_tz_nonexistent(self, method, ts_str, freq): with pytest.raises(pytz.NonExistentTimeError, match="2018-03-11 02:00:00"): getattr(ser.dt, method)(freq, nonexistent="raise") - @pytest.mark.parametrize("freq", ["ns", "U", "1000U"]) + @pytest.mark.parametrize("freq", ["ns", "us", "1000us"]) def test_dt_round_nonnano_higher_resolution_no_op(self, freq): # GH 52761 ser = Series( @@ -611,7 +611,7 @@ def test_strftime_period_hours(self): tm.assert_series_equal(result, expected) def test_strftime_period_minutes(self): - ser = Series(period_range("20130101", periods=4, freq="L")) + ser = Series(period_range("20130101", periods=4, freq="ms")) result = ser.dt.strftime("%Y/%m/%d %H:%M:%S.%l") expected = Series( [ @@ -784,8 +784,8 @@ class TestSeriesPeriodValuesDtAccessor: Period("2016-01-01 00:01:00", freq="M"), ], [ - Period("2016-01-01 00:00:00", freq="S"), - Period("2016-01-01 00:00:01", freq="S"), + Period("2016-01-01 00:00:00", freq="s"), + Period("2016-01-01 00:00:01", freq="s"), ], ], ) diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index 8daaf087085c6..a388f0f80fa94 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -355,7 +355,7 @@ def test_indexing_over_size_cutoff_period_index(monkeypatch): monkeypatch.setattr(libindex, "_SIZE_CUTOFF", 1000) n = 1100 - idx = period_range("1/1/2000", freq="T", periods=n) + idx = period_range("1/1/2000", freq="min", periods=n) assert idx._engine.over_size_threshold s = Series(np.random.default_rng(2).standard_normal(len(idx)), index=idx) @@ -455,7 +455,7 @@ def test_getitem_str_month_with_datetimeindex(): expected = ts["2013-05"] tm.assert_series_equal(expected, ts) - idx = date_range(start="2013-05-31 00:00", end="2013-05-31 23:59", freq="S") + idx = date_range(start="2013-05-31 00:00", end="2013-05-31 23:59", freq="s") ts = Series(range(len(idx)), index=idx) expected = ts["2013-05"] tm.assert_series_equal(expected, ts) diff --git a/pandas/tests/tseries/frequencies/test_freq_code.py b/pandas/tests/tseries/frequencies/test_freq_code.py index e961fdc295c96..f25477afa2626 100644 --- a/pandas/tests/tseries/frequencies/test_freq_code.py +++ b/pandas/tests/tseries/frequencies/test_freq_code.py @@ -8,10 +8,12 @@ ) from pandas._libs.tslibs.dtypes import _attrname_to_abbrevs +import pandas._testing as tm + @pytest.mark.parametrize( "freqstr,exp_freqstr", - [("D", "D"), ("W", "D"), ("M", "D"), ("S", "S"), ("T", "S"), ("H", "S")], + [("D", "D"), ("W", "D"), ("M", "D"), ("s", "s"), ("min", "s"), ("H", "s")], ) def test_get_to_timestamp_base(freqstr, exp_freqstr): off = to_offset(freqstr) @@ -30,18 +32,18 @@ def test_get_to_timestamp_base(freqstr, exp_freqstr): ("M", "month"), ("D", "day"), ("H", "hour"), - ("T", "minute"), - ("S", "second"), - ("L", "millisecond"), - ("U", "microsecond"), - ("N", "nanosecond"), + ("min", "minute"), + ("s", "second"), + ("ms", "millisecond"), + ("us", "microsecond"), + ("ns", "nanosecond"), ], ) def test_get_attrname_from_abbrev(freqstr, expected): assert Resolution.get_reso_from_freqstr(freqstr).attrname == expected -@pytest.mark.parametrize("freq", ["D", "H", "T", "S", "L", "U", "N"]) +@pytest.mark.parametrize("freq", ["D", "H", "min", "s", "ms", "us", "ns"]) def test_get_freq_roundtrip2(freq): obj = Resolution.get_reso_from_freqstr(freq) result = _attrname_to_abbrevs[obj.attrname] @@ -51,12 +53,12 @@ def test_get_freq_roundtrip2(freq): @pytest.mark.parametrize( "args,expected", [ - ((1.5, "T"), (90, "S")), - ((62.4, "T"), (3744, "S")), - ((1.04, "H"), (3744, "S")), + ((1.5, "min"), (90, "s")), + ((62.4, "min"), (3744, "s")), + ((1.04, "H"), (3744, "s")), ((1, "D"), (1, "D")), - ((0.342931, "H"), (1234551600, "U")), - ((1.2345, "D"), (106660800, "L")), + ((0.342931, "H"), (1234551600, "us")), + ((1.2345, "D"), (106660800, "ms")), ], ) def test_resolution_bumping(args, expected): @@ -69,7 +71,7 @@ def test_resolution_bumping(args, expected): @pytest.mark.parametrize( "args", [ - (0.5, "N"), + (0.5, "ns"), # Too much precision in the input can prevent. (0.3429324798798269273987982, "H"), ], @@ -95,3 +97,12 @@ def test_compatibility(freqstr, expected): ts_np = np.datetime64("2021-01-01T08:00:00.00") do = to_offset(freqstr) assert ts_np + do == np.datetime64(expected) + + +@pytest.mark.parametrize("freq", ["T", "S", "L", "N", "U"]) +def test_units_t_l_deprecated_from__attrname_to_abbrevs(freq): + # GH 52536 + msg = f"'{freq}' is deprecated and will be removed in a future version." + + with tm.assert_produces_warning(FutureWarning, match=msg): + Resolution.get_reso_from_freqstr(freq) diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index d811b2cf12c19..ab7bda2fa5792 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -39,11 +39,11 @@ params=[ (timedelta(1), "D"), (timedelta(hours=1), "H"), - (timedelta(minutes=1), "T"), - (timedelta(seconds=1), "S"), - (np.timedelta64(1, "ns"), "N"), - (timedelta(microseconds=1), "U"), - (timedelta(microseconds=1000), "L"), + (timedelta(minutes=1), "min"), + (timedelta(seconds=1), "s"), + (np.timedelta64(1, "ns"), "ns"), + (timedelta(microseconds=1), "us"), + (timedelta(microseconds=1000), "ms"), ] ) def base_delta_code_pair(request): @@ -254,7 +254,8 @@ def test_infer_freq_tz_series(tz_naive_fixture): ], ) @pytest.mark.parametrize( - "freq", ["H", "3H", "10T", "3601S", "3600001L", "3600000001U", "3600000000001N"] + "freq", + ["H", "3H", "10min", "3601s", "3600001ms", "3600000001us", "3600000000001ns"], ) def test_infer_freq_tz_transition(tz_naive_fixture, date_pair, freq): # see gh-8772 @@ -437,7 +438,7 @@ def test_series_inconvertible_string(): frequencies.infer_freq(Series(["foo", "bar"])) -@pytest.mark.parametrize("freq", [None, "L"]) +@pytest.mark.parametrize("freq", [None, "ms"]) def test_series_period_index(freq): # see gh-6407 # @@ -449,7 +450,7 @@ def test_series_period_index(freq): frequencies.infer_freq(s) -@pytest.mark.parametrize("freq", ["M", "L", "S"]) +@pytest.mark.parametrize("freq", ["M", "ms", "s"]) def test_series_datetime_index(freq): s = Series(date_range("20130101", periods=10, freq=freq)) inferred = frequencies.infer_freq(s) @@ -530,12 +531,12 @@ def test_infer_freq_non_nano(): arr = np.arange(10).astype(np.int64).view("M8[s]") dta = DatetimeArray._simple_new(arr, dtype=arr.dtype) res = frequencies.infer_freq(dta) - assert res == "S" + assert res == "s" arr2 = arr.view("m8[ms]") tda = TimedeltaArray._simple_new(arr2, dtype=arr2.dtype) res2 = frequencies.infer_freq(tda) - assert res2 == "L" + assert res2 == "ms" def test_infer_freq_non_nano_tzaware(tz_aware_fixture): diff --git a/pandas/tests/tseries/offsets/test_business_month.py b/pandas/tests/tseries/offsets/test_business_month.py index 9f7fb990d238a..a14451e60aa89 100644 --- a/pandas/tests/tseries/offsets/test_business_month.py +++ b/pandas/tests/tseries/offsets/test_business_month.py @@ -31,7 +31,7 @@ ) def test_apply_index(cls, n): offset = cls(n=n) - rng = pd.date_range(start="1/1/2000", periods=100000, freq="T") + rng = pd.date_range(start="1/1/2000", periods=100000, freq="min") ser = pd.Series(rng) res = rng + offset diff --git a/pandas/tests/tseries/offsets/test_index.py b/pandas/tests/tseries/offsets/test_index.py index ad3478b319898..7a62944556d11 100644 --- a/pandas/tests/tseries/offsets/test_index.py +++ b/pandas/tests/tseries/offsets/test_index.py @@ -44,7 +44,7 @@ ) def test_apply_index(cls, n): offset = cls(n=n) - rng = date_range(start="1/1/2000", periods=100000, freq="T") + rng = date_range(start="1/1/2000", periods=100000, freq="min") ser = Series(rng) res = rng + offset diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 5139331bebaf7..29215101a84e0 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -811,7 +811,7 @@ def test_alias_equality(self): assert k == v.copy() def test_rule_code(self): - lst = ["M", "MS", "BM", "BMS", "D", "B", "H", "T", "S", "L", "U"] + lst = ["M", "MS", "BM", "BMS", "D", "B", "H", "min", "s", "ms", "us"] for k in lst: assert k == _get_offset(k).rule_code # should be cached - this is kind of an internals test... diff --git a/pandas/tests/tslibs/test_period_asfreq.py b/pandas/tests/tslibs/test_period_asfreq.py index 7c9047b3e7c60..49cb1af9406fe 100644 --- a/pandas/tests/tslibs/test_period_asfreq.py +++ b/pandas/tests/tslibs/test_period_asfreq.py @@ -25,26 +25,26 @@ def get_freq_code(freqstr: str) -> int: "freq1,freq2,expected", [ ("D", "H", 24), - ("D", "T", 1440), - ("D", "S", 86400), - ("D", "L", 86400000), - ("D", "U", 86400000000), - ("D", "N", 86400000000000), - ("H", "T", 60), - ("H", "S", 3600), - ("H", "L", 3600000), - ("H", "U", 3600000000), - ("H", "N", 3600000000000), - ("T", "S", 60), - ("T", "L", 60000), - ("T", "U", 60000000), - ("T", "N", 60000000000), - ("S", "L", 1000), - ("S", "U", 1000000), - ("S", "N", 1000000000), - ("L", "U", 1000), - ("L", "N", 1000000), - ("U", "N", 1000), + ("D", "min", 1440), + ("D", "s", 86400), + ("D", "ms", 86400000), + ("D", "us", 86400000000), + ("D", "ns", 86400000000000), + ("H", "min", 60), + ("H", "s", 3600), + ("H", "ms", 3600000), + ("H", "us", 3600000000), + ("H", "ns", 3600000000000), + ("min", "s", 60), + ("min", "ms", 60000), + ("min", "us", 60000000), + ("min", "ns", 60000000000), + ("s", "ms", 1000), + ("s", "us", 1000000), + ("s", "ns", 1000000000), + ("ms", "us", 1000), + ("ms", "ns", 1000000), + ("us", "ns", 1000), ], ) def test_intra_day_conversion_factors(freq1, freq2, expected): diff --git a/pandas/tests/tslibs/test_to_offset.py b/pandas/tests/tslibs/test_to_offset.py index 27ddbb82f49a9..bc3e06646b235 100644 --- a/pandas/tests/tslibs/test_to_offset.py +++ b/pandas/tests/tslibs/test_to_offset.py @@ -20,12 +20,12 @@ ("2h 60min", offsets.Hour(3)), ("2h 20.5min", offsets.Second(8430)), ("1.5min", offsets.Second(90)), - ("0.5S", offsets.Milli(500)), - ("15l500u", offsets.Micro(15500)), - ("10s75L", offsets.Milli(10075)), + ("0.5s", offsets.Milli(500)), + ("15ms500us", offsets.Micro(15500)), + ("10s75ms", offsets.Milli(10075)), ("1s0.25ms", offsets.Micro(1000250)), - ("1s0.25L", offsets.Micro(1000250)), - ("2800N", offsets.Nano(2800)), + ("1s0.25ms", offsets.Micro(1000250)), + ("2800ns", offsets.Nano(2800)), ("2SM", offsets.SemiMonthEnd(2)), ("2SM-16", offsets.SemiMonthEnd(2, day_of_month=16)), ("2SMS-14", offsets.SemiMonthBegin(2, day_of_month=14)), @@ -38,7 +38,7 @@ def test_to_offset(freq_input, expected): @pytest.mark.parametrize( - "freqstr,expected", [("-1S", -1), ("-2SM", -2), ("-1SMS", -1), ("-5min10s", -310)] + "freqstr,expected", [("-1s", -1), ("-2SM", -2), ("-1SMS", -1), ("-5min10s", -310)] ) def test_to_offset_negative(freqstr, expected): result = to_offset(freqstr) @@ -49,12 +49,12 @@ def test_to_offset_negative(freqstr, expected): "freqstr", [ "2h20m", - "U1", - "-U", - "3U1", - "-2-3U", + "us1", + "-us", + "3us1", + "-2-3us", "-2D:3H", - "1.5.0S", + "1.5.0s", "2SMS-15-15", "2SMS-15D", "100foo", @@ -119,7 +119,7 @@ def test_to_offset_whitespace(freqstr, expected): @pytest.mark.parametrize( - "freqstr,expected", [("00H 00T 01S", 1), ("-00H 03T 14S", -194)] + "freqstr,expected", [("00H 00min 01s", 1), ("-00H 03min 14s", -194)] ) def test_to_offset_leading_zero(freqstr, expected): result = to_offset(freqstr) diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index 70b7534b296f3..f4d903dc19fb7 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -920,7 +920,7 @@ def test_rolling_numerical_accuracy_kahan_mean(add): result = ( df.resample("1s").ffill().rolling("3s", closed="left", min_periods=3).mean() ) - dates = date_range("19700101 09:00:00", periods=7, freq="S") + dates = date_range("19700101 09:00:00", periods=7, freq="s") expected = DataFrame( { "A": [ @@ -1065,11 +1065,13 @@ def test_rolling_on_df_transposed(): ("index", "window"), [ ( - period_range(start="2020-01-01 08:00", end="2020-01-01 08:08", freq="T"), - "2T", + period_range(start="2020-01-01 08:00", end="2020-01-01 08:08", freq="min"), + "2min", ), ( - period_range(start="2020-01-01 08:00", end="2020-01-01 12:00", freq="30T"), + period_range( + start="2020-01-01 08:00", end="2020-01-01 12:00", freq="30min" + ), "1h", ), ], diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index caa34a067ac69..af88bd7b2a6d6 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -68,11 +68,11 @@ "MS": "M", "D": "D", "B": "B", - "T": "T", - "S": "S", - "L": "L", - "U": "U", - "N": "N", + "min": "min", + "s": "s", + "ms": "ms", + "us": "us", + "ns": "ns", "H": "H", "Q": "Q", "A": "A", @@ -271,19 +271,19 @@ def get_freq(self) -> str | None: return _maybe_add_count("H", delta / pph) elif _is_multiple(delta, ppm): # Minutes - return _maybe_add_count("T", delta / ppm) + return _maybe_add_count("min", delta / ppm) elif _is_multiple(delta, pps): # Seconds - return _maybe_add_count("S", delta / pps) + return _maybe_add_count("s", delta / pps) elif _is_multiple(delta, (pps // 1000)): # Milliseconds - return _maybe_add_count("L", delta / (pps // 1000)) + return _maybe_add_count("ms", delta / (pps // 1000)) elif _is_multiple(delta, (pps // 1_000_000)): # Microseconds - return _maybe_add_count("U", delta / (pps // 1_000_000)) + return _maybe_add_count("us", delta / (pps // 1_000_000)) else: # Nanoseconds - return _maybe_add_count("N", delta) + return _maybe_add_count("ns", delta) @cache_readonly def day_deltas(self) -> list[int]: @@ -472,7 +472,6 @@ def is_subperiod(source, target) -> bool: ------- bool """ - if target is None or source is None: return False source = _maybe_coerce_freq(source) @@ -483,31 +482,31 @@ def is_subperiod(source, target) -> bool: return _quarter_months_conform( get_rule_month(source), get_rule_month(target) ) - return source in {"D", "C", "B", "M", "H", "T", "S", "L", "U", "N"} + return source in {"D", "C", "B", "M", "H", "min", "s", "ms", "us", "ns"} elif _is_quarterly(target): - return source in {"D", "C", "B", "M", "H", "T", "S", "L", "U", "N"} + return source in {"D", "C", "B", "M", "H", "min", "s", "ms", "us", "ns"} elif _is_monthly(target): - return source in {"D", "C", "B", "H", "T", "S", "L", "U", "N"} + return source in {"D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif _is_weekly(target): - return source in {target, "D", "C", "B", "H", "T", "S", "L", "U", "N"} + return source in {target, "D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif target == "B": - return source in {"B", "H", "T", "S", "L", "U", "N"} + return source in {"B", "H", "min", "s", "ms", "us", "ns"} elif target == "C": - return source in {"C", "H", "T", "S", "L", "U", "N"} + return source in {"C", "H", "min", "s", "ms", "us", "ns"} elif target == "D": - return source in {"D", "H", "T", "S", "L", "U", "N"} + return source in {"D", "H", "min", "s", "ms", "us", "ns"} elif target == "H": - return source in {"H", "T", "S", "L", "U", "N"} - elif target == "T": - return source in {"T", "S", "L", "U", "N"} - elif target == "S": - return source in {"S", "L", "U", "N"} - elif target == "L": - return source in {"L", "U", "N"} - elif target == "U": - return source in {"U", "N"} - elif target == "N": - return source in {"N"} + return source in {"H", "min", "s", "ms", "us", "ns"} + elif target == "min": + return source in {"min", "s", "ms", "us", "ns"} + elif target == "s": + return source in {"s", "ms", "us", "ns"} + elif target == "ms": + return source in {"ms", "us", "ns"} + elif target == "us": + return source in {"us", "ns"} + elif target == "ns": + return source in {"ns"} else: return False @@ -541,31 +540,31 @@ def is_superperiod(source, target) -> bool: smonth = get_rule_month(source) tmonth = get_rule_month(target) return _quarter_months_conform(smonth, tmonth) - return target in {"D", "C", "B", "M", "H", "T", "S", "L", "U", "N"} + return target in {"D", "C", "B", "M", "H", "min", "s", "ms", "us", "ns"} elif _is_quarterly(source): - return target in {"D", "C", "B", "M", "H", "T", "S", "L", "U", "N"} + return target in {"D", "C", "B", "M", "H", "min", "s", "ms", "us", "ns"} elif _is_monthly(source): - return target in {"D", "C", "B", "H", "T", "S", "L", "U", "N"} + return target in {"D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif _is_weekly(source): - return target in {source, "D", "C", "B", "H", "T", "S", "L", "U", "N"} + return target in {source, "D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif source == "B": - return target in {"D", "C", "B", "H", "T", "S", "L", "U", "N"} + return target in {"D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif source == "C": - return target in {"D", "C", "B", "H", "T", "S", "L", "U", "N"} + return target in {"D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif source == "D": - return target in {"D", "C", "B", "H", "T", "S", "L", "U", "N"} + return target in {"D", "C", "B", "H", "min", "s", "ms", "us", "ns"} elif source == "H": - return target in {"H", "T", "S", "L", "U", "N"} - elif source == "T": - return target in {"T", "S", "L", "U", "N"} - elif source == "S": - return target in {"S", "L", "U", "N"} - elif source == "L": - return target in {"L", "U", "N"} - elif source == "U": - return target in {"U", "N"} - elif source == "N": - return target in {"N"} + return target in {"H", "min", "s", "ms", "us", "ns"} + elif source == "min": + return target in {"min", "s", "ms", "us", "ns"} + elif source == "s": + return target in {"s", "ms", "us", "ns"} + elif source == "ms": + return target in {"ms", "us", "ns"} + elif source == "us": + return target in {"us", "ns"} + elif source == "ns": + return target in {"ns"} else: return False @@ -586,7 +585,10 @@ def _maybe_coerce_freq(code) -> str: assert code is not None if isinstance(code, DateOffset): code = code.rule_code - return code.upper() + if code in {"min", "s", "ms", "us", "ns"}: + return code + else: + return code.upper() def _quarter_months_conform(source: str, target: str) -> bool: diff --git a/pandas/util/__init__.py b/pandas/util/__init__.py index 8fe928ed6c5cf..82b3aa56c653c 100644 --- a/pandas/util/__init__.py +++ b/pandas/util/__init__.py @@ -23,3 +23,7 @@ def __getattr__(key: str): return cache_readonly raise AttributeError(f"module 'pandas.util' has no attribute '{key}'") + + +def capitalize_first_letter(s): + return s[:1].upper() + s[1:]