Skip to content
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

Conversation

ArchPh03nix
Copy link
Contributor

@ArchPh03nix ArchPh03nix commented Aug 16, 2023

@ArchPh03nix
Copy link
Contributor Author

I would like to know if I'm going in the right direction/if the logic needs to be changed

@@ -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():
Copy link
Member

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

def test_array_validate_setitem_value():
# Issue# 51044
arr = pd.Series(range(5)).array
with pytest.raises(TypeError, match="bad"):
Copy link
Member

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

arr = pd.Series(range(5)).array
with pytest.raises(TypeError, match="bad"):
arr._validate_setitem_value("foo")
arr._validate_setitem_value(1.5)
Copy link
Member

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

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()):
Copy link
Member

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


elif kind == "f":
if lib.is_integer(value) or lib.is_float(value):
return value
Copy link
Member

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?

Copy link
Contributor Author

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

@jbrockmendel
Copy link
Member

I would like to know if I'm going in the right direction/if the logic needs to be changed

A bunch of tests are failing on the CI. This is the first place to look for potential problems.

@mroeschke mroeschke added Error Reporting Incorrect or improved errors from pandas ExtensionArray Extending pandas with custom dtypes or arrays. labels Aug 16, 2023
pandas/core/arrays/numpy_.py Outdated Show resolved Hide resolved
pandas/core/arrays/numpy_.py Outdated Show resolved Hide resolved
pandas/core/arrays/numpy_.py Outdated Show resolved Hide resolved
else:
if self.dtype == NumpyEADtype("object") or self.dtype is None:
return value
if NumpyEADtype(type(value)) != self.dtype:

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)

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

@dbalagula
Copy link

Hi @mroeschke are you able to provide any guidance here?

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot added the Stale label Sep 24, 2023
@mroeschke
Copy link
Member

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.

@mroeschke mroeschke closed this Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas ExtensionArray Extending pandas with custom dtypes or arrays. Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: _validate_setitem_value fails to raise for PandasArray
4 participants