-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Revert set_index inspection/error handling for 0.24.1 #25085
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
31dcbb7
DOC: Minor what's new fix (#24933)
rth 84056c5
Backport PR #24916: BUG-24212 fix regression in #24897 (#24951)
meeseeksmachine e22a6c8
Revert "Backport PR #24916: BUG-24212 fix regression in #24897 (#24951)"
jorisvandenbossche 638ac19
Backport PR #24965: Fixed itertuples usage in to_dict (#24978)
meeseeksmachine 72dc33f
Backport PR #24989: DOC: Document breaking change to read_csv (#24996)
meeseeksmachine fd1c66c
Backport PR #24964: DEPR: Fixed warning for implicit registration (#2…
meeseeksmachine d54c3a5
Backport PR #24973: fix for BUG: grouping with tz-aware: Values falls…
TomAugspurger e3cc0b1
Backport PR #24967: REGR: Preserve order by default in Index.differen…
meeseeksmachine c228597
Backport PR #24961: fix+test to_timedelta('NaT', box=False) (#25025)
meeseeksmachine 7956533
Backport PR #25033: BUG: Fixed merging on tz-aware (#25041)
meeseeksmachine 722bb79
Backport PR #24993: Test nested PandasArray (#25042)
meeseeksmachine e3634b1
Backport PR #25039: BUG: avoid usage in_qtconsole for recent IPython …
meeseeksmachine 4f865c5
Backport PR #25024: REGR: fix read_sql delegation for queries on MySQ…
meeseeksmachine c21d32f
Backport PR #25069: REGR: rename_axis with None should remove axis na…
meeseeksmachine 5cb622a
DOC: 0.24.1 whatsnew (#25027)
TomAugspurger c397839
Revert "DOC: update DF.set_index (#24762)"
h-vetinari 4a211e9
Revert "API: better error-handling for df.set_index (#22486)"
h-vetinari 103a092
Replace deprecated assert_raises_regex
h-vetinari 8086f39
Re-migrate 0.24.0 extension (.txt -> .rst)
h-vetinari 999295e
Re-add docstring clarifications
h-vetinari c24df00
Backport PR #25063: API: change Index set ops sort=True -> sort=None …
meeseeksmachine 627b17a
trigger azure
TomAugspurger bc405ce
Backport PR #25084: DOC: Cleanup 0.24.1 whatsnew (#25086)
meeseeksmachine 02db6ec
Backport PR #25026: DOC: Start 0.24.2.rst (#25073)
meeseeksmachine ff34d2e
trigger azure
TomAugspurger 2aa800c
Merge remote-tracking branch 'upstream/0.24.x' into revert_set_index
h-vetinari 330b343
Keep all tests from #24984; xfail where necessary
h-vetinari 24a4df4
Merge remote-tracking branch 'origin/revert_set_index' into revert_se…
h-vetinari 963a813
Remove stray debugging line
h-vetinari 4db4849
Add whatsnew
h-vetinari 8c913c2
Merge remote-tracking branch 'upstream/master' into h-vetinari-revert…
jorisvandenbossche 5a6cc73
Merge remote-tracking branch 'upstream/master' into revert_set_index
h-vetinari ff62753
Re-add reverted 0.24.0 whatsnew
h-vetinari 65c7880
Re-add handling for duplicate drops
h-vetinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Revert "DOC: update DF.set_index (#24762)"
This reverts commit e984947.
- Loading branch information
commit c397839705603f82f02bc2c32961352b160b80ec
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ def test_set_index_after_mutation(self): | |
# 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, | ||
list, lambda x: [list(x)], | ||
list, tuple, iter, lambda x: [list(x)], | ||
lambda x: MultiIndex.from_arrays([x])]) | ||
@pytest.mark.parametrize('append, index_name', [(True, None), | ||
(True, 'B'), (True, 'test'), (False, None)]) | ||
|
@@ -135,7 +135,7 @@ def test_set_index_pass_single_array(self, frame_of_index_cols, | |
with pytest.raises(KeyError, match=msg): | ||
df.set_index(key, drop=drop, append=append) | ||
else: | ||
# np.array/list-of-list "forget" the name of B | ||
# np.array/tuple/iter/list-of-list "forget" the name of B | ||
name_mi = getattr(key, 'names', None) | ||
name = [getattr(key, 'name', None)] if name_mi is None else name_mi | ||
|
||
|
@@ -150,7 +150,8 @@ def test_set_index_pass_single_array(self, frame_of_index_cols, | |
|
||
# MultiIndex constructor does not work directly on Series -> lambda | ||
# also test index name if append=True (name is duplicate here for A & B) | ||
@pytest.mark.parametrize('box', [Series, Index, np.array, list, | ||
@pytest.mark.parametrize('box', [Series, Index, np.array, | ||
list, tuple, iter, | ||
lambda x: MultiIndex.from_arrays([x])]) | ||
@pytest.mark.parametrize('append, index_name', | ||
[(True, None), (True, 'A'), (True, 'B'), | ||
|
@@ -162,7 +163,7 @@ def test_set_index_pass_arrays(self, frame_of_index_cols, | |
df.index.name = index_name | ||
|
||
keys = ['A', box(df['B'])] | ||
# np.array/list "forget" the name of B | ||
# np.array/list/tuple/iter "forget" the name of B | ||
names = ['A', None if box in [np.array, list, tuple, iter] else 'B'] | ||
|
||
result = df.set_index(keys, drop=drop, append=append) | ||
|
@@ -178,10 +179,12 @@ def test_set_index_pass_arrays(self, frame_of_index_cols, | |
# MultiIndex constructor does not work directly on Series -> lambda | ||
# We also emulate a "constructor" for the label -> lambda | ||
# also test index name if append=True (name is duplicate here for A) | ||
@pytest.mark.parametrize('box2', [Series, Index, np.array, list, | ||
@pytest.mark.parametrize('box2', [Series, Index, np.array, | ||
list, tuple, iter, | ||
lambda x: MultiIndex.from_arrays([x]), | ||
lambda x: x.name]) | ||
@pytest.mark.parametrize('box1', [Series, Index, np.array, list, | ||
@pytest.mark.parametrize('box1', [Series, Index, np.array, | ||
list, tuple, iter, | ||
lambda x: MultiIndex.from_arrays([x]), | ||
lambda x: x.name]) | ||
@pytest.mark.parametrize('append, index_name', [(True, None), | ||
|
@@ -195,14 +198,17 @@ def test_set_index_pass_arrays_duplicate(self, frame_of_index_cols, drop, | |
keys = [box1(df['A']), box2(df['A'])] | ||
result = df.set_index(keys, drop=drop, append=append) | ||
|
||
# if either box was iter, the content has been consumed; re-read it | ||
keys = [box1(df['A']), box2(df['A'])] | ||
|
||
# need to adapt first drop for case that both keys are 'A' -- | ||
# cannot drop the same column twice; | ||
# use "is" because == would give ambiguous Boolean error for containers | ||
first_drop = False if (keys[0] is 'A' and keys[1] is 'A') else drop | ||
|
||
# to test against already-tested behaviour, we add sequentially, | ||
# hence second append always True; must wrap keys in list, otherwise | ||
# box = list would be interpreted as keys | ||
# box = list would be illegal | ||
expected = df.set_index([keys[0]], drop=first_drop, append=append) | ||
expected = expected.set_index([keys[1]], drop=drop, append=True) | ||
tm.assert_frame_equal(result, expected) | ||
|
@@ -232,7 +238,7 @@ def test_set_index_verify_integrity(self, frame_of_index_cols): | |
|
||
@pytest.mark.parametrize('append', [True, False]) | ||
@pytest.mark.parametrize('drop', [True, False]) | ||
def test_set_index_raise_keys(self, frame_of_index_cols, drop, append): | ||
def test_set_index_raise(self, frame_of_index_cols, drop, append): | ||
df = frame_of_index_cols | ||
|
||
with pytest.raises(KeyError, match="['foo', 'bar', 'baz']"): | ||
|
@@ -243,31 +249,14 @@ def test_set_index_raise_keys(self, frame_of_index_cols, drop, append): | |
with pytest.raises(KeyError, match='X'): | ||
df.set_index([df['A'], df['B'], 'X'], drop=drop, append=append) | ||
|
||
msg = "[('foo', 'foo', 'foo', 'bar', 'bar')]" | ||
# tuples always raise KeyError | ||
with pytest.raises(KeyError, match=msg): | ||
df.set_index(tuple(df['A']), drop=drop, append=append) | ||
|
||
# also within a list | ||
with pytest.raises(KeyError, match=msg): | ||
df.set_index(['A', df['A'], tuple(df['A'])], | ||
drop=drop, append=append) | ||
|
||
@pytest.mark.parametrize('append', [True, False]) | ||
@pytest.mark.parametrize('drop', [True, False]) | ||
@pytest.mark.parametrize('box', [set, iter]) | ||
def test_set_index_raise_on_type(self, frame_of_index_cols, box, | ||
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. could leave these tests and just xfail them. |
||
drop, append): | ||
df = frame_of_index_cols | ||
|
||
msg = 'The parameter "keys" may be a column key, .*' | ||
# forbidden type, e.g. set/tuple/iter | ||
with pytest.raises(ValueError, match=msg): | ||
df.set_index(box(df['A']), drop=drop, append=append) | ||
msg = 'The parameter "keys" may only contain a combination of.*' | ||
# forbidden type, e.g. set | ||
with pytest.raises(TypeError, match=msg): | ||
df.set_index(set(df['A']), drop=drop, append=append) | ||
|
||
# forbidden type in list, e.g. set/tuple/iter | ||
with pytest.raises(ValueError, match=msg): | ||
df.set_index(['A', df['A'], box(df['A'])], | ||
# forbidden type in list, e.g. set | ||
with pytest.raises(TypeError, match=msg): | ||
df.set_index(['A', df['A'], set(df['A'])], | ||
drop=drop, append=append) | ||
|
||
def test_construction_with_categorical_index(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.