Skip to content

Commit 0bc1a89

Browse files
Move warning location and update tests
1 parent a5ef0c3 commit 0bc1a89

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,6 @@ cdef inline int64_t parse_timedelta_string(str ts) except? -1:
299299
if len(ts) == 0 or ts in nat_strings:
300300
return NPY_NAT
301301

302-
if re.search(r"^\d+\s?[M|Y|m|y]$", ts):
303-
warnings.warn(
304-
"Units 'M', 'Y', 'm' and 'y' do not represent unambiguous "
305-
"timedelta values and will be removed in a future version",
306-
FutureWarning,
307-
stacklevel=2,
308-
)
309-
310302
for c in ts:
311303

312304
# skip whitespace / commas
@@ -476,6 +468,15 @@ cdef inline timedelta_from_spec(object number, object frac, object unit):
476468

477469
try:
478470
unit = ''.join(unit)
471+
472+
if unit in ["M", "Y", "m", "y"]:
473+
warnings.warn(
474+
"Units 'M', 'Y', 'm' and 'y' do not represent unambiguous "
475+
"timedelta values and will be removed in a future version",
476+
FutureWarning,
477+
stacklevel=2,
478+
)
479+
479480
if unit == 'M':
480481
# To parse ISO 8601 string, 'M' should be treated as minute,
481482
# not month

pandas/tests/resample/test_datetime_index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,7 @@ def test_resample_origin():
752752
resampled = ts.resample("5min", origin=offset_timestamp).mean()
753753
tm.assert_index_equal(resampled.index, exp_rng)
754754

755-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
756-
resampled = ts.resample("5min", origin="epoch", offset="2m").mean()
755+
resampled = ts.resample("5min", origin="epoch", offset="2min").mean()
757756
tm.assert_index_equal(resampled.index, exp_rng)
758757

759758
# origin of '1999-31-12 12:02:00' should be equivalent for this case

pandas/tests/scalar/timedelta/test_constructors.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
from pandas import Timedelta, offsets, to_timedelta
7-
import pandas._testing as tm
87

98

109
def test_construction():
@@ -41,9 +40,8 @@ def test_construction():
4140
assert Timedelta("1 hr") == timedelta(hours=1)
4241
assert Timedelta("1 hours") == timedelta(hours=1)
4342
assert Timedelta("-1 hours") == -timedelta(hours=1)
44-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
45-
assert Timedelta("1 m") == timedelta(minutes=1)
46-
assert Timedelta("1.5 m") == timedelta(seconds=90)
43+
assert Timedelta("1 min") == timedelta(minutes=1)
44+
assert Timedelta("1.5 min") == timedelta(seconds=90)
4745
assert Timedelta("1 minute") == timedelta(minutes=1)
4846
assert Timedelta("1 minutes") == timedelta(minutes=1)
4947
assert Timedelta("1 s") == timedelta(seconds=1)

0 commit comments

Comments
 (0)