Skip to content

PERF: Fix performance regression in get_loc of IntervalIndex #51339

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 4 commits into from
Feb 14, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Feb 12, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

caused in 184e1674

No need to call validate here

https://asv-runner.github.io/asv-collection/pandas/#indexing.IntervalIndexing.time_loc_list

@phofl phofl added Performance Memory or execution speed performance Interval Interval data type labels Feb 12, 2023
@phofl phofl added this to the 2.0 milestone Feb 12, 2023
@@ -727,7 +730,7 @@ def __getitem__(
if np.ndim(left) > 1:
# GH#30588 multi-dimensional indexer disallowed
raise ValueError("multi-dimensional indexing not allowed")
return self._shallow_copy(left, right)
return self._shallow_copy(left, right, verify_integrity=False)
Copy link
Member

Choose a reason for hiding this comment

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

couldnt we also skip _ensure_simple_new_inputs, i.e. just do

return self._simple_new(left, right, dtype=self.dtype)

Copy link
Member Author

Choose a reason for hiding this comment

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

let's see if it works, probably not necessary

@@ -675,7 +677,8 @@ def _shallow_copy(self: IntervalArrayT, left, right) -> IntervalArrayT:
"""
dtype = IntervalDtype(left.dtype, closed=self.closed)
left, right, dtype = self._ensure_simple_new_inputs(left, right, dtype=dtype)
self._validate(left, right, dtype=dtype)
if verify_integrity:
Copy link
Member

Choose a reason for hiding this comment

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

so is this still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not for this regression, but I think we should look through all usages to see if it's necessary everywhere

@jbrockmendel
Copy link
Member

pandas/core/arrays/interval.py:729: error: Argument 2 to "_simple_new" of "IntervalArray" has incompatible type "Union[Period, Timestamp, Timedelta, NaTType, DatetimeArray, TimedeltaArray, ndarray[Any, Any]]"; expected "Union[Union[DatetimeArray, TimedeltaArray], ndarray[Any, Any]]" [arg-type]

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM pending green

@phofl phofl merged commit 7d545f0 into pandas-dev:main Feb 14, 2023
@phofl phofl deleted the perf_interval branch February 14, 2023 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Interval Interval data type Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants