Skip to content

Commit 866dc08

Browse files
natmokvalmroeschke
authored andcommitted
DEPR: deprecate strings T, S, L, U, and N in offsets frequencies, resolution abbreviations, _attrname_to_abbrevs (pandas-dev#54061)
1 parent b90a8fb commit 866dc08

File tree

118 files changed

+1074
-861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+1074
-861
lines changed

asv_bench/benchmarks/arithmetic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class Timeseries:
262262
def setup(self, tz):
263263
N = 10**6
264264
halfway = (N // 2) - 1
265-
self.s = Series(date_range("20010101", periods=N, freq="T", tz=tz))
265+
self.s = Series(date_range("20010101", periods=N, freq="min", tz=tz))
266266
self.ts = self.s[halfway]
267267

268268
self.s2 = Series(date_range("20010101", periods=N, freq="s", tz=tz))
@@ -460,7 +460,7 @@ class OffsetArrayArithmetic:
460460

461461
def setup(self, offset):
462462
N = 10000
463-
rng = date_range(start="1/1/2000", periods=N, freq="T")
463+
rng = date_range(start="1/1/2000", periods=N, freq="min")
464464
self.rng = rng
465465
self.ser = Series(rng)
466466

@@ -479,7 +479,7 @@ class ApplyIndex:
479479

480480
def setup(self, offset):
481481
N = 10000
482-
rng = date_range(start="1/1/2000", periods=N, freq="T")
482+
rng = date_range(start="1/1/2000", periods=N, freq="min")
483483
self.rng = rng
484484

485485
def time_apply_index(self, offset):

asv_bench/benchmarks/eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Query:
4444
def setup(self):
4545
N = 10**6
4646
halfway = (N // 2) - 1
47-
index = pd.date_range("20010101", periods=N, freq="T")
47+
index = pd.date_range("20010101", periods=N, freq="min")
4848
s = pd.Series(index)
4949
self.ts = s.iloc[halfway]
5050
self.df = pd.DataFrame({"a": np.random.randn(N), "dates": index}, index=index)

asv_bench/benchmarks/gil.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def time_kth_smallest(self):
178178
class ParallelDatetimeFields:
179179
def setup(self):
180180
N = 10**6
181-
self.dti = date_range("1900-01-01", periods=N, freq="T")
181+
self.dti = date_range("1900-01-01", periods=N, freq="min")
182182
self.period = self.dti.to_period("D")
183183

184184
def time_datetime_field_year(self):

asv_bench/benchmarks/index_cached_properties.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def setup(self, index_type):
2525
N = 10**5
2626
if index_type == "MultiIndex":
2727
self.idx = pd.MultiIndex.from_product(
28-
[pd.date_range("1/1/2000", freq="T", periods=N // 2), ["a", "b"]]
28+
[pd.date_range("1/1/2000", freq="min", periods=N // 2), ["a", "b"]]
2929
)
3030
elif index_type == "DatetimeIndex":
31-
self.idx = pd.date_range("1/1/2000", freq="T", periods=N)
31+
self.idx = pd.date_range("1/1/2000", freq="min", periods=N)
3232
elif index_type == "Int64Index":
3333
self.idx = pd.Index(range(N), dtype="int64")
3434
elif index_type == "PeriodIndex":
35-
self.idx = pd.period_range("1/1/2000", freq="T", periods=N)
35+
self.idx = pd.period_range("1/1/2000", freq="min", periods=N)
3636
elif index_type == "RangeIndex":
3737
self.idx = pd.RangeIndex(start=0, stop=N)
3838
elif index_type == "IntervalIndex":

asv_bench/benchmarks/index_object.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SetOperations:
2525

2626
def setup(self, index_structure, dtype, method):
2727
N = 10**5
28-
dates_left = date_range("1/1/2000", periods=N, freq="T")
28+
dates_left = date_range("1/1/2000", periods=N, freq="min")
2929
fmt = "%Y-%m-%d %H:%M:%S"
3030
date_str_left = Index(dates_left.strftime(fmt))
3131
int_left = Index(np.arange(N))

asv_bench/benchmarks/io/json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def time_float_longint_str_lines(self):
290290
class ToJSONMem:
291291
def setup_cache(self):
292292
df = DataFrame([[1]])
293-
df2 = DataFrame(range(8), date_range("1/1/2000", periods=8, freq="T"))
293+
df2 = DataFrame(range(8), date_range("1/1/2000", periods=8, freq="min"))
294294
frames = {"int": df, "float": df.astype(float), "datetime": df2}
295295

296296
return frames

asv_bench/benchmarks/join_merge.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class JoinNonUnique:
212212
# outer join of non-unique
213213
# GH 6329
214214
def setup(self):
215-
date_index = date_range("01-Jan-2013", "23-Jan-2013", freq="T")
215+
date_index = date_range("01-Jan-2013", "23-Jan-2013", freq="min")
216216
daily_dates = date_index.to_period("D").to_timestamp("S", "S")
217217
self.fracofday = date_index.values - daily_dates.values
218218
self.fracofday = self.fracofday.astype("timedelta64[ns]")
@@ -338,7 +338,7 @@ class MergeDatetime:
338338
def setup(self, units, tz):
339339
unit_left, unit_right = units
340340
N = 10_000
341-
keys = Series(date_range("2012-01-01", freq="T", periods=N, tz=tz))
341+
keys = Series(date_range("2012-01-01", freq="min", periods=N, tz=tz))
342342
self.left = DataFrame(
343343
{
344344
"key": keys.sample(N * 10, replace=True).dt.as_unit(unit_left),

asv_bench/benchmarks/sparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SparseSeriesToFrame:
2222
def setup(self):
2323
K = 50
2424
N = 50001
25-
rng = date_range("1/1/2000", periods=N, freq="T")
25+
rng = date_range("1/1/2000", periods=N, freq="min")
2626
self.series = {}
2727
for i in range(1, K):
2828
data = np.random.randn(N)[:-i]

asv_bench/benchmarks/timeseries.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def time_infer_freq(self, freq):
116116
class TimeDatetimeConverter:
117117
def setup(self):
118118
N = 100000
119-
self.rng = date_range(start="1/1/2000", periods=N, freq="T")
119+
self.rng = date_range(start="1/1/2000", periods=N, freq="min")
120120

121121
def time_convert(self):
122122
DatetimeConverter.convert(self.rng, None, None)
@@ -129,9 +129,9 @@ class Iteration:
129129
def setup(self, time_index):
130130
N = 10**6
131131
if time_index is timedelta_range:
132-
self.idx = time_index(start=0, freq="T", periods=N)
132+
self.idx = time_index(start=0, freq="min", periods=N)
133133
else:
134-
self.idx = time_index(start="20140101", freq="T", periods=N)
134+
self.idx = time_index(start="20140101", freq="min", periods=N)
135135
self.exit = 10000
136136

137137
def time_iter(self, time_index):
@@ -149,7 +149,7 @@ class ResampleDataFrame:
149149
param_names = ["method"]
150150

151151
def setup(self, method):
152-
rng = date_range(start="20130101", periods=100000, freq="50L")
152+
rng = date_range(start="20130101", periods=100000, freq="50ms")
153153
df = DataFrame(np.random.randn(100000, 2), index=rng)
154154
self.resample = getattr(df.resample("1s"), method)
155155

@@ -163,8 +163,8 @@ class ResampleSeries:
163163

164164
def setup(self, index, freq, method):
165165
indexes = {
166-
"period": period_range(start="1/1/2000", end="1/1/2001", freq="T"),
167-
"datetime": date_range(start="1/1/2000", end="1/1/2001", freq="T"),
166+
"period": period_range(start="1/1/2000", end="1/1/2001", freq="min"),
167+
"datetime": date_range(start="1/1/2000", end="1/1/2001", freq="min"),
168168
}
169169
idx = indexes[index]
170170
ts = Series(np.random.randn(len(idx)), index=idx)
@@ -178,7 +178,7 @@ class ResampleDatetetime64:
178178
# GH 7754
179179
def setup(self):
180180
rng3 = date_range(
181-
start="2000-01-01 00:00:00", end="2000-01-01 10:00:00", freq="555000U"
181+
start="2000-01-01 00:00:00", end="2000-01-01 10:00:00", freq="555000us"
182182
)
183183
self.dt_ts = Series(5, rng3, dtype="datetime64[ns]")
184184

@@ -270,7 +270,7 @@ class DatetimeAccessor:
270270

271271
def setup(self, tz):
272272
N = 100000
273-
self.series = Series(date_range(start="1/1/2000", periods=N, freq="T", tz=tz))
273+
self.series = Series(date_range(start="1/1/2000", periods=N, freq="min", tz=tz))
274274

275275
def time_dt_accessor(self, tz):
276276
self.series.dt

asv_bench/benchmarks/tslibs/timestamp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def time_to_julian_date(self, tz):
136136
self.ts.to_julian_date()
137137

138138
def time_floor(self, tz):
139-
self.ts.floor("5T")
139+
self.ts.floor("5min")
140140

141141
def time_ceil(self, tz):
142-
self.ts.ceil("5T")
142+
self.ts.ceil("5min")
143143

144144

145145
class TimestampAcrossDst:

doc/source/user_guide/10min.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ financial applications. See the :ref:`Time Series section <timeseries>`.
610610

611611
.. ipython:: python
612612
613-
rng = pd.date_range("1/1/2012", periods=100, freq="S")
613+
rng = pd.date_range("1/1/2012", periods=100, freq="s")
614614
ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)
615615
ts.resample("5Min").sum()
616616

doc/source/user_guide/scale.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Suppose our raw dataset on disk has many columns.
4040
return df
4141
4242
timeseries = [
43-
make_timeseries(freq="1T", seed=i).rename(columns=lambda x: f"{x}_{i}")
43+
make_timeseries(freq="1min", seed=i).rename(columns=lambda x: f"{x}_{i}")
4444
for i in range(10)
4545
]
4646
ts_wide = pd.concat(timeseries, axis=1)
@@ -87,7 +87,7 @@ can store larger datasets in memory.
8787
.. ipython:: python
8888
:okwarning:
8989
90-
ts = make_timeseries(freq="30S", seed=0)
90+
ts = make_timeseries(freq="30s", seed=0)
9191
ts.to_parquet("timeseries.parquet")
9292
ts = pd.read_parquet("timeseries.parquet")
9393
ts
@@ -173,7 +173,7 @@ files. Each file in the directory represents a different year of the entire data
173173
pathlib.Path("data/timeseries").mkdir(exist_ok=True)
174174
175175
for i, (start, end) in enumerate(zip(starts, ends)):
176-
ts = make_timeseries(start=start, end=end, freq="1T", seed=i)
176+
ts = make_timeseries(start=start, end=end, freq="1min", seed=i)
177177
ts.to_parquet(f"data/timeseries/ts-{i:0>2d}.parquet")
178178
179179

doc/source/user_guide/timedeltas.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ The ``freq`` parameter can passed a variety of :ref:`frequency aliases <timeseri
390390

391391
.. ipython:: python
392392
393-
pd.timedelta_range(start="1 days", end="2 days", freq="30T")
393+
pd.timedelta_range(start="1 days", end="2 days", freq="30min")
394394
395395
pd.timedelta_range(start="1 days", periods=5, freq="2D5H")
396396

doc/source/user_guide/timeseries.rst

+36-26
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ would include matching times on an included date:
603603
dft = pd.DataFrame(
604604
np.random.randn(100000, 1),
605605
columns=["A"],
606-
index=pd.date_range("20130101", periods=100000, freq="T"),
606+
index=pd.date_range("20130101", periods=100000, freq="min"),
607607
)
608608
dft
609609
dft.loc["2013"]
@@ -905,11 +905,11 @@ into ``freq`` keyword arguments. The available date offsets and associated frequ
905905
:class:`~pandas.tseries.offsets.CustomBusinessHour`, ``'CBH'``, "custom business hour"
906906
:class:`~pandas.tseries.offsets.Day`, ``'D'``, "one absolute day"
907907
:class:`~pandas.tseries.offsets.Hour`, ``'H'``, "one hour"
908-
:class:`~pandas.tseries.offsets.Minute`, ``'T'`` or ``'min'``,"one minute"
909-
:class:`~pandas.tseries.offsets.Second`, ``'S'``, "one second"
910-
:class:`~pandas.tseries.offsets.Milli`, ``'L'`` or ``'ms'``, "one millisecond"
911-
:class:`~pandas.tseries.offsets.Micro`, ``'U'`` or ``'us'``, "one microsecond"
912-
:class:`~pandas.tseries.offsets.Nano`, ``'N'``, "one nanosecond"
908+
:class:`~pandas.tseries.offsets.Minute`, ``'min'``,"one minute"
909+
:class:`~pandas.tseries.offsets.Second`, ``'s'``, "one second"
910+
:class:`~pandas.tseries.offsets.Milli`, ``'ms'``, "one millisecond"
911+
:class:`~pandas.tseries.offsets.Micro`, ``'us'``, "one microsecond"
912+
:class:`~pandas.tseries.offsets.Nano`, ``'ns'``, "one nanosecond"
913913

914914
``DateOffsets`` additionally have :meth:`rollforward` and :meth:`rollback`
915915
methods for moving a date forward or backward respectively to a valid offset
@@ -1264,11 +1264,16 @@ frequencies. We will refer to these aliases as *offset aliases*.
12641264
"BAS, BYS", "business year start frequency"
12651265
"BH", "business hour frequency"
12661266
"H", "hourly frequency"
1267-
"T, min", "minutely frequency"
1268-
"S", "secondly frequency"
1269-
"L, ms", "milliseconds"
1270-
"U, us", "microseconds"
1271-
"N", "nanoseconds"
1267+
"min", "minutely frequency"
1268+
"s", "secondly frequency"
1269+
"ms", "milliseconds"
1270+
"us", "microseconds"
1271+
"ns", "nanoseconds"
1272+
1273+
.. deprecated:: 2.2.0
1274+
1275+
Aliases ``T``, ``S``, ``L``, ``U``, and ``N`` are deprecated in favour of the aliases
1276+
``min``, ``s``, ``ms``, ``us``, and ``ns``.
12721277

12731278
.. note::
12741279

@@ -1318,11 +1323,16 @@ frequencies. We will refer to these aliases as *period aliases*.
13181323
"Q", "quarterly frequency"
13191324
"A, Y", "yearly frequency"
13201325
"H", "hourly frequency"
1321-
"T, min", "minutely frequency"
1322-
"S", "secondly frequency"
1323-
"L, ms", "milliseconds"
1324-
"U, us", "microseconds"
1325-
"N", "nanoseconds"
1326+
"min", "minutely frequency"
1327+
"s", "secondly frequency"
1328+
"ms", "milliseconds"
1329+
"us", "microseconds"
1330+
"ns", "nanoseconds"
1331+
1332+
.. deprecated:: 2.2.0
1333+
1334+
Aliases ``T``, ``S``, ``L``, ``U``, and ``N`` are deprecated in favour of the aliases
1335+
``min``, ``s``, ``ms``, ``us``, and ``ns``.
13261336

13271337

13281338
Combining aliases
@@ -1343,7 +1353,7 @@ You can combine together day and intraday offsets:
13431353
13441354
pd.date_range(start, periods=10, freq="2h20min")
13451355
1346-
pd.date_range(start, periods=10, freq="1D10U")
1356+
pd.date_range(start, periods=10, freq="1D10us")
13471357
13481358
Anchored offsets
13491359
~~~~~~~~~~~~~~~~
@@ -1635,7 +1645,7 @@ Basics
16351645

16361646
.. ipython:: python
16371647
1638-
rng = pd.date_range("1/1/2012", periods=100, freq="S")
1648+
rng = pd.date_range("1/1/2012", periods=100, freq="s")
16391649
16401650
ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)
16411651
@@ -1725,11 +1735,11 @@ For upsampling, you can specify a way to upsample and the ``limit`` parameter to
17251735
17261736
# from secondly to every 250 milliseconds
17271737
1728-
ts[:2].resample("250L").asfreq()
1738+
ts[:2].resample("250ms").asfreq()
17291739
1730-
ts[:2].resample("250L").ffill()
1740+
ts[:2].resample("250ms").ffill()
17311741
1732-
ts[:2].resample("250L").ffill(limit=2)
1742+
ts[:2].resample("250ms").ffill(limit=2)
17331743
17341744
Sparse resampling
17351745
~~~~~~~~~~~~~~~~~
@@ -1752,7 +1762,7 @@ If we want to resample to the full range of the series:
17521762

17531763
.. ipython:: python
17541764
1755-
ts.resample("3T").sum()
1765+
ts.resample("3min").sum()
17561766
17571767
We can instead only resample those groups where we have points as follows:
17581768

@@ -1766,7 +1776,7 @@ We can instead only resample those groups where we have points as follows:
17661776
freq = to_offset(freq)
17671777
return pd.Timestamp((t.value // freq.delta.value) * freq.delta.value)
17681778
1769-
ts.groupby(partial(round, freq="3T")).sum()
1779+
ts.groupby(partial(round, freq="3min")).sum()
17701780
17711781
.. _timeseries.aggregate:
17721782

@@ -1783,10 +1793,10 @@ Resampling a ``DataFrame``, the default will be to act on all columns with the s
17831793
17841794
df = pd.DataFrame(
17851795
np.random.randn(1000, 3),
1786-
index=pd.date_range("1/1/2012", freq="S", periods=1000),
1796+
index=pd.date_range("1/1/2012", freq="s", periods=1000),
17871797
columns=["A", "B", "C"],
17881798
)
1789-
r = df.resample("3T")
1799+
r = df.resample("3min")
17901800
r.mean()
17911801
17921802
We can select a specific column or columns using standard getitem.
@@ -2155,7 +2165,7 @@ Passing a string representing a lower frequency than ``PeriodIndex`` returns par
21552165
dfp = pd.DataFrame(
21562166
np.random.randn(600, 1),
21572167
columns=["A"],
2158-
index=pd.period_range("2013-01-01 9:00", periods=600, freq="T"),
2168+
index=pd.period_range("2013-01-01 9:00", periods=600, freq="min"),
21592169
)
21602170
dfp
21612171
dfp.loc["2013-01-01 10H"]

doc/source/whatsnew/v0.13.0.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,16 @@ Enhancements
669669
Period conversions in the range of seconds and below were reworked and extended
670670
up to nanoseconds. Periods in the nanosecond range are now available.
671671

672-
.. ipython:: python
672+
.. code-block:: python
673673
674-
pd.date_range('2013-01-01', periods=5, freq='5N')
674+
In [79]: pd.date_range('2013-01-01', periods=5, freq='5N')
675+
Out[79]:
676+
DatetimeIndex([ '2013-01-01 00:00:00',
677+
'2013-01-01 00:00:00.000000005',
678+
'2013-01-01 00:00:00.000000010',
679+
'2013-01-01 00:00:00.000000015',
680+
'2013-01-01 00:00:00.000000020'],
681+
dtype='datetime64[ns]', freq='5N')
675682
676683
or with frequency as offset
677684

0 commit comments

Comments
 (0)