-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: fix: list
as index item does not raise
#61674
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,6 +567,14 @@ def __new__( | |
# Ensure we get 1-D array of tuples instead of 2D array. | ||
data = com.asarray_tuplesafe(data, dtype=_dtype_obj) | ||
|
||
# 60925 should raise when one of index's items is a list and others are not | ||
if any(isinstance(el, list) for el in data) and not all( | ||
isinstance(el, list) for el in data | ||
): | ||
Comment on lines
+570
to
+573
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No non-hashable value should occur here. Instead, can you do this check on |
||
raise ValueError( | ||
"Index names must all be hashable, or all lists to make MultiIndex" | ||
) | ||
|
||
try: | ||
arr = sanitize_array(data, None, dtype=dtype, copy=copy) | ||
except ValueError as err: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,9 +71,12 @@ def test_assign_index_sequences(self): | |
repr(df) | ||
|
||
# this travels an improper code path | ||
# 60925 should raise when one of index's items is a list and others are not | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use |
||
index[0] = ["faz", "boo"] | ||
df.index = index | ||
repr(df) | ||
msg = "Index names must all be hashable, or all lists to make MultiIndex" | ||
with pytest.raises(ValueError, match=msg): | ||
df.index = index | ||
repr(df) | ||
Comment on lines
+78
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it should raise on the first line, is that right? If so, can you remove |
||
|
||
def test_repr_with_mi_nat(self): | ||
df = DataFrame({"X": [1, 2]}, index=[[NaT, Timestamp("20130101")], ["a", "b"]]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.