-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
REF: Refactor Date/TimeLikeOps #24038
Conversation
Moves the implementation / inheritence from indexes to arrays.
Hello @TomAugspurger! Thanks for submitting the PR.
|
Codecov Report
@@ Coverage Diff @@
## master #24038 +/- ##
==========================================
- Coverage 42.46% 42.45% -0.01%
==========================================
Files 161 161
Lines 51557 51557
==========================================
- Hits 21892 21889 -3
- Misses 29665 29668 +3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24038 +/- ##
==========================================
- Coverage 42.46% 42.45% -0.01%
==========================================
Files 161 161
Lines 51557 51556 -1
==========================================
- Hits 21892 21888 -4
- Misses 29665 29668 +3
Continue to review full report at Codecov.
|
@@ -80,6 +82,189 @@ def _get_attributes_dict(self): | |||
return {k: getattr(self, k, None) for k in self._attributes} | |||
|
|||
|
|||
class DatelikeOps(object): | |||
""" | |||
Common ops for DatetimeIndex/PeriodIndex, but not TimedeltaIndex. |
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.
Index --> Array/Index
from pandas import Index | ||
return Index(self.format(date_format=date_format), | ||
dtype=compat.text_type) | ||
strftime.__doc__ = """ |
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.
Not a big deal, but is there a reason not to put this docstring in the normal docstring place and then accomplish the formatting with @Substitution(...)
?
Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex. | ||
""" | ||
|
||
_round_doc = ( |
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 we avoid having these in the TimedeltaArray/Index namespace?
|
||
Returns | ||
------- | ||
DatetimeIndex, TimedeltaIndex, or Series |
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.
Array/Index/Series
if 'tz' in attribs: | ||
attribs['tz'] = None | ||
return self._ensure_localized( | ||
self._shallow_copy(result, **attribs), ambiguous, nonexistent |
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.
The array classes don't have _shallow_copy anymore. Use _simple_new directly?
------- | ||
i8 1d array | ||
""" | ||
from pandas import Index |
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.
Is there any way to avoid this? We've pretty assiduously kept the EA subclasses Index-ignorant so far
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.
That's what the old version did. I haven't looked at which is more appropriate here.
attribs['freq'] = None | ||
if 'tz' in attribs: | ||
attribs['tz'] = None | ||
return self._ensure_localized( |
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.
Do the array classes have _ensure_localized?
+1 on the scope. Needs tests for the methods added to DTA/TDA/PA |
In response to So in response to
That can't be done yet (at least I don't see an easy way), until the indexes have been split from the arrays. Things like |
ok with going ahead with this to avoid blocking and making diffs easier. @jbrockmendel |
OK. I'll see if I can implement tests in a follow-up. |
thanks @TomAugspurger |
No real functional changes, just an inheritance reorganization to make the diff at #24024 smaller.
Changes: