Skip to content

Commit 38ff9d5

Browse files
author
y-p
committed
BUG: util.testing.makeCustomIndex dies when nlevels > nentries
1 parent 76ed23b commit 38ff9d5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pandas/util/testing.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from numpy.random import randn
1515
import numpy as np
1616

17-
from pandas.core.common import isnull
17+
from pandas.core.common import isnull, _is_sequence
1818
import pandas.core.index as index
1919
import pandas.core.series as series
2020
import pandas.core.frame as frame
@@ -375,6 +375,7 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None,
375375
ndupe_l - (Optional), list of ints, the number of rows for which the
376376
label will repeated at the corresponding level, you can specify just
377377
the first few, the rest will use the default ndupe_l of 1.
378+
len(ndupe_l) <= nlevels.
378379
idx_type - "i"/"f"/"s"/"u"/"dt".
379380
If idx_type is not None, `idx_nlevels` must be 1.
380381
"i"/"f" creates an integer/float index,
@@ -386,8 +387,8 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None,
386387

387388
from pandas.util.compat import Counter
388389
if ndupe_l is None:
389-
ndupe_l = [1] * nentries
390-
assert len(ndupe_l) <= nentries
390+
ndupe_l = [1] * nlevels
391+
assert (_is_sequence(ndupe_l) and len(ndupe_l) <= nlevels)
391392
assert (names is None or names is False
392393
or names is True or len(names) is nlevels)
393394
assert idx_type is None or \
@@ -417,9 +418,9 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None,
417418
raise ValueError('"%s" is not a legal value for `idx_type`, use '
418419
'"i"/"f"/"s"/"u"/"dt".' % idx_type)
419420

420-
if len(ndupe_l) < nentries:
421-
ndupe_l.extend([1] * (nentries - len(ndupe_l)))
422-
assert len(ndupe_l) == nentries
421+
if len(ndupe_l) < nlevels:
422+
ndupe_l.extend([1] * (nlevels - len(ndupe_l)))
423+
assert len(ndupe_l) == nlevels
423424

424425
assert all([x > 0 for x in ndupe_l])
425426

@@ -503,6 +504,7 @@ def makeCustomDataframe(nrows, ncols, c_idx_names=True, r_idx_names=True,
503504
r_idx_names=["FEE","FI","FO","FAM"],
504505
c_idx_nlevels=2)
505506
507+
>> a=mkdf(5,3,r_idx_nlevels=2,c_idx_nlevels=4)
506508
"""
507509

508510
assert c_idx_nlevels > 0

0 commit comments

Comments
 (0)