-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
TST: Isin converted floats unnecessarily to int causing rounding issues #37770
Conversation
pandas/core/algorithms.py
Outdated
# Try finding a dtype which would not change our values | ||
values, _ = maybe_upcast(values, dtype=dtype) | ||
dtype = values.dtype | ||
except (ValueError, TypeError): |
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.
what cases raise?
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.
TypeError
when values is an array with pd.NaT
(test_isin_nan_common_float64
in pandas/tests/indexes/test_base.py
)
ValueError
if values contains strings, which can't be converted to int (test_isin_level_kwarg
in same file for example)
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.
not a big fan of this, can we not be explict here on the dtype checks (as we are elsewhere).?
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 maybe_convert_numeric``` but would have to keep a
try except`` block too. Is there a function I am not aware of to check, if we can convert to numeric from object without try except?
pandas/core/algorithms.py
Outdated
# Try finding a dtype which would not change our values | ||
values, _ = maybe_upcast(values, dtype=dtype) | ||
dtype = values.dtype | ||
except (ValueError, TypeError): |
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.
not a big fan of this, can we not be explict here on the dtype checks (as we are elsewhere).?
The problem I was facing is, that we sometimes get numpy arrays from dtype objects actually containing integers/floats, which we would like to cast to integer to try isin. So we can not really filter for integer dtypes on |
I think a recent PR from @jbrockmendel may have obviated the need for this, but merge master and let's see |
No, |
ive been looking at |
That would work, yes. Will look into this during the weekend |
The one usage of _ensure_data that passed |
� Conflicts: � doc/source/whatsnew/v1.2.0.rst � pandas/core/algorithms.py
Your commit yesterday fixed above cases, so only adding tests here. |
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -801,6 +801,7 @@ Reshaping | |||
- Bug in :func:`merge_ordered` returned wrong join result when length of ``left_by`` or ``right_by`` equals to the rows of ``left`` or ``right`` (:issue:`38166`) | |||
- Bug in :func:`merge_ordered` didn't raise when elements in ``left_by`` or ``right_by`` not exist in ``left`` columns or ``right`` columns (:issue:`38167`) | |||
- Bug in :func:`DataFrame.drop_duplicates` not validating bool dtype for ``ignore_index`` keyword (:issue:`38274`) | |||
- Bug in :meth:`Series.isin` cast ``float`` unnecessarily to ``int`` when :class:`Series` to look in was from dtype ``int`` (:issue:`19356`) |
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.
"cast float
unnecessarily" -> "unnecessarily casting float
dtypes"
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.
probably needs to move to 1.3.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.
I think it makes more sense removing the whatsnew entirely, since your fix went into 1.2. Would be confusing having this in 1.3
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.
LGTM
this might be fixed on master now, can youi revisit |
Yes was fixed by @jbrockmendel, hence only adding tests here |
excellent, thanks @phofl |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff