Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: deprecate strings T, S, L, U, and N in offsets frequencies, resolution abbreviations, _attrname_to_abbrevs #54061

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6e3e96e
DEPR: deprecate codes T and L in to_abbrevs/_abbrev_to_attrnames
natmokval Jul 10, 2023
fe88663
replace T/L with min/ms in _prefix, period_code_map, _attrname_to_abb…
natmokval Jul 12, 2023
1e79480
correct def get_freq for tseries, fix tests
natmokval Jul 14, 2023
f7fd2a1
replace T, L in _offset_to_period_map, is_subperiod, is_superperiod, …
natmokval Jul 14, 2023
98e8a39
correct def to_timedelta, def _round_temporally and fix tests
natmokval Jul 17, 2023
93bbd08
correct def resolution_string, get_reso_from_freqstr and fix tests
natmokval Jul 21, 2023
b0dfd2f
Merge branch 'main' into DEPR-codes-T-L-from-_attrname_to_abbrevs-_ab…
natmokval Jul 21, 2023
51c62a1
fix tests
natmokval Jul 21, 2023
898f811
correct def _maybe_coerce_freq , is_subperiod, is_superperiod, and _o…
natmokval Jul 23, 2023
1d30c07
fix a test for plotting
natmokval Jul 25, 2023
37de346
Merge branch 'main' into DEPR-codes-T-L-from-_attrname_to_abbrevs-_ab…
natmokval Jul 25, 2023
7171237
fix tests
natmokval Jul 25, 2023
29dcd8d
fix failures in asv benchmarks
natmokval Jul 25, 2023
317718a
correct docstrings
natmokval Jul 27, 2023
99a0cf9
deprecate abbrevs U, N add dict depr_abbrevs and fix tests
natmokval Jul 28, 2023
a13a041
correct get_freq and fix tests
natmokval Jul 31, 2023
a949282
Merge branch 'main' into DEPR-codes-T-L-from-_attrname_to_abbrevs-_ab…
natmokval Jul 31, 2023
7bd6188
correct is_superperiod, is_subperiod, _maybe_coerce_freq and fix tests
natmokval Jul 31, 2023
77949c4
correct __eq__ for PeriodDtype
natmokval Aug 1, 2023
a24c0ec
update docstrings
natmokval Aug 1, 2023
733d68b
correct whatsnew and user_guide
natmokval Aug 1, 2023
beeac14
correct tables of Offset/Period aliases in user_guide
natmokval Aug 1, 2023
a3e3522
correct warning message, add the warning to some tests
natmokval Aug 1, 2023
65ddf90
resolve conflicts in tests
natmokval Aug 1, 2023
c61b0fb
add the futurewarning to def asfreq, fix tests
natmokval Aug 1, 2023
c2f45ba
add the futurewarning to to_offset, correct warning message and add t…
natmokval Aug 2, 2023
73405bf
add the warning to parse_timedelta_unit, remove t, l, u, n from timed…
natmokval Aug 2, 2023
b2ab238
correct docstrings, update user_guide for timeseries and add tests
natmokval Aug 2, 2023
4775471
update whatsnew/v2.1.0.rst
natmokval Aug 2, 2023
c3ed691
remove warning from to_timedelta, correct tests
natmokval Aug 3, 2023
155b0a7
Merge branch 'main' into DEPR-codes-T-L-from-_attrname_to_abbrevs-_ab…
natmokval Aug 7, 2023
31d292c
deprecate 'S' in favour of 's', fix tests
natmokval Aug 9, 2023
d5dabd0
fix tests
natmokval Aug 9, 2023
9cf0565
correct parse_iso_format_string, fix tests
natmokval Aug 13, 2023
609646e
correct docs
natmokval Aug 17, 2023
cc04261
correct docs
natmokval Aug 17, 2023
93533d9
correct docstrings in PeriodProperties
natmokval Aug 17, 2023
9ba1734
Merge branch 'main' into DEPR-codes-T-L-from-_attrname_to_abbrevs-_ab…
natmokval Aug 17, 2023
b79e9b6
correct docs, tests, and add lines to whatsnew/v2.2.0.rst
natmokval Aug 17, 2023
3408d0b
resolve conflict
natmokval Aug 17, 2023
12888f8
correct examples in docs
natmokval Aug 17, 2023
cdd5f6b
resolve conflict
natmokval Aug 18, 2023
c7b8b24
resolve conflict
natmokval Aug 21, 2023
5bb2ca8
correct v2.2.0.rst and test_subset
natmokval Aug 22, 2023
c54e431
resolve conflict in v2.2.0.rst
natmokval Aug 22, 2023
0966d2f
resolve conflict
natmokval Aug 22, 2023
271bd6b
resolve conflict v2.2.0.rst
natmokval Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/gil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions asv_bench/benchmarks/index_cached_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/index_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/join_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions asv_bench/benchmarks/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/tslibs/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/dtypes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cpdef int64_t periods_per_second(NPY_DATETIMEUNIT reso) except? -1
cpdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso)
cpdef bint is_supported_unit(NPY_DATETIMEUNIT reso)

