Skip to content

TST: Ensure makeCategoricalIndex categories are unique #46429

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 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/categoricals.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def time_remove_categories(self):
class Rank:
def setup(self):
N = 10**5
ncats = 100
ncats = 20

self.s_str = pd.Series(tm.makeCategoricalIndex(N, ncats)).astype(str)
self.s_str_cat = pd.Series(self.s_str, dtype="category")
Expand Down
2 changes: 1 addition & 1 deletion pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def makeUnicodeIndex(k=10, name=None):

def makeCategoricalIndex(k=10, n=3, name=None, **kwargs):
"""make a length k index or n categories"""
x = rands_array(nchars=4, size=n)
x = rands_array(nchars=4, size=n, replace=False)
return CategoricalIndex(
Categorical.from_codes(np.arange(k) % n, categories=x), name=name, **kwargs
)
Expand Down
4 changes: 2 additions & 2 deletions pandas/_testing/_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def randbool(size=(), p: float = 0.5):
)


def rands_array(nchars, size, dtype="O"):
def rands_array(nchars, size, dtype="O", replace=True):
"""
Generate an array of byte strings.
"""
retval = (
np.random.choice(RANDS_CHARS, size=nchars * np.prod(size))
np.random.choice(RANDS_CHARS, size=nchars * np.prod(size), replace=replace)
.view((np.str_, nchars))
.reshape(size)
)
Expand Down