Skip to content
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

PERF: join on unordered CategoricalIndex #56345

Merged

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley commented Dec 5, 2023

existing test: test_join_with_categorical_index

import pandas as pd
import numpy as np

categories = [f"cat_{i:03}" for i in range(1000)]

idx1 = pd.CategoricalIndex(np.repeat(categories, 1000), categories=categories)
idx2 = pd.CategoricalIndex(categories[100:200], categories=reversed(categories))

df1 = pd.DataFrame({"val1": 1}, index=idx1)
df2 = pd.DataFrame({"val2": 2}, index=idx2)

%timeit df1.join(df2)

# 129 ms ± 7.93 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)   -> main
# 28.4 ms ± 1.18 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)  -> PR

@lukemanley lukemanley added Performance Memory or execution speed performance Reshaping Concat, Merge/Join, Stack/Unstack, Explode Categorical Categorical Data Type labels Dec 5, 2023
@lukemanley lukemanley added this to the 2.2 milestone Dec 5, 2023
@@ -4930,6 +4936,18 @@ def _get_leaf_sorter(labels: list[np.ndarray]) -> npt.NDArray[np.intp]:
)
return join_index, left_indexer, right_indexer

def _can_join_monotonic(self, other):
if (
# not isinstance(self.dtype, CategoricalDtype)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Is this still relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, forgot to remove that. Its now removed. thanks

@mroeschke mroeschke merged commit f2b3795 into pandas-dev:main Dec 6, 2023
43 of 44 checks passed
@mroeschke
Copy link
Member

Thanks @lukemanley

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Performance Memory or execution speed performance Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants