-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: _validate_setitem_value fails to raise for PandasArray #51044 #54575
BUG: _validate_setitem_value fails to raise for PandasArray #51044 #54575
Conversation
I would like to know if I'm going in the right direction/if the logic needs to be changed |
pandas/tests/arrays/test_array.py
Outdated
@@ -444,3 +444,11 @@ def test_array_to_numpy_na(): | |||
result = arr.to_numpy(na_value=True, dtype=bool) | |||
expected = np.array([True, True]) | |||
tm.assert_numpy_array_equal(result, expected) | |||
|
|||
|
|||
def test_array_validate_setitem_value(): |
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.
this can go in tests.arrays.numpy_.test_numpy.py
pandas/tests/arrays/test_array.py
Outdated
def test_array_validate_setitem_value(): | ||
# Issue# 51044 | ||
arr = pd.Series(range(5)).array | ||
with pytest.raises(TypeError, match="bad"): |
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 pytest.raises around each of the bad calls below. otherwise when the first one raises, the second one doesnt get tested
pandas/tests/arrays/test_array.py
Outdated
arr = pd.Series(range(5)).array | ||
with pytest.raises(TypeError, match="bad"): | ||
arr._validate_setitem_value("foo") | ||
arr._validate_setitem_value(1.5) |
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 test that 1.5 doesn't raise on float/complex-dtype
pandas/core/arrays/numpy_.py
Outdated
if lib.is_integer(value) or lib.is_float(value): | ||
return value | ||
else: | ||
if lib.is_integer(value) or (lib.is_float(value) and value.is_integer()): |
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.
this is only for integer-dtype. also you'll need to check itemsize to be sure it fits. there is probably something in core.dtypes.cast (maybe np_can_hold_element?) that can be reused here
pandas/core/arrays/numpy_.py
Outdated
|
||
elif kind == "f": | ||
if lib.is_integer(value) or lib.is_float(value): | ||
return value |
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.
these checks are correct for scalar value, not sure if validate_setitem_value needs to handle listlike?
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 TypeError still occurs if listlike values are entered in to validate causing tests to fail, even if it's supposed to work, see pandas/tests/arrays/numpy_/test_numpy.py test_ufunc_unary
A bunch of tests are failing on the CI. This is the first place to look for potential problems. |
pandas/core/arrays/numpy_.py
Outdated
else: | ||
if self.dtype == NumpyEADtype("object") or self.dtype is None: | ||
return value | ||
if NumpyEADtype(type(value)) != 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 think you can just add a check for NumpyEADtype(type(value)) == self.dtype
as an or
when you do NumpyEADtype(type(value)) == NumpyEADtype(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.
Then you can just raise a TypeError without any more checks
Hi @mroeschke are you able to provide any guidance here? |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen. |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.