-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: astyp via loc to int64 #36942
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
hardikpnsp
wants to merge
4
commits into
pandas-dev:master
from
hardikpnsp:test_astyp_via_loc_to_Int64
Closed
TST: astyp via loc to int64 #36942
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a63365b
TST: astype cast via loc with nan values (#31861)
hardikpnsp 52b7c21
TST: added NA to the astype via loc test (#31861)
hardikpnsp 129b1b5
TST: updated to proper comment and variable name
hardikpnsp 5a993b8
TST: added working conditions for astype via loc (#31861)
hardikpnsp 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import pytest | ||
|
||
from pandas import ( | ||
NA, | ||
Categorical, | ||
CategoricalDtype, | ||
DataFrame, | ||
|
@@ -136,6 +137,34 @@ def test_astype_cast_nan_inf_int(self, val, dtype): | |
with pytest.raises(ValueError, match=msg): | ||
df.astype(dtype) | ||
|
||
@pytest.mark.parametrize("dtype", ["Int64", "Int32", "Int16"]) | ||
@pytest.mark.parametrize("val", [np.nan, NA]) | ||
def test_astype_cast_via_loc_nan_int(self, val, dtype): | ||
# GH31861 | ||
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 the working conditions as well (e.g. nan + a value) from the OP 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. sure! let me try. |
||
expected = DataFrame({"a": ["foo"], "b": integer_array([val], dtype=dtype)}) | ||
df = DataFrame({"a": ["foo"], "b": [val]}) | ||
df.loc[:, "b"] = df.loc[:, "b"].astype(dtype) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
expected2 = DataFrame( | ||
{"a": ["foo", "foo"], "b": integer_array([val, 1.0], dtype=dtype)} | ||
) | ||
df2 = DataFrame({"a": ["foo", "foo"], "b": [val, 1.0]}) | ||
df2.loc[:, "b"] = df2.loc[:, "b"].astype(dtype) | ||
tm.assert_frame_equal(df2, expected2) | ||
|
||
expected3 = DataFrame( | ||
{"a": ["foo", "foo"], "b": integer_array([val, val], dtype=dtype)} | ||
) | ||
df3 = DataFrame({"a": ["foo", "foo"], "b": [val, val]}) | ||
df3.loc[:, "b"] = df3.loc[:, "b"].astype(dtype) | ||
tm.assert_frame_equal(df3, expected3) | ||
|
||
expected4 = DataFrame({"b": integer_array([val], dtype=dtype)}) | ||
df4 = DataFrame({"b": [val]}) | ||
df4.loc[:, "b"] = df4.loc[:, "b"].astype(dtype) | ||
tm.assert_frame_equal(df4, expected4) | ||
|
||
def test_astype_str(self): | ||
# see GH#9757 | ||
a = Series(date_range("2010-01-04", periods=5)) | ||
|
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.
use
nulls_fixture
instead andany_nullable_int_dtype
fixtureThere 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.
@jreback , here in
nulls_fixture
, the test case fails forpd.NaT
because it is inferred asdatetime64
. I think it is expected behavior but would like your opinion on it.code snippet for reference
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.
@arw2019 @jreback , Any updates on this one? would appreciate some help and direction.
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.
Could use
pytest.skipif
for the datetime caseor test for the
TypeError
somehow but I'm not sure that's necessary