-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: AssertionError on Series.append(DataFrame) fix #30975 #31036
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 11 commits
7a3b6fe
8ea217f
d522438
b717007
b584b35
1e5e8e7
53f1c11
4e1f6b1
041ed12
721a560
f312bae
a1ebee2
32d2989
87ea2aa
19dcea3
cdf92ae
a747921
a256fe8
14e0fb4
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 | ||||
---|---|---|---|---|---|---|
|
@@ -2539,6 +2539,13 @@ def append(self, to_append, ignore_index=False, verify_integrity=False) -> "Seri | |||||
to_concat.extend(to_append) | ||||||
else: | ||||||
to_concat = [self, to_append] | ||||||
for x in to_concat[1:]: | ||||||
if isinstance(x, (pd.DataFrame,)): | ||||||
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.
Suggested change
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. instead of checking if its a dataframe, would be better to check not an acceptable type, e.g. Series, list-like of Series. 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. IIUC other incorrect types are caught by concat. This PR will be backported so just minimising the changes here to fix the regression (raises AssertionError) for now. 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 catch the AssertionError and raise improved message instead? 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 i would rather not backport this, let's actually fix this properly. 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.
and backport the proper fix? I think we need something backported. to get back to the (dubious) 0.25.3 behaviour could just remove the 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.
ok let's do that then |
||||||
msg = ( | ||||||
f"to_append should be a Series or list/tuple of Series, " | ||||||
f"got {type(to_append).__name__}" | ||||||
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. may make the error message clearer in the case where the sequence contains a DataFame
Suggested change
|
||||||
) | ||||||
raise TypeError(msg) | ||||||
hvardhan20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return self._ensure_type( | ||||||
concat( | ||||||
to_concat, ignore_index=ignore_index, verify_integrity=verify_integrity | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -61,6 +61,18 @@ def test_append_tuples(self): | |||||||||||||
|
||||||||||||||
tm.assert_series_equal(expected, result) | ||||||||||||||
|
||||||||||||||
def test_append_dataframe_raises(self): | ||||||||||||||
hvardhan20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
# GH 30975 | ||||||||||||||
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) | ||||||||||||||
li = [df.B, df] | ||||||||||||||
|
||||||||||||||
msg = "to_append should be a Series or list/tuple of Series, got DataFrame" | ||||||||||||||
with pytest.raises(TypeError, match=msg): | ||||||||||||||
df.A.append(df) | ||||||||||||||
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. also need to add test to check items in a list/tuple 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. Is this an acceptable test case for testing items in sequence?
Suggested change
|
||||||||||||||
msg = "to_append should be a Series or list/tuple of Series, got list" | ||||||||||||||
with pytest.raises(TypeError, match=msg): | ||||||||||||||
df.A.append(li) | ||||||||||||||
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 use just the minimum to invoke TypeError
Suggested change
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
class TestSeriesAppendWithDatetimeIndex: | ||||||||||||||
def test_append(self): | ||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.