-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Move to_period, to_perioddelta up to EA subclasses #23113
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e2c6727
Move repeat up to array mixin
jbrockmendel 5c32348
Move tolist up
jbrockmendel ba5c2c1
Move to_perioddelta up
jbrockmendel e1e05a9
Avoid passing object dtype to simple_new
jbrockmendel d3ca5e9
de-duplicate wrapping code
jbrockmendel b4c2496
de-duplicate wrapping code
jbrockmendel 192170b
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel b8c2647
test fixup
jbrockmendel a99b1f1
Fixup unused import
jbrockmendel edea5ef
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel a4ee53d
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel eaf364f
privatize to_perioddelta in Array class
jbrockmendel 0a5bb77
revert move of repeat, tolist
jbrockmendel b38ad9b
remove tests for removed methods
jbrockmendel 28bcd5a
Revert privatization in test
jbrockmendel 033960a
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel 91aaef4
add comment [ci skip]
jbrockmendel 44c8162
Merge branch 'dlike6' of https://github.com/jbrockmendel/pandas into …
jbrockmendel ef5c1e6
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel 3b31903
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel 0ce415b
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel 5d8bc1a
Merge branch 'master' of https://github.com/pandas-dev/pandas into dl…
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ | |
from pandas.tseries.offsets import ( | ||
CDay, prefix_mapping) | ||
|
||
from pandas.core.tools.timedeltas import to_timedelta | ||
from pandas.util._decorators import Appender, cache_readonly, Substitution | ||
import pandas.core.common as com | ||
import pandas.tseries.offsets as offsets | ||
|
@@ -545,13 +544,6 @@ def to_series(self, keep_tz=False, index=None, name=None): | |
|
||
return Series(values, index=index, name=name) | ||
|
||
@Appender(DatetimeArrayMixin.to_period.__doc__) | ||
def to_period(self, freq=None): | ||
from pandas.core.indexes.period import PeriodIndex | ||
|
||
result = DatetimeArrayMixin.to_period(self, freq=freq) | ||
return PeriodIndex(result, name=self.name) | ||
|
||
def snap(self, freq='S'): | ||
""" | ||
Snap time stamps to nearest occurring frequency | ||
|
@@ -623,23 +615,6 @@ def union(self, other): | |
result.freq = to_offset(result.inferred_freq) | ||
return result | ||
|
||
def to_perioddelta(self, freq): | ||
""" | ||
Calculate TimedeltaIndex of difference between index | ||
values and index converted to periodIndex at specified | ||
freq. Used for vectorized offsets | ||
|
||
Parameters | ||
---------- | ||
freq: Period frequency | ||
|
||
Returns | ||
------- | ||
y: TimedeltaIndex | ||
""" | ||
return to_timedelta(self.asi8 - self.to_period(freq) | ||
.to_timestamp().asi8) | ||
|
||
def union_many(self, others): | ||
""" | ||
A bit of a hack to accelerate unioning a collection of indexes | ||
|
@@ -1168,6 +1143,9 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): | |
is_year_end = wrap_field_accessor(DatetimeArrayMixin.is_year_end) | ||
is_leap_year = wrap_field_accessor(DatetimeArrayMixin.is_leap_year) | ||
|
||
to_perioddelta = wrap_array_method(DatetimeArrayMixin.to_perioddelta, | ||
False) | ||
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. Does anyone know why the result's |
||
to_period = wrap_array_method(DatetimeArrayMixin.to_period, True) | ||
normalize = wrap_array_method(DatetimeArrayMixin.normalize, True) | ||
to_julian_date = wrap_array_method(DatetimeArrayMixin.to_julian_date, | ||
False) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I find this a rather "obscure" method (meaning, not directly sure how it would be useful for me as a user). But I am also not a frequent user of periods/offsets, so difficult to say (and maybe a good example in the docstring might already help).
So what I want to say: in case this is indeed rather for internal use, I would not make it a public method on the array class (but can still do the move but make it for example private here)
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.
This is used indirectly in DatetimeIndex + DateOffset, so will be needed for DatetimeArray + DateOffset.
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.
we might want to make this private, i dont' think we need to expose to the user
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.
I privatized this earlier today, but have now changed my mind. For DateOffset arithmetic to work "for free" it needs to have the same name. We can revisit this later if needbe.
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.
OK, can you then add a comment like
TODO(EA): make this private
, for once we do the actual split (because I suppose then this is no longer a problem?)