-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
De-duplicate add_offset_array methods #19835
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
Conversation
pandas/core/indexes/datetimelike.py
Outdated
| kwargs = {} | ||
| if not is_period_dtype(self): | ||
| kwargs['freq'] = 'infer' | ||
| return self.__class__(res_values, **kwargs) |
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.
use .shallow_copy
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.
Changed it to shallow_copy and it broke several tests, so just pushed with it changed back to self.__class__. For some reason DatetimeIndex._simple_new returns an ndarray if its input values have object-dtype, which is the case 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.
so try using _shallow_copy_with_infer, we by definition never ever use self.__class__ in Index construction.
| ---------- | ||
| other : Index, np.ndarray | ||
| object-dtype containing pd.DateOffset objects | ||
| op : {operator.add, operator.sub} |
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 you assert on the operator
Codecov Report
@@ Coverage Diff @@
## master #19835 +/- ##
==========================================
+ Coverage 91.57% 91.58% +<.01%
==========================================
Files 150 150
Lines 48903 48870 -33
==========================================
- Hits 44785 44758 -27
+ Misses 4118 4112 -6
Continue to review full report at Codecov.
|
|
thanks! |
Combine DTI/TDI/PI add_offset_array and sub_offset_array methods.
Re-order
__add__and__sub__if/else branches to put scalars up front.This was going to include fixes for DTI/TDI with ndarray[timedelta64]/ndarray[datetime64], but the diff got big enough to split that off to the next one.