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

API: Implement set_freq for DTI/TDI, deprecate freq setter #20892

Closed
wants to merge 3 commits into from

Conversation

jschendel
Copy link
Member

@jschendel jschendel commented May 1, 2018

Summary:

  • Follow-up to BUG: Fix freq setter for DatetimeIndex/TimedeltaIndex and deprecate for PeriodIndex #20772
    • See that PR for relevant discussion
  • Implements a set_freq method for DatetimeIndex and TimedeltaIndex
  • Deprecates the freq setter for DatetimeIndex and TimedeltaIndex
    • Had to change some instances of the DTI/TDI implementation to directly set the _freq attribute
    • Had to modify some tests to use set_freq instead of the setter
    • Didn't see any related deprecation warnings in the logs from the CI runs hooked to my local repo

cc @jreback @jorisvandenbossche

@@ -399,7 +400,6 @@ def test_daterange_bug_456(self):
# GH #456
rng1 = bdate_range('12/5/2011', '12/5/2011')
rng2 = bdate_range('12/2/2011', '12/5/2011')
rng2.freq = BDay()
Copy link
Member Author

Choose a reason for hiding this comment

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

This is redundant, as bdate_range should already set this as the frequency. I couldn't find a test that verified this though, so I added a check to a test a few lines above. Same deal with the CDay() changes below.

@codecov
Copy link

codecov bot commented May 1, 2018

Codecov Report

Merging #20892 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20892      +/-   ##
==========================================
+ Coverage   91.81%   91.81%   +<.01%     
==========================================
  Files         153      153              
  Lines       49479    49491      +12     
==========================================
+ Hits        45428    45441      +13     
+ Misses       4051     4050       -1
Flag Coverage Δ
#multiple 90.21% <100%> (ø) ⬆️
#single 41.83% <20.83%> (-0.02%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/timedeltas.py 91.15% <100%> (ø) ⬆️
pandas/core/indexes/datetimelike.py 96.85% <100%> (+0.05%) ⬆️
pandas/core/indexes/datetimes.py 95.77% <100%> (+0.01%) ⬆️
pandas/core/resample.py 96.07% <100%> (ø) ⬆️
pandas/core/base.py 97.05% <0%> (+0.22%) ⬆️

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 28dbae9...5778e28. Read the comment docs.

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.

can u add to api.rst

warnings.warn(msg, FutureWarning, stacklevel=2)
self.freq = value
if value is not None:
value = to_offset(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

call set_freq here

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for the deprecated offset setter which is just an alias for the freq setter, so I don't think set_freq should be used here since setting is to happen inplace (as was the previous convention). This previously would call the freq setter, but since that's also being deprecated it was subsequently raising the freq setter warning too, so I just reused the freq setter code to avoid the additional warning.

@jschendel
Copy link
Member Author

Added set_freq to api.rst

@jreback jreback added API Design Frequency DateOffsets Deprecate Functionality to remove in pandas labels May 1, 2018
@jreback jreback added this to the 0.23.0 milestone May 1, 2018
@jreback jreback added the Datetime Datetime data dtype label May 1, 2018
if value is not None:
value = frequencies.to_offset(value)
self._validate_frequency(self, value)

self._freq = value

def set_freq(self, freq):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make this available on the .dt accessors as well

Copy link
Member Author

Choose a reason for hiding this comment

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

This currently does nothing when used with the dt accessor due to #20937; the underlying frequency gets changed with set_freq, but upon Series construction the new frequency gets lost.

I've pushed a commit to add this to the dt accessor, and xfailed the corresponding tests I've added. Can revert the commit if this is no longer deemed important.

@jreback jreback added this to the 0.23.0 milestone May 4, 2018
@jreback
Copy link
Contributor

jreback commented May 4, 2018

nice PR @jschendel , lgtm.

any comments @jorisvandenbossche @TomAugspurger

@jreback
Copy link
Contributor

jreback commented May 8, 2018

@jorisvandenbossche you commented on the issue. but this PR looks pretty good to me, and it allows chained operations, something we like, not to mention .dt friendliness.

@TomAugspurger
Copy link
Contributor

This has a merge conflict in the release notes now.

I'm 50/50 on the changes here, will wait for @jorisvandenbossche to review.

@jorisvandenbossche
Copy link
Member

As I commented on the issue, I still don't see the need or added value to add a new method for this (and yes, this is a nicely done PR, that's not my problem :-)). See #20886 (comment)

BTW, I don't feel strongly about this (as it is something I will never use), so I am fine to go with the majority if there is one, I just have the feeling we are adding a new method for something we don't need (and the bar to add new methods should be higher)

@jreback
Copy link
Contributor

jreback commented May 14, 2018

ok, closing this. thanks for the PR @jschendel we can revisit in the future if more interest.

@jreback jreback closed this May 14, 2018
@jschendel jschendel deleted the freq-setter-depr branch September 24, 2018 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Deprecate Functionality to remove in pandas Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: DatetimeIndex.set_freq
4 participants