Skip to content

Commit d7401bc

Browse files
mroeschkeyehoshuadimarsky
authored andcommitted
TST: Ensure makeCategoricalIndex categories are unique (pandas-dev#46429)
1 parent e9f7fb4 commit d7401bc

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

asv_bench/benchmarks/categoricals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def time_remove_categories(self):
187187
class Rank:
188188
def setup(self):
189189
N = 10**5
190-
ncats = 100
190+
ncats = 20
191191

192192
self.s_str = pd.Series(tm.makeCategoricalIndex(N, ncats)).astype(str)
193193
self.s_str_cat = pd.Series(self.s_str, dtype="category")

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def makeUnicodeIndex(k=10, name=None):
305305

306306
def makeCategoricalIndex(k=10, n=3, name=None, **kwargs):
307307
"""make a length k index or n categories"""
308-
x = rands_array(nchars=4, size=n)
308+
x = rands_array(nchars=4, size=n, replace=False)
309309
return CategoricalIndex(
310310
Categorical.from_codes(np.arange(k) % n, categories=x), name=name, **kwargs
311311
)

pandas/_testing/_random.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def randbool(size=(), p: float = 0.5):
1414
)
1515

1616

17-
def rands_array(nchars, size, dtype="O"):
17+
def rands_array(nchars, size, dtype="O", replace=True):
1818
"""
1919
Generate an array of byte strings.
2020
"""
2121
retval = (
22-
np.random.choice(RANDS_CHARS, size=nchars * np.prod(size))
22+
np.random.choice(RANDS_CHARS, size=nchars * np.prod(size), replace=replace)
2323
.view((np.str_, nchars))
2424
.reshape(size)
2525
)

0 commit comments

Comments
 (0)