-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
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
DEPR: Add Deprecated warning for timedelta with passed units M and Y #23264
Conversation
Hello @ryankarlos! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on February 08, 2019 at 22:56 Hours UTC |
Just made a related PR #23259 for timedelta docstring so thought I would give this a try as well. This is an initial PR to check if Im on the right track - my first time adding deprecated warnings. |
Could you add some tests that validate that the warning is raised? Would need to check Also there might be some existing tests that use those offsets, so could you check the logs and see if any tests are raising the warning as well? |
Sure will work on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- need to have a specific test for this
- where we are testing this now, need to catch the warnings (or can just call that part 1 is ok)
- whatsnew note in the deprecation section
Deprecating |
4963cb1
to
09eb209
Compare
@mroeschke Ive added an update with tests for deprecating units - please have a look. Ive fetched the latest merge #23439 to include the changes from there as well. |
Be sure to also check the CI runs (travis) to see where else 'M' and 'Y' might be used with timedelta. We will need to catch the deprecation behavior of other tests that use this behavior. |
09eb209
to
ad28eff
Compare
Codecov Report
@@ Coverage Diff @@
## master #23264 +/- ##
==========================================
- Coverage 92.15% 92.15% -0.01%
==========================================
Files 166 166
Lines 52294 52299 +5
==========================================
+ Hits 48194 48198 +4
- Misses 4100 4101 +1
Continue to review full report at Codecov.
|
@mroeschke sorry for the delay - ive added those fixes in now. I could see around 6 failures in Travis - showing deprecation warnings for |
can you merge master and upate |
@jreback Yes sure, sorry somehow I had missed your replies to my previous commits. |
1f779ef
to
74a48bd
Compare
@mroeschke I think I may need to add a warning for Timedelta as its not producing any FutureWarning making the tests fail - im not sure where this would need to be added though |
Sorry for the delay @ryankarlos. You can add the pandas/pandas/_libs/tslibs/timedeltas.pyx Line 1143 in 7e64d9c
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments, but looking good!
@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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the check_stacklevel=False
here?
Here it should be work, in the one below for to_timedelta
, it is fine to keep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 check_stacklevel
for Timdelta
(setting stacklevel = 2
or stacklevel=3
seems to make no difference). Not sure if it will get through travis if i don't set to check_stacklevel=False
- i remember experimenting with this in the previous builds which failed.:
../../../anaconda/envs/pandas-dev/lib/python3.7/contextlib.py:119: AssertionError
________________________________ TestTimedeltas.test_unit_m_y_deprecated[M] _________________________________
self = <pandas.tests.scalar.timedelta.test_timedelta.TestTimedeltas object at 0x1c169e02b0>, unit = 'M'
@pytest.mark.skipif(sys.version_info < (3, 5),
reason="requires python3.5 or higher")
@pytest.mark.parametrize('unit', ['Y', 'y', 'M'])
def test_unit_m_y_deprecated(self, unit):
with tm.assert_produces_warning(FutureWarning) as w1:
Timedelta(10, unit)
pandas/tests/scalar/timedelta/test_timedelta.py:387:
self = <contextlib._GeneratorContextManager object at 0x1c169e0438>, type = None, value = None
traceback = None
def __exit__(self, type, value, traceback):
if type is None:
try:
next(self.gen)
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
================================== 3 failed, 75 deselected in 0.68 seconds ==================================
@jorisvandenbossche i've pushed latest changes with removing checkstacklevel for timedelta test as requested-- if it fails is it ok to revert ? |
@ryankarlos tested it locally, and apparently it needs to be 1 for Timedelta, and not 2. |
I just tried with 1 for Timedelta locally but still getting the assertion error |
Did you rebuild pandas before testing? The change is in a cython |
thanks, Ok it passes now but I had to merge master and build C extensions on a fresh pandas build - wasn't working when cythonizing on the previous env for some reason. |
@jreback @jorisvandenbossche all green now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update! Two more minor comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comments and some from @jorisvandenbossche ping when updated and on green
@jreback All green now...... I merged master and added the requested changes. |
thanks @ryankarlos nice PR! |
@jreback thanks, will hopefully get a few more in before the 0.25 release ! |
git diff upstream/master -u -- "*.py" | flake8 --diff
pytest pandas/tests/scalar/timedelta/test_timedelta.py -k test_unit_m_y_deprecated
andpytest pandas/tests/indexes/timedeltas/test_timedelta.py -k test_unit_m_y_deprecated
isort