cdef dict c_DEPR_ABBREVS
cdef dict attrname_to_abbrevs
cdef dict npy_unit_to_attrname
cdef dict attrname_to_npy_unit
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from enum import Enum
# are imported in tests.
_attrname_to_abbrevs: dict[str, str]
_period_code_map: dict[str, int]
DEPR_ABBREVS: dict[str, str]
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved

def periods_per_day(reso: int) -> int: ...
def periods_per_second(reso: int) -> int: ...
Expand Down
48 changes: 40 additions & 8 deletions pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -141,11 +144,11 @@ _period_code_map = {
"B": PeriodDtypeCode.B, # Business days
"D": PeriodDtypeCode.D, # Daily
"H": PeriodDtypeCode.H, # Hourly
"T": PeriodDtypeCode.T, # Minutely
"min": PeriodDtypeCode.T, # Minutely
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved
"S": PeriodDtypeCode.S, # Secondly
"L": PeriodDtypeCode.L, # Millisecondly
"U": PeriodDtypeCode.U, # Microsecondly
"N": PeriodDtypeCode.N, # Nanosecondly
"ms": PeriodDtypeCode.L, # Millisecondly
"us": PeriodDtypeCode.U, # Microsecondly
"ns": PeriodDtypeCode.N, # Nanosecondly
}

_reverse_period_code_map = {
Expand Down Expand Up @@ -174,15 +177,28 @@ _attrname_to_abbrevs = {
"month": "M",
"day": "D",
"hour": "H",
"minute": "T",
"minute": "min",
"second": "S",
"millisecond": "L",
"microsecond": "U",
"nanosecond": "N",
"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",
"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
Expand Down Expand Up @@ -273,6 +289,14 @@ class Resolution(Enum):
True
"""
try:
if freq in DEPR_ABBREVS:
warnings.warn(
f"Code freq={freq} is deprecated "
"and will be removed in a future version.",
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved
FutureWarning,
stacklevel=find_stack_level(),
)
freq = freq.replace("T", "min").replace("L", "ms")
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved
attr_name = _abbrev_to_attrnames[freq]
except KeyError:
# For quarterly and yearly resolutions, we need to chop off
Expand All @@ -283,6 +307,14 @@ 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 {"T", "L"}:
warnings.warn(
f"Code freq={split_freq[0]} is deprecated "
"and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
split_freq[0] = split_freq[0].replace("T", "min").replace("L", "ms")
MarcoGorelli marked this conversation as resolved.
Show resolved Hide resolved
attr_name = _abbrev_to_attrnames[split_freq[0]]

return cls.from_attrname(attr_name)
Expand Down
32 changes: 16 additions & 16 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -996,23 +996,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
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``:
Expand Down Expand Up @@ -1085,7 +1085,7 @@ 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
Expand All @@ -1094,14 +1094,14 @@ timedelta}, default 'raise'
>>> ts.floor(freq='N') # 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``:
Expand Down Expand Up @@ -1174,7 +1174,7 @@ 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
Expand All @@ -1183,14 +1183,14 @@ timedelta}, default 'raise'
>>> ts.ceil(freq='U') # 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``:
Expand Down
Loading