Skip to content

ENH/PERF: add ExtensionArray.duplicated #55255

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 20 commits into from
Oct 3, 2023

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley commented Sep 23, 2023

[updated]

asv continuous -f 1.1 upstream/main arrow-temporal-duplicated -b algorithms.Duplicated

       before           after         ratio
-         101±2ms         51.6±3ms     0.51  algorithms.Duplicated.time_duplicated(False, False, 'string[pyarrow]')
-        98.5±3ms         47.3±4ms     0.48  algorithms.Duplicated.time_duplicated(False, 'first', 'string[pyarrow]')
-        96.0±4ms         45.5±4ms     0.47  algorithms.Duplicated.time_duplicated(False, 'last', 'string[pyarrow]')
-      1.57±0.03s       13.6±0.3ms     0.01  algorithms.Duplicated.time_duplicated(False, False, 'timestamp[ms][pyarrow]')
-      1.54±0.02s       13.1±0.7ms     0.01  algorithms.Duplicated.time_duplicated(False, 'first', 'timestamp[ms][pyarrow]')
-         1.55±0s       12.8±0.7ms     0.01  algorithms.Duplicated.time_duplicated(False, 'last', 'timestamp[ms][pyarrow]')

@lukemanley lukemanley added Performance Memory or execution speed performance Arrow pyarrow functionality labels Sep 23, 2023
@lukemanley lukemanley added this to the 2.2 milestone Sep 23, 2023
values = values._to_masked() # type: ignore[union-attr]
else:
values = (
values._maybe_convert_datelike_array() # type: ignore[union-attr]
Copy link
Member

Choose a reason for hiding this comment

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

let's just make a EA.duplicated for this? xref #27264, #48424

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to implement ExtensionArray.duplicated. This is now a bit more general in that it is faster for more than just the pyarrow timestamp and duration types. See updated timings in OP.

@lukemanley lukemanley changed the title PERF: Series.duplicated for pyarrow timestamp and duration types PERF: Series.duplicated for pyarrow dtypes Sep 26, 2023
@lukemanley lukemanley changed the title PERF: Series.duplicated for pyarrow dtypes ENH/PERF: add ExtensionArray.duplicated Sep 27, 2023
def duplicated(
self, keep: Literal["first", "last", False] = "first"
) -> npt.NDArray[np.bool_]:
return algos.duplicated(np.asarray(self), keep=keep)
Copy link
Member

Choose a reason for hiding this comment

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

Does sparse need to pass mask for it's NA values?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated to pass the mask

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

One comment otherwise looks good

@@ -80,7 +81,7 @@ class Duplicated:
"datetime64[ns]",
"datetime64[ns, tz]",
"timestamp[ms][pyarrow]",
"duration[s][pyarrow]",
"string[pyarrow]",
Copy link
Member

Choose a reason for hiding this comment

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

why getting rid of duration here?

i think at some pint "string" on L80 will become redundant with "string[pyarrow]" here, so maybe a TODO(3.0) to get rid of one when that happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

The original version of this PR only targeted pyarrow timestamp and duration types. The current version improves perf for a larger number of pyarrow types so thought I'd add a non-temporal type as well. I can add it back if you want.

Copy link
Member

Choose a reason for hiding this comment

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

im fine either way, just curious. usually for asvs we go throw the kitchen sink at it but there are downsides to that

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

@mroeschke mroeschke merged commit 3bf0f64 into pandas-dev:main Oct 3, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

@rhshadrach
Copy link
Member

This patch may have induced a performance regression. If it was a necessary behavior change, this may have been expected and everything is okay.

Please check the links below. If any ASVs are parameterized, the combinations of parameters that a regression has been detected for appear as subbullets.

Subsequent benchmarks may have skipped some commits. The link below lists the commits that are between the two benchmark runs where the regression was identified.

6e6a683...3bf0f64

@lukemanley lukemanley deleted the arrow-temporal-duplicated branch November 16, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Performance Memory or execution speed performance
Projects
None yet
4 participants