-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Fix infer_dtype result for float with embedded pd.NA #61624
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
Changes from 3 commits
3f1a734
a6b3962
33bd950
ddd7e3b
c35c86d
799d9ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1387,6 +1387,15 @@ def test_infer_dtype_period_with_na(self, na_value): | |||||||||||||||||||||
arr = np.array([na_value, Period("2011-01", freq="D"), na_value]) | ||||||||||||||||||||||
assert lib.infer_dtype(arr, skipna=True) == "period" | ||||||||||||||||||||||
|
||||||||||||||||||||||
@pytest.mark.parametrize("na_value", [pd.NA, np.nan]) | ||||||||||||||||||||||
def test_infer_dtype_numeric_with_na(self, na_value): | ||||||||||||||||||||||
# GH61621 | ||||||||||||||||||||||
arr = Series([1, 2, na_value], dtype=object) | ||||||||||||||||||||||
assert lib.infer_dtype(arr, skipna=True) == "integer" | ||||||||||||||||||||||
|
||||||||||||||||||||||
arr = Series([1.0, 2.0, na_value], dtype=object) | ||||||||||||||||||||||
assert lib.infer_dtype(arr, skipna=True) == "floating" | ||||||||||||||||||||||
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. Nitpick:
Suggested change
Or
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. Agreed - would recommend changing the variable here to 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. Thank you both for your review. I've been missing it. I updated it. (799d9ca) |
||||||||||||||||||||||
|
||||||||||||||||||||||
def test_infer_dtype_all_nan_nat_like(self): | ||||||||||||||||||||||
arr = np.array([np.nan, np.nan]) | ||||||||||||||||||||||
assert lib.infer_dtype(arr, skipna=True) == "floating" | ||||||||||||||||||||||
|
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.
To be sure, this removal is unrelated to the other change here, is that right? That is, we can remove this line on main and it won't break any tests.
Uh oh!
There was an error while loading. Please reload this page.
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.
That's right. I tested it on my forked repo, and all TC passed. (heoh#7)
At the time of writing the commit, I simply judged it as unnecessary code and removed it.
However, after seeing your question, I took a second look at the
convert_dtypes()
function. It exists for theinteger
andboolean
cases as well, and I felt that it was intended to explicitly indicate that theinferred_dtype
is of typestr
.(Previous work: #50094 a4c409e)
Even though the test passes without it, I don't understand pandas well enough yet to anticipate the side effects. For now, I think it's safer to respect the existing code style, so I added it back.(ddd7e3b)
Please feel free to let me know if I need to make any corrections again. Thanks for the review.