-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
fix for TypeError: unorderable types" in when using set_index with multiple column names #22072
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
Changes from 12 commits
af2ab19
9bf7262
bcea58b
42f093d
bba1e9c
1b3959e
10ed01a
801803a
8daf9e6
4cd3c0c
c45705c
927f24f
213c4ea
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 |
---|---|---|
|
@@ -2538,7 +2538,10 @@ def _factorize_from_iterable(values): | |
ordered=values.ordered) | ||
codes = values.codes | ||
else: | ||
cat = Categorical(values, ordered=True) | ||
# The value of ordered is irrelevant since we don't use cat as such, | ||
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 add the issue reference |
||
# but only the resulting categories, the order of which is independent | ||
# from ordered. Set ordered to False as default. See GH #15457 | ||
cat = Categorical(values, ordered=False) | ||
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. Smart fix... but not really simple to understand. Please add a comment stating that the value of |
||
categories = cat.categories | ||
codes = cat.codes | ||
return codes, categories | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,3 +463,12 @@ def test_tuples_with_name_string(): | |
pd.Index(li, name='abc') | ||
with pytest.raises(ValueError): | ||
pd.Index(li, name='a') | ||
|
||
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 undo the change in this file? (it's extraneous to your PR) 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. @gfyoung (unless I'm wrong) this comment ended up showing here by mistake? |
||
|
||
def test_from_tuples_with_tuple_label(): | ||
# GH 15457 | ||
expected = pd.DataFrame([[2, 1, 2], [4, (1, 2), 3]], | ||
columns=['a', 'b', 'c']).set_index(['a', 'b']) | ||
idx = pd.MultiIndex.from_tuples([(2, 1), (4, (1, 2))], names=('a', 'b')) | ||
result = pd.DataFrame([2, 3], columns=['c'], index=idx) | ||
tm.assert_frame_equal(expected, result) |
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.
Double backticks around
TypeError
, no space after:class: