BUG: Index.str.partition gives ValueError while trying to compute index name (expand=False) (original) (raw)

Index.str.partition's behaviour changed in 3ab35b4 in a backwards incompatible way which doesn't seem intentional.

Code Sample, a copy-pastable example if possible

python3 -c 'import pandas; pandas.Index(["a,b", "c,d"], name="hello").str.partition(",")'

Traceback (most recent call last): File "", line 1, in File "/home/pwaller/.local/src/pandas/pandas/core/strings.py", line 1432, in partition return self._wrap_result(result, expand=expand) File "/home/pwaller/.local/src/pandas/pandas/core/strings.py", line 1348, in _wrap_result return MultiIndex.from_tuples(result, names=name) File "/home/pwaller/.local/src/pandas/pandas/indexes/multi.py", line 889, in from_tuples return MultiIndex.from_arrays(arrays, sortorder=sortorder, names=names) File "/home/pwaller/.local/src/pandas/pandas/indexes/multi.py", line 844, in from_arrays names=names, verify_integrity=False) File "/home/pwaller/.local/src/pandas/pandas/indexes/multi.py", line 92, in new result._set_names(names) File "/home/pwaller/.local/src/pandas/pandas/indexes/multi.py", line 446, in _set_names raise ValueError('Length of names must match number of levels in ' ValueError: Length of names must match number of levels in MultiIndex.

Expected Output

In [1]: import pandas; pandas.Index(["a,b", "c,d"], name="hello").str.partition(",") Out[1]: MultiIndex(levels=[['a', 'c'], [','], ['b', 'd']], labels=[[0, 1], [0, 0], [0, 1]])

Versions

I bisected the problem to 3ab35b4 (cc @sinhrks). The problem is not present in 0.17.1 and is present in 0.18.0rc2.

Note: when I use a name="foo", it happens to work because it has the correct length, the index name ends up being ["f", "o", "o"], so it's possible this is tested somewhere and happens to work even though it's not correct for a large number of use cases.