-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: preserve object-dtype index when accessing DataFrame column / PERF: improve perf of Series fastpath constructor #42950
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
Changes from 1 commit
64f9690
57659b8
64e7403
972185f
973713f
a133162
15e274e
33fde4f
0f1ee8a
22cc921
94cc2ad
da90ef1
2443961
0431a11
daebcf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,7 +441,11 @@ def __init__( | |
data = SingleArrayManager.from_array(data, index) | ||
|
||
generic.NDFrame.__init__(self, data) | ||
self.name = name | ||
if fastpath: | ||
# skips validation of the name | ||
object.__setattr__(self, "_name", name) | ||
else: | ||
self.name = name | ||
self._set_axis(0, index, fastpath=True) | ||
|
||
def _init_dict(self, data, index=None, dtype: Dtype | None = None): | ||
|
@@ -531,23 +535,23 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None: | |
if not fastpath: | ||
labels = ensure_index(labels) | ||
|
||
if labels._is_all_dates: | ||
deep_labels = labels | ||
if isinstance(labels, CategoricalIndex): | ||
deep_labels = labels.categories | ||
|
||
if not isinstance( | ||
deep_labels, (DatetimeIndex, PeriodIndex, TimedeltaIndex) | ||
): | ||
try: | ||
labels = DatetimeIndex(labels) | ||
# need to set here because we changed the index | ||
if fastpath: | ||
self._mgr.set_axis(axis, labels) | ||
except (tslibs.OutOfBoundsDatetime, ValueError): | ||
# labels may exceeds datetime bounds, | ||
# or not be a DatetimeIndex | ||
pass | ||
if labels._is_all_dates: | ||
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. nice! 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. Apparently this is being relied upon in the pytables code though .. And looking into it further, the change I made here of course changes behaviour, as it no longer try to infer object dtype as datetime in the fastpath. 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. Although that should probably be considered as a bug fix. With master:
where the index of the column-as-Series becomes different .. 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. IIRC we deprecated this, then un-deprecated bc we didn't have good warning handling/suppression, and were going to try to re-deprecate before long 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. Do you have a reference (issue/PR) for this? 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. There is #36697, but that's for the non-fastpath way, I think? While here it's specifically the fastpath that I am changing (which is not used when a user creates a Series directly themselves). 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. when we did that i dont remember any distinction being made between fastpath vs non-fastpath |
||
deep_labels = labels | ||
if isinstance(labels, CategoricalIndex): | ||
deep_labels = labels.categories | ||
|
||
if not isinstance( | ||
deep_labels, (DatetimeIndex, PeriodIndex, TimedeltaIndex) | ||
): | ||
try: | ||
labels = DatetimeIndex(labels) | ||
# need to set here because we changed the index | ||
if fastpath: | ||
self._mgr.set_axis(axis, labels) | ||
except (tslibs.OutOfBoundsDatetime, ValueError): | ||
# labels may exceeds datetime bounds, | ||
# or not be a DatetimeIndex | ||
pass | ||
|
||
object.__setattr__(self, "_index", labels) | ||
if not fastpath: | ||
|
Uh oh!
There was an error while loading. Please reload this page.