-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: make DatetimeIndex._simple_new actually simple #32282
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
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.
some questions. generally like the simplifcation, but it does make a bit for awkardness elsewhere
@@ -36,7 +32,16 @@ def _new_DatetimeIndex(cls, d): | |||
if "data" in d and not isinstance(d["data"], DatetimeIndex): | |||
# Avoid need to verify integrity by calling simple_new directly | |||
data = d.pop("data") | |||
result = cls._simple_new(data, **d) | |||
if not isinstance(data, DatetimeArray): |
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.
what is all this about?
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.
backward compat for old pickles
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 make this nicer. it is very hard to grok.
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.
pls comment the cases
pandas/tseries/offsets.py
Outdated
@@ -1155,7 +1155,12 @@ def apply_index(self, i): | |||
shifted = liboffsets.shift_months(i.asi8, self.n, self._day_opt) | |||
# TODO: going through __new__ raises on call to _validate_frequency; | |||
# are we passing incorrect freq? | |||
return type(i)._simple_new(shifted, freq=i.freq, dtype=i.dtype) | |||
dta = i | |||
if not isinstance(i._data, np.ndarray): |
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.
WAT?
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.
compat for getting either a DTA or a DTI, we already do this in a couple places. I think we can do it just once by putting it in the apply_index_wraps
decorator
@@ -816,7 +809,10 @@ def _fast_union(self, other, sort=None): | |||
loc = right.searchsorted(left_end, side="right") | |||
right_chunk = right.values[loc:] | |||
dates = concat_compat((left.values, right_chunk)) | |||
return self._shallow_copy(dates) | |||
result = self._shallow_copy(dates) | |||
result._set_freq("infer") |
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.
you could change _set_freq to return self to make this idiom more clear (also _set_freq should be marked in the doc-string as a mutating function)
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.
Holding off on this since _set_freq needs a bigger rethink, xref #31218.
All other comments addressed, i think
comments addressed + green |
thanks |
alright! i think with this the only _simple_new that isnt actually simple is IntervalArray |
No description provided.