Skip to content

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

Merged
merged 39 commits into from
Mar 14, 2020

Conversation

jbrockmendel
Copy link
Member

No description provided.

@jbrockmendel jbrockmendel added Refactor Internal refactoring of code Constructors Series/DataFrame/Index/pd.array Constructors labels Feb 28, 2020
Copy link
Contributor

@jreback jreback left a 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):
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls comment the cases

@@ -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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WAT?

Copy link
Member Author

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")
Copy link
Contributor

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)

Copy link
Member Author

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

@jbrockmendel
Copy link
Member Author

comments addressed + green

@jreback jreback added this to the 1.1 milestone Mar 14, 2020
@jreback jreback merged commit f676a21 into pandas-dev:master Mar 14, 2020
@jreback
Copy link
Contributor

jreback commented Mar 14, 2020

thanks

@jbrockmendel
Copy link
Member Author

alright! i think with this the only _simple_new that isnt actually simple is IntervalArray

@jbrockmendel jbrockmendel deleted the simplenew-dta branch March 14, 2020 02:29
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants