-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.append with empty DataFrame and Series with tz-aware datetime value allocated object column #35038
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e20cd55
BUG: DataFrame.append with empty DataFrame and Series with tz-aware d…
simonjayhawkins f762000
Merge remote-tracking branch 'upstream/master' into precursor
simonjayhawkins df2e135
change expected as per comment
simonjayhawkins 5c9619b
Merge remote-tracking branch 'upstream/master' into precursor
simonjayhawkins 20c3c73
extend test
simonjayhawkins a7ee95f
Merge remote-tracking branch 'upstream/master' into precursor
simonjayhawkins 662f7ef
add release note
simonjayhawkins aa08441
Merge remote-tracking branch 'upstream/master' into precursor
simonjayhawkins a45517e
Merge remote-tracking branch 'upstream/master' into precursor
simonjayhawkins 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 |
---|---|---|
|
@@ -1087,20 +1087,27 @@ def test_append_empty_frame_to_series_with_dateutil_tz(self): | |
date = Timestamp("2018-10-24 07:30:00", tz=dateutil.tz.tzutc()) | ||
s = Series({"date": date, "a": 1.0, "b": 2.0}) | ||
df = DataFrame(columns=["c", "d"]) | ||
result = df.append(s, ignore_index=True) | ||
# n.b. it's not clear to me that expected is correct here. | ||
# It's possible that the `date` column should have | ||
# datetime64[ns, tz] dtype for both result and expected. | ||
# that would be more consistent with new columns having | ||
# their own dtype (float for a and b, datetime64ns, tz for date). | ||
result_a = df.append(s, ignore_index=True) | ||
expected = DataFrame( | ||
[[np.nan, np.nan, 1.0, 2.0, date]], | ||
columns=["c", "d", "a", "b", "date"], | ||
dtype=object, | ||
[[np.nan, np.nan, 1.0, 2.0, date]], columns=["c", "d", "a", "b", "date"] | ||
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. does this fully replicate the OP test? 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. extended test |
||
) | ||
# These columns get cast to object after append | ||
expected["a"] = expected["a"].astype(float) | ||
expected["b"] = expected["b"].astype(float) | ||
expected["c"] = expected["c"].astype(object) | ||
expected["d"] = expected["d"].astype(object) | ||
tm.assert_frame_equal(result_a, expected) | ||
|
||
expected = DataFrame( | ||
[[np.nan, np.nan, 1.0, 2.0, date]] * 2, columns=["c", "d", "a", "b", "date"] | ||
) | ||
expected["c"] = expected["c"].astype(object) | ||
expected["d"] = expected["d"].astype(object) | ||
|
||
result_b = result_a.append(s, ignore_index=True) | ||
tm.assert_frame_equal(result_b, expected) | ||
|
||
# column order is different | ||
expected = expected[["c", "d", "date", "a", "b"]] | ||
result = df.append([s, s], ignore_index=True) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
|
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.
@simonjayhawkins do you remember why is was needed to add this
axis=0
?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.
see #35032 (comment)