-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7a3b6fe
GH 30975-Fix for Series.append(DataFrame)
hvardhan20 8ea217f
GH 30975-Fix for Series.append(DataFrame)
hvardhan20 d522438
GH 30975-Fix for Series.append(DataFrame) PEP-8 compliant
hvardhan20 b717007
GH 30975-Fix for Series.append(DataFrame) Adding TypeError Testcase
hvardhan20 b584b35
GH 30975-Fix for Series.append(DataFrame) Modified
hvardhan20 1e5e8e7
GH 30975-Fix for Series.append(DataFrame) Doc Build Fix
hvardhan20 53f1c11
GH 31087 Updates ggpy reference to plotnine
hvardhan20 4e1f6b1
Revert "GH 31087 Updates ggpy reference to plotnine"
hvardhan20 041ed12
Revert "GH 31087 Updates ggpy reference to plotnine"
hvardhan20 721a560
GH 30975-Fix for Series.append(DataFrame) Simple message change
hvardhan20 f312bae
GH 30975-Fix for Series.append(DataFrame) Simple message test change
hvardhan20 a1ebee2
GH 30975-Fix for Series.append(DataFrame) Removed self._ensure_type
hvardhan20 32d2989
GH 30975-Fix for Series.append(DataFrame) Removed self._ensure_type r…
hvardhan20 87ea2aa
GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour
hvardhan20 19dcea3
GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typ…
hvardhan20 cdf92ae
GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typ…
hvardhan20 a747921
GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typ…
hvardhan20 a256fe8
GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typ…
hvardhan20 14e0fb4
GH 30975-Fix for Series.append(DataFrame) 0.25.3 behaviour return typ…
hvardhan20 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
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -61,6 +61,20 @@ def test_append_tuples(self): | |||||||||||||
|
||||||||||||||
tm.assert_series_equal(expected, result) | ||||||||||||||
|
||||||||||||||
def test_append_dataframe(self): | ||||||||||||||
hvardhan20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
# GH 30975 | ||||||||||||||
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]}) | ||||||||||||||
df2 = pd.DataFrame({"C": [5, 6], "D": [7, 8]}) | ||||||||||||||
|
||||||||||||||
expected = pd.Series(pd.concat([df.A, df2.D])) | ||||||||||||||
result = df.A.append(df2.D) | ||||||||||||||
hvardhan20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
|
||||||||||||||
tm.assert_series_equal(expected, result) | ||||||||||||||
hvardhan20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
|
||||||||||||||
msg = "to_append should be a Series or list/tuple of Series, got " \ | ||||||||||||||
"<class 'pandas.core.frame.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
|
||||||||||||||
|
||||||||||||||
class TestSeriesAppendWithDatetimeIndex: | ||||||||||||||
def test_append(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.
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.
I think should allow a Series to be appended to a subclassed Series
also need to move the check into above condition to check the items of a sequence
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.
or instead of inside the else, loop over to_concat[1:] outside the else
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.
Thanks for the hint @simonjayhawkins.
Could you please suggest the better way to do this between the following 2 ways:
1)
Both go after the else. The problem with 2nd way is we cannot get the type of the sequence element which raises the Error. If there's a better way to do this, please do share.
Thanks!
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.
Test case test_concatlike_same_dtypes is failing in pipeline, which is testing the appending of various data types and expecting to catch and raise a TypeError in Concatenator constructor.
With
if not isinstance(x, Series):
to_append will catch & raise TypeError for all data types.Hence test_concatlike_same_dtypes is failing.
I think we should consider the following change:
What are your thoughts on this?
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.
IIUC correctly from the issue the behaviour of adding a DataFrame needs to be revisited, so I agree that maybe checking for a DataFrame maybe better than checking for not a Series.
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.
I prefer the simple loop of step 1 (fails faster) and the simplicity of message 2.