-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR: Add Deprecated warning for timedelta with passed units M and Y #23264
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
Changes from 18 commits
5eaa8d0
0a836d2
e890fa6
bfe74e5
e5e1198
d0dd551
af5d761
938c6fe
16f8b9c
5a64320
3b67476
ab52460
9cb51c5
c6f82c7
b1599a5
a21a6a2
261672e
4010bdb
3f87a0b
b7aedc1
f44bae0
5d2dceb
b745b8c
d014f56
ca0ea09
76497d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
""" test the scalar Timedelta """ | ||
from datetime import timedelta | ||
import re | ||
import sys | ||
|
||
import numpy as np | ||
import pytest | ||
|
@@ -317,6 +319,7 @@ def test_nat_converters(self): | |
assert result.dtype.kind == 'm' | ||
assert result.astype('int64') == iNaT | ||
|
||
@pytest.mark.filterwarnings("ignore:M and Y units are deprecated") | ||
@pytest.mark.parametrize('units, np_unit', | ||
[(['Y', 'y'], 'Y'), | ||
(['M'], 'M'), | ||
|
@@ -376,6 +379,21 @@ def test_unit_parser(self, units, np_unit, wrapper): | |
result = Timedelta('2{}'.format(unit)) | ||
assert result == expected | ||
|
||
@pytest.mark.skipif(sys.version_info < (3, 6), | ||
reason="requires python3.6 or higher") | ||
ryankarlos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@pytest.mark.parametrize('unit', ['Y', 'y', 'M']) | ||
def test_unit_m_y_deprecated(self, unit): | ||
with tm.assert_produces_warning(FutureWarning, | ||
check_stacklevel=False) as w1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorisvandenbossche I just tried running this locally and i get an assertion error if I remove ../../../anaconda/envs/pandas-dev/lib/python3.7/contextlib.py:119: AssertionError self = <pandas.tests.scalar.timedelta.test_timedelta.TestTimedeltas object at 0x1c169e02b0>, unit = 'M'
pandas/tests/scalar/timedelta/test_timedelta.py:387: self = <contextlib._GeneratorContextManager object at 0x1c169e0438>, type = None, value = None
E AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/ryannazareth/anaconda/envs/pandas-dev/lib/python3.7/site-packages/_pytest/python.py != /Users/ryannazareth/Documents/Python_sprints/pandas-ryankarlos/pandas/tests/scalar/timedelta/test_timedelta.py. Warning message: M and Y units are deprecated and will be removed in a future version. ../../../anaconda/envs/pandas-dev/lib/python3.7/contextlib.py:119: AssertionError |
||
Timedelta(10, unit) | ||
msg = r'.* units are deprecated .*' | ||
assert re.match(msg, str(w1[0].message)) | ||
with tm.assert_produces_warning(FutureWarning, | ||
check_stacklevel=False) as w2: | ||
to_timedelta(10, unit) | ||
ryankarlos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
msg = r'.* units are deprecated .*' | ||
assert re.match(msg, str(w2[0].message)) | ||
|
||
def test_numeric_conversions(self): | ||
assert Timedelta(0) == np.timedelta64(0, 'ns') | ||
assert Timedelta(10) == np.timedelta64(10, 'ns') | ||
|
Uh oh!
There was an error while loading. Please reload this page.