8000 DEPR/API: disallow lists within list for set_index by h-vetinari · Pull Request #24697 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR/API: disallow lists within list for set_index #24697

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

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bf0eee0
DEPR/API: disallow lists within list for set_index
h-vetinari Jan 10, 2019
ed0de1f
Add deprecation and whatsnew
h-vetinari Jan 10, 2019
dc274e3
restore test for list-of-scalars interpreted as keys
h-vetinari Jan 10, 2019
623fc9a
Small doc fixes
h-vetinari Jan 10, 2019
5f6e303
Improve docstring; small fixes
h-vetinari Jan 10, 2019
13d4e40
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Jan 10, 2019
813b4fc
Remove last mention of "list-like"
h-vetinari Jan 10, 2019
4c130ee
rephrase "illegal"
h-vetinari Jan 10, 2019
8731834
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Jan 10, 2019
29fbc6a
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Jan 14, 2019
cc04a64
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Jan 14, 2019
e1d999b
Improve warning message (review TomAugspurger)
h-vetinari Jan 14, 2019
726ef1c
typo
h-vetinari Jan 14, 2019
0e1f709
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Jan 16, 2019
b0b326f
Tuples always considered keys; KeyError, not ValueError if missing
h-vetinari Jan 16, 2019
6cbcc47
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Jan 20, 2019
c881aaa
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
8000 h-vetinari Feb 24, 2019
0214801
Actually commit fix for conflict, duh
h-vetinari Feb 24, 2019
61c511d
Move whatsnew to 0.25
h-vetinari Feb 24, 2019
7381245
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Mar 1, 2019
5fa544c
Add deprecation-section (review jreback)
h-vetinari Mar 1, 2019
a016bf0
Merge remote-tracking branch 'upstream/master' into depr_LL_set_index
h-vetinari Mar 3, 2019
0c65876
Fix doc fails
h-vetinari Mar 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
restore test for list-of-scalars interpreted as keys
  • Loading branch information
h-vetinari committed Jan 10, 2019
commit dc274e3926747f4eabd9ccdada39803ca1abbe72
26 changes: 16 additions & 10 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_set_index_after_mutation(self):
# MultiIndex constructor does not work directly on Series -> lambda
# Add list-of-list constructor because list is ambiguous -> lambda
# also test index name if append=True (name is duplicate here for B)
@pytest.mark.parametrize('box', [Series, Index, np.array,
@pytest.mark.parametrize('box', [Series, Index, np.array, list,
lambda x: MultiIndex.from_arrays([x])])
@pytest.mark.parametrize('append, index_name', [(True, None),
(True, 'B'), (True, 'test'), (False, None)])
Expand All @@ -128,18 +128,24 @@ def test_set_index_pass_single_array(self, frame_of_index_cols,
df.index.name = index_name

key = box(df['B'])
# np.array "forgets" the name of B
name_mi = getattr(key, 'names', None)
name = [getattr(key, 'name', None)] if name_mi is None else name_mi
if box == list:
# list of strings gets interpreted as list of keys
msg = "['one', 'two', 'three', 'one', 'two']"
with pytest.raises(KeyError, match=msg):
df.set_index(key, drop=drop, append=append)
else:
# np.array "forgets" the name of B
name_mi = getattr(key, 'names', None)
name = [getattr(key, 'name', None)] if name_mi is None else name_mi

result = df.set_index(key, drop=drop, append=append)
result = df.set_index(key, drop=drop, append=append)

# only valid column keys are dropped
# since B is always passed as array above, nothing is dropped
expected = df.set_index(['B'], drop=False, append=append)
expected.index.names = [index_name] + name if append else name
# only valid column keys are dropped
# since B is always passed as array above, nothing is dropped
expected = df.set_index(['B'], drop=False, append=append)
expected.index.names = [index_name] + name if append else name

tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(result, expected)

# MultiIndex constructor does not work directly on Series -> lambda
# also test index name if append=True (name is duplicate here for A & B)
Expand Down
0