Skip to content

Conversation

ryankarlos
Copy link
Contributor

@ryankarlos ryankarlos commented Oct 21, 2018

  • closes DEPR: Timedelta with passed unit M, Y #16344
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • tests passed locally - pytest pandas/tests/scalar/timedelta/test_timedelta.py -k test_unit_m_y_deprecated and pytest pandas/tests/indexes/timedeltas/test_timedelta.py -k test_unit_m_y_deprecated
  • checked import format to pass linter - isort

@pep8speaks
Copy link

pep8speaks commented Oct 21, 2018

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

@ryankarlos
Copy link
Contributor Author

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.

@mroeschke
Copy link
Member

Could you add some tests that validate that the warning is raised? Would need to check Timedelta, TimedeltaIndex, and to_timedelta.

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?

@mroeschke mroeschke added Timedelta Timedelta data type Deprecate Functionality to remove in pandas labels Oct 21, 2018
@ryankarlos
Copy link
Contributor Author

Sure will work on it.

Copy link
Contributor

@jreback jreback left a 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

@sinhrks sinhrks mentioned this pull request Nov 1, 2018
4 tasks
@sinhrks
Copy link
Member

sinhrks commented Nov 1, 2018

Deprecating Timedelta may be easier after #23439

@ryankarlos ryankarlos force-pushed the timedelta_unit_depracated branch from 4963cb1 to 09eb209 Compare November 12, 2018 21:09
@ryankarlos
Copy link
Contributor Author

@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.

@mroeschke
Copy link
Member

mroeschke commented Nov 13, 2018

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.

@ryankarlos ryankarlos force-pushed the timedelta_unit_depracated branch from 09eb209 to ad28eff Compare November 23, 2018 00:46
@codecov
Copy link

codecov bot commented Nov 23, 2018

Codecov Report

Merging #23264 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 90.62% <100%> (ø) ⬆️
#single 42.27% <60%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/tools/timedeltas.py 98.11% <100%> (+0.11%) ⬆️
pandas/core/indexes/timedeltas.py 90.27% <100%> (+0.05%) ⬆️
pandas/util/testing.py 87.89% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d1b14c...76497d3. Read the comment docs.

@ryankarlos
Copy link
Contributor Author

@mroeschke sorry for the delay - ive added those fixes in now. I could see around 6 failures in Travis - showing deprecation warnings for test_unit_parser using M and Y.

@jreback
Copy link
Contributor

jreback commented Dec 14, 2018

can you merge master and upate

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Dec 16, 2018

@jreback Yes sure, sorry somehow I had missed your replies to my previous commits.

@ryankarlos ryankarlos force-pushed the timedelta_unit_depracated branch 2 times, most recently from 1f779ef to 74a48bd Compare December 16, 2018 17:58
@ryankarlos
Copy link
Contributor Author

ryankarlos commented Dec 16, 2018

@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

@mroeschke
Copy link
Member

Sorry for the delay @ryankarlos.

You can add the FutureWarning here for the Timedelta scalar:

def __new__(cls, object value=_no_input, unit=None, **kwargs):

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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:
Copy link
Member

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.

Copy link
Contributor Author

@ryankarlos ryankarlos Feb 3, 2019

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 ==================================

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Feb 3, 2019

@jorisvandenbossche i've pushed latest changes with removing checkstacklevel for timedelta test as requested-- if it fails is it ok to revert ?

@jorisvandenbossche
Copy link
Member

@ryankarlos tested it locally, and apparently it needs to be 1 for Timedelta, and not 2.

@ryankarlos
Copy link
Contributor Author

I just tried with 1 for Timedelta locally but still getting the assertion error

@jorisvandenbossche
Copy link
Member

Did you rebuild pandas before testing? The change is in a cython .pyx file, so you need to rebuild the C extensions before the change will be in effect.

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Feb 4, 2019

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.

@ryankarlos
Copy link
Contributor Author

@jreback @jorisvandenbossche all green now

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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

Copy link
Contributor

@jreback jreback left a 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

@ryankarlos
Copy link
Contributor Author

@jreback All green now...... I merged master and added the requested changes.

@jreback jreback merged commit 04df22f into pandas-dev:master Feb 8, 2019
@jreback
Copy link
Contributor

jreback commented Feb 8, 2019

thanks @ryankarlos nice PR!

@ryankarlos
Copy link
Contributor Author

@jreback thanks, will hopefully get a few more in before the 0.25 release !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DEPR: Timedelta with passed unit M, Y
8 participants