-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: Inconsistent behavior of .replace() in Int64 series with NA #38693
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
Conversation
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 @ftrihardjo
def test_replace_int_with_na(self, dtype): | ||
result = pd.Series([0, None]).astype(dtype) |
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.
can you put the issue number as a comment here? see some other tests for an example
@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64']) | ||
def test_replace_int_with_na(self, dtype): | ||
result = pd.Series([0, None]).astype(dtype) | ||
result.replace(0, pd.NA) |
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 you'll want
result = result.replace(0, pd.NA)
result = pd.Series([0, None]).astype(dtype) | ||
result.replace(0, pd.NA) | ||
expected = pd.Series([0, None]).astype(dtype) | ||
expected.fillna(0).replace(0, pd.NA) |
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.
why is this line needed? Just construct expected
directly
.replace()
in Int64 series with <NA>
.
thank you for your review
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
…On Sat, Dec 26, 2020 at 1:09 AM Marco Gorelli ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Thanks @ftrihardjo <https://github.com/ftrihardjo>
------------------------------
In pandas/tests/series/methods/test_replace.py
<#38693 (comment)>:
> + def test_replace_int_with_na(self, dtype):
+ result = pd.Series([0, None]).astype(dtype)
can you put the issue number as a comment here? see some other tests for
an example
------------------------------
In pandas/tests/series/methods/test_replace.py
<#38693 (comment)>:
> @@ -208,6 +208,14 @@ def test_replace_with_dict_with_bool_keys(self):
expected = pd.Series(["yes", False, "yes"])
tm.assert_series_equal(result, expected)
+ @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
+ def test_replace_int_with_na(self, dtype):
+ result = pd.Series([0, None]).astype(dtype)
+ result.replace(0, pd.NA)
I think you'll want
result = result.replace(0, pd.NA)
------------------------------
In pandas/tests/series/methods/test_replace.py
<#38693 (comment)>:
> @@ -208,6 +208,14 @@ def test_replace_with_dict_with_bool_keys(self):
expected = pd.Series(["yes", False, "yes"])
tm.assert_series_equal(result, expected)
+ @pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
+ def test_replace_int_with_na(self, dtype):
+ result = pd.Series([0, None]).astype(dtype)
+ result.replace(0, pd.NA)
+ expected = pd.Series([0, None]).astype(dtype)
+ expected.fillna(0).replace(0, pd.NA)
why is this line needed? Just construct expected directly
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38693 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF2RQQOYKEZAMDBFVPBC7UDSWTILXANCNFSM4VI6XQWA>
.
|
def test_replace_int_with_na(self, dtype): | ||
# GH 38267 | ||
result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) | ||
expected = pd.Series([0, None]).astype(dtype).fillna(0).replace(0, pd.NA) |
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.
Is it possible to construct expected
directly (e.g. expected = pd.Series([pd.NA, pd.NA])
)?
@@ -208,6 +208,13 @@ def test_replace_with_dict_with_bool_keys(self): | |||
expected = pd.Series(["yes", False, "yes"]) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize("dtype", ["int8", "int16", "int32", "int64"]) |
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.
the types need to be capitalised, as in the issue, e.g. Int64
not int64
@@ -208,6 +208,13 @@ def test_replace_with_dict_with_bool_keys(self): | |||
expected = pd.Series(["yes", False, "yes"]) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) | |||
def test_replace_int_with_na(self, dtype): |
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.
should use any_nullable_int_dtype
fixture here
@pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) | ||
def test_replace_int_with_na(self, dtype): | ||
# GH 38267 | ||
result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) |
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.
pass dtype directly to the Series constructor
@@ -208,6 +208,13 @@ def test_replace_with_dict_with_bool_keys(self): | |||
expected = pd.Series(["yes", False, "yes"]) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) | |||
def test_replace_int_with_na(self, dtype): |
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'd call it test_replace_nullable_int_with_na
or test_replace_Int_with_na
def test_replace_int_with_na(self, dtype): | ||
# GH 38267 | ||
result = pd.Series([0, None]).astype(dtype).replace(0, pd.NA) | ||
expected = pd.Series([pd.NA, pd.NA]) |
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.
you also need to pass dtype here else (looking at CI output) this casts to object. That's why currently this test doesn't actually pass
Thanks @ftrihardjo , looks like just #38693 (comment) still needs to be addressed |
@pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) | ||
def test_replace_Int_with_na(self, dtype): | ||
# GH 38267 | ||
result = pd.Series([0, None], dtype=dtype).replace(0, pd.NA) |
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.
can you add the working example as well e.g. 0,1 as another case.
@@ -208,6 +208,13 @@ def test_replace_with_dict_with_bool_keys(self): | |||
expected = pd.Series(["yes", False, "yes"]) | |||
tm.assert_series_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize("dtype", ["Int8", "Int16", "Int32", "Int64"]) |
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.
can you use the fixture: any_nullable_int_dtype instead here.
Hello @ftrihardjo! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-12-28 02:00:00 UTC |
.replace()
in Int64 series with <NA>
.
thanks @ftrihardjo |
.replace()
in Int64 series with<NA>
. #38267black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff