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 unit parameters ’T’, 't', 'L', and 'l' #53557

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 4 additions & 0 deletions pandas/_libs/tslibs/dtypes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,14 @@ cpdef NPY_DATETIMEUNIT abbrev_to_npy_unit(str abbrev):
return NPY_DATETIMEUNIT.NPY_FR_h
elif abbrev == "m":
return NPY_DATETIMEUNIT.NPY_FR_m
elif abbrev == "T" or abbrev == "t":
return NPY_DATETIMEUNIT.NPY_FR_m
elif abbrev == "s":
return NPY_DATETIMEUNIT.NPY_FR_s
elif abbrev == "ms":
return NPY_DATETIMEUNIT.NPY_FR_ms
elif abbrev == "L" or abbrev == "l":
return NPY_DATETIMEUNIT.NPY_FR_ms
elif abbrev == "us":
return NPY_DATETIMEUNIT.NPY_FR_us
elif abbrev == "ns":
Expand Down
2 changes: 2 additions & 0 deletions pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ UnitChoices = Literal[
"min",
"minutes",
"t",
"T",
"s",
"seconds",
"sec",
Expand All @@ -48,6 +49,7 @@ UnitChoices = Literal[
"milli",
"millis",
"l",
"L",
"us",
"microseconds",
"microsecond",
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ cpdef inline str parse_timedelta_unit(str unit):
"""
if unit is None:
return "ns"
elif unit == "M":
elif unit in {"M", "t", "T", "l", "L"}:
return unit
try:
return timedelta_abbrevs[unit.lower()]
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/tools/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def to_timedelta(
* 'W'
* 'D' / 'days' / 'day'
* 'hours' / 'hour' / 'hr' / 'h'
* 'm' / 'minute' / 'min' / 'minutes' / 'T'
* 'm' / 'minute' / 'min' / 'minutes'
* 'S' / 'seconds' / 'sec' / 'second'
* 'ms' / 'milliseconds' / 'millisecond' / 'milli' / 'millis' / 'L'
* 'ms' / 'milliseconds' / 'millisecond' / 'milli' / 'millis'
* 'us' / 'microseconds' / 'microsecond' / 'micro' / 'micros' / 'U'
* 'ns' / 'nanoseconds' / 'nano' / 'nanos' / 'nanosecond' / 'N'

Expand Down Expand Up @@ -181,6 +181,9 @@ def to_timedelta(
"represent unambiguous timedelta values durations."
)

if unit in {"t", "T", "l", "L"}:
raise ValueError("Units 't', 'T', 'l' and 'L' are no longer supported.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this - there should probably be a FutureWarning first, and then in version 3.0 these units can raise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment. I’ll replace raising ValueError with FutureWarning.


if arg is None:
return arg
elif isinstance(arg, ABCSeries):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/timedeltas/test_timedelta_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_timedelta_range(self):
result = timedelta_range("1 days, 00:00:02", periods=5, freq="2D")
tm.assert_index_equal(result, expected)

expected = to_timedelta(np.arange(50), unit="T") * 30
result = timedelta_range("0 days", freq="30T", periods=50)
expected = to_timedelta(np.arange(50), unit="min") * 30
result = timedelta_range("0 days", freq="30min", periods=50)
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize(
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/resample/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ def test_resample_as_freq_with_subperiod():
def test_resample_with_timedeltas():
expected = DataFrame({"A": np.arange(1480)})
expected = expected.groupby(expected.index // 30).sum()
expected.index = timedelta_range("0 days", freq="30T", periods=50)
expected.index = timedelta_range("0 days", freq="30min", periods=50)

df = DataFrame(
{"A": np.arange(1480)}, index=pd.to_timedelta(np.arange(1480), unit="T")
{"A": np.arange(1480)}, index=pd.to_timedelta(np.arange(1480), unit="min")
)
result = df.resample("30T").sum()
result = df.resample("30min").sum()

tm.assert_frame_equal(result, expected)

s = df["A"]
result = s.resample("30T").sum()
result = s.resample("30min").sum()
tm.assert_series_equal(result, expected["A"])


Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/scalar/timedelta/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,9 @@ def test_nat_converters(self):
"minute",
"min",
"minutes",
"t",
"Minute",
"Min",
"Minutes",
"T",
]
]
+ [
Expand All @@ -520,13 +518,11 @@ def test_nat_converters(self):
"millisecond",
"milli",
"millis",
"l",
"MS",
"Milliseconds",
"Millisecond",
"Milli",
"Millis",
"L",
]
]
+ [
Expand Down