-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
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 31 commits
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
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
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 |
---|---|---|
|
@@ -193,6 +193,11 @@ def test_set_index_pass_arrays_duplicate(self, frame_of_index_cols, drop, | |
df.index.name = index_name | ||
|
||
keys = [box1(df['A']), box2(df['A'])] | ||
|
||
TomAugspurger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
# == gives ambiguous Boolean for Series | ||
TomAugspurger marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if drop and keys[0] is 'A' and keys[1] is 'A': | ||
pytest.xfail(reason='broken due to reversion, see GH 25085') | ||
|
||
result = df.set_index(keys, drop=drop, append=append) | ||
|
||
# need to adapt first drop for case that both keys are 'A' -- | ||
|
@@ -253,23 +258,129 @@ def test_set_index_raise_keys(self, frame_of_index_cols, drop, append): | |
df.set_index(['A', df['A'], tuple(df['A'])], | ||
drop=drop, append=append) | ||
|
||
@pytest.mark.xfail(reason='broken due to revert, see GH 25085') | ||
@pytest.mark.parametrize('append', [True, False]) | ||
@pytest.mark.parametrize('drop', [True, False]) | ||
@pytest.mark.parametrize('box', [set, iter]) | ||
@pytest.mark.parametrize('box', [set, iter, lambda x: (y for y in x)], | ||
ids=['set', 'iter', 'generator']) | ||
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): | ||
# forbidden type, e.g. set/iter/generator | ||
with pytest.raises(TypeError, match=msg): | ||
df.set_index(box(df['A']), drop=drop, append=append) | ||
|
||
# forbidden type in list, e.g. set/tuple/iter | ||
with pytest.raises(ValueError, match=msg): | ||
# forbidden type in list, e.g. set/iter/generator | ||
with pytest.raises(TypeError, match=msg): | ||
df.set_index(['A', df['A'], box(df['A'])], | ||
drop=drop, append=append) | ||
|
||
def test_set_index_custom_label_type(self): | ||
# GH 24969 | ||
|
||
class Thing(object): | ||
def __init__(self, name, color): | ||
self.name = name | ||
self.color = color | ||
|
||
def __str__(self): | ||
return "<Thing %r>" % (self.name,) | ||
|
||
# necessary for pretty KeyError | ||
__repr__ = __str__ | ||
|
||
thing1 = Thing('One', 'red') | ||
thing2 = Thing('Two', 'blue') | ||
df = DataFrame({thing1: [0, 1], thing2: [2, 3]}) | ||
expected = DataFrame({thing1: [0, 1]}, | ||
index=Index([2, 3], name=thing2)) | ||
|
||
# use custom label directly | ||
result = df.set_index(thing2) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# custom label wrapped in list | ||
result = df.set_index([thing2]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# missing key | ||
thing3 = Thing('Three', 'pink') | ||
msg = "<Thing 'Three'>" | ||
with pytest.raises(KeyError, match=msg): | ||
# missing label directly | ||
df.set_index(thing3) | ||
|
||
with pytest.raises(KeyError, match=msg): | ||
# missing label in list | ||
df.set_index([thing3]) | ||
|
||
def test_set_index_custom_label_hashable_iterable(self): | ||
# GH 24969 | ||
|
||
# actual example discussed in GH 24984 was e.g. for shapely.geometry | ||
# objects (e.g. a collection of Points) that can be both hashable and | ||
# iterable; using frozenset as a stand-in for testing here | ||
|
||
class Thing(frozenset): | ||
# need to stabilize repr for KeyError (due to random order in sets) | ||
def __repr__(self): | ||
tmp = sorted(list(self)) | ||
# double curly brace prints one brace in format string | ||
return "frozenset({{{}}})".format(', '.join(map(repr, tmp))) | ||
|
||
thing1 = Thing(['One', 'red']) | ||
thing2 = Thing(['Two', 'blue']) | ||
df = DataFrame({thing1: [0, 1], thing2: [2, 3]}) | ||
expected = DataFrame({thing1: [0, 1]}, | ||
index=Index([2, 3], name=thing2)) | ||
|
||
# use custom label directly | ||
result = df.set_index(thing2) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# custom label wrapped in list | ||
result = df.set_index([thing2]) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# missing key | ||
thing3 = Thing(['Three', 'pink']) | ||
msg = '.*' # due to revert, see GH 25085 | ||
with pytest.raises(KeyError, match=msg): | ||
# missing label directly | ||
df.set_index(thing3) | ||
|
||
with pytest.raises(KeyError, match=msg): | ||
# missing label in list | ||
df.set_index([thing3]) | ||
|
||
def test_set_index_custom_label_type_raises(self): | ||
# GH 24969 | ||
|
||
# purposefully inherit from something unhashable | ||
class Thing(set): | ||
def __init__(self, name, color): | ||
self.name = name | ||
self.color = color | ||
|
||
def __str__(self): | ||
return "<Thing %r>" % (self.name,) | ||
|
||
thing1 = Thing('One', 'red') | ||
thing2 = Thing('Two', 'blue') | ||
df = DataFrame([[0, 2], [1, 3]], columns=[thing1, thing2]) | ||
|
||
msg = 'unhashable type.*' | ||
|
||
with pytest.raises(TypeError, match=msg): | ||
# use custom label directly | ||
df.set_index(thing2) | ||
|
||
with pytest.raises(TypeError, match=msg): | ||
# custom label wrapped in list | ||
df.set_index([thing2]) | ||
|
||
def test_construction_with_categorical_index(self): | ||
ci = tm.makeCategoricalIndex(10) | ||
ci.name = 'B' | ||
|
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.