-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix combine_first converting timestamp to int #35514
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8a4181d
BUG: fix combine_first converting timestamp to int (#28481)
nixphix 0b938f6
Add whats new entry
nixphix 9f841c9
Uncomment failing test cases
nixphix 115667e
Merge branch 'master' into fix/combine-first
simonjayhawkins a044c2d
Merge branch 'master' into fix/combine-first
nixphix 457a0ab
Fix failing test cases
nixphix 8178c2e
Resolve comments
nixphix 5f22f4d
Merge branch 'master' into fix/combine-first
nixphix 28b61c3
Black format
nixphix 62997c4
Merge branch 'master' into fix/combine-first
nixphix 299ff04
Split test case
nixphix 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 |
---|---|---|
|
@@ -140,9 +140,13 @@ def test_combine_first_mixed_bug(self): | |
) | ||
df2 = DataFrame([[-42.6, np.nan, True], [-5.0, 1.6, False]], index=[1, 2]) | ||
|
||
result = df1.combine_first(df2)[2] | ||
result1 = df1.combine_first(df2)[2] | ||
result2 = df2.combine_first(df1)[2] | ||
# this would fail prior to this fix | ||
nixphix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tm.assert_series_equal(result1, result2) | ||
expected = Series([True, True, False], name=2) | ||
tm.assert_series_equal(result, expected) | ||
# regression | ||
# tm.assert_series_equal(result, expected) | ||
nixphix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# GH 3593, converting datetime64[ns] incorrectly | ||
df0 = DataFrame( | ||
|
@@ -339,9 +343,13 @@ def test_combine_first_int(self): | |
df1 = pd.DataFrame({"a": [0, 1, 3, 5]}, dtype="int64") | ||
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. can you parameterize this as well |
||
df2 = pd.DataFrame({"a": [1, 4]}, dtype="int64") | ||
|
||
res = df1.combine_first(df2) | ||
tm.assert_frame_equal(res, df1) | ||
assert res["a"].dtype == "int64" | ||
res1 = df1.combine_first(df2) | ||
res2 = df1.combine_first(df2) | ||
# this would fail prior to this fix | ||
assert res1["a"].dtype == res2["a"].dtype | ||
nixphix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# regression | ||
# tm.assert_frame_equal(res, df1) | ||
# assert res["a"].dtype == "int64" | ||
|
||
@pytest.mark.parametrize("val", [1, 1.0]) | ||
def test_combine_first_with_asymmetric_other(self, val): | ||
|
@@ -353,3 +361,19 @@ def test_combine_first_with_asymmetric_other(self, val): | |
exp = pd.DataFrame({"isBool": [True], "isNum": [val]}) | ||
|
||
tm.assert_frame_equal(res, exp) | ||
|
||
|
||
@pytest.mark.parametrize("val", [pd.NaT, np.nan, None]) | ||
nixphix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_combine_first_timestamp_bug(val): | ||
nixphix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. can you add a comment here "# GH#35514" |
||
df1 = pd.DataFrame([[val, val]], columns=["a", "b"]) | ||
df2 = pd.DataFrame( | ||
[[datetime(2020, 1, 1), datetime(2020, 1, 2)]], columns=["b", "c"] | ||
) | ||
|
||
res = df1.combine_first(df2) | ||
exp = pd.DataFrame( | ||
[[val, datetime(2020, 1, 1), datetime(2020, 1, 2)]], columns=["a", "b", "c"] | ||
) | ||
|
||
tm.assert_frame_equal(res, exp) |
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.