-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: tighten what we accept in TimedeltaIndex._simple_new #31315
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
14 commits
Select commit
Hold shift + click to select a range
13b6fe8
REF: require PeriodArray in PeriodIndex._simple_new
jbrockmendel 4477131
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel a09884f
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel 02e9f79
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel 8034d43
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel 13facbc
tighter control over TimedeltaArray._simple_new args
jbrockmendel 9cce216
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel 92d4d7e
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel c1a56a8
be stricter in shallow_copy
jbrockmendel 9c90e2d
check none-freq
jbrockmendel aa2668c
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel cfa9d79
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
jbrockmendel b30aafa
implement _asfreq_compat
jbrockmendel 4fe9849
Merge branch 'master' of https://github.com/pandas-dev/pandas into si…
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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
from pandas.core.groupby.groupby import GroupBy, _GroupBy, _pipe_template, get_groupby | ||
from pandas.core.groupby.grouper import Grouper | ||
from pandas.core.groupby.ops import BinGrouper | ||
from pandas.core.indexes.api import Index | ||
from pandas.core.indexes.datetimes import DatetimeIndex, date_range | ||
from pandas.core.indexes.period import PeriodIndex, period_range | ||
from pandas.core.indexes.timedeltas import TimedeltaIndex, timedelta_range | ||
|
@@ -424,10 +425,7 @@ def _wrap_result(self, result): | |
|
||
if isinstance(result, ABCSeries) and result.empty: | ||
obj = self.obj | ||
if isinstance(obj.index, PeriodIndex): | ||
result.index = obj.index.asfreq(self.freq) | ||
else: | ||
result.index = obj.index._shallow_copy(freq=self.freq) | ||
result.index = _asfreq_compat(obj.index, freq=self.freq) | ||
result.name = getattr(obj, "name", None) | ||
|
||
return result | ||
|
@@ -1787,8 +1785,8 @@ def asfreq(obj, freq, method=None, how=None, normalize=False, fill_value=None): | |
|
||
elif len(obj.index) == 0: | ||
new_obj = obj.copy() | ||
new_obj.index = obj.index._shallow_copy(freq=to_offset(freq)) | ||
|
||
new_obj.index = _asfreq_compat(obj.index, freq) | ||
else: | ||
dti = date_range(obj.index[0], obj.index[-1], freq=freq) | ||
dti.name = obj.index.name | ||
|
@@ -1797,3 +1795,28 @@ def asfreq(obj, freq, method=None, how=None, normalize=False, fill_value=None): | |
new_obj.index = new_obj.index.normalize() | ||
|
||
return new_obj | ||
|
||
|
||
def _asfreq_compat(index, freq): | ||
""" | ||
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. should this be in the indexes sub-tree? 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. if we start using it elsewhere then we can move it. as long as its just here, id prefer to keep it private |
||
Helper to mimic asfreq on (empty) DatetimeIndex and TimedeltaIndex. | ||
|
||
Parameters | ||
---------- | ||
index : PeriodIndex, DatetimeIndex, or TimedeltaIndex | ||
freq : DateOffset | ||
|
||
Returns | ||
------- | ||
same type as index | ||
""" | ||
if len(index) != 0: | ||
# This should never be reached, always checked by the caller | ||
raise ValueError( | ||
"Can only set arbitrary freq for empty DatetimeIndex or TimedeltaIndex" | ||
) | ||
if isinstance(index, PeriodIndex): | ||
new_index = index.asfreq(freq=freq) | ||
else: | ||
new_index = Index([], dtype=index.dtype, freq=freq, name=index.name) | ||
return new_index |
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.
Uh oh!
There was an error while loading. Please reload this page.