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

Enable assert_almost_equal to test numpy-like zero-dimensional arrays #54507

Closed
wants to merge 3 commits into from

Conversation

kvn4
Copy link
Contributor

@kvn4 kvn4 commented Aug 11, 2023

@kvn4 kvn4 requested a review from WillAyd as a code owner August 11, 2023 20:13
@@ -24,7 +24,13 @@ from pandas.core.dtypes.missing import array_equivalent


cdef bint isiterable(obj):
return hasattr(obj, "__iter__")
if hasattr(obj, "__iter__"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel ok here?

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 add a comment # GH#54507 here

how does this affect the runtime of the test suite? if its neglible then im fine with it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to affect the runtime of the test suite by much

@gfyoung gfyoung added Enhancement Testing pandas testing functions or related to the test suite Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). labels Aug 17, 2023
@kvn4
Copy link
Contributor Author

kvn4 commented Aug 20, 2023

hi @WillAyd and @jbrockmendel just wanted to bump this in case it got buried. Do you guys want me to make any changes?

"obj",
[
MockNumpyLikeArray(np.ndarray((2,) * 1)),
MockNumpyLikeArray(np.array([])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why isnt this considered iterable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, when I try iterating them:

TypeError                                 Traceback (most recent call last)
----> 1 next(np.ndarray((2,) * 1))

TypeError: 'numpy.ndarray' object is not an iterator

TypeError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 next(np.array([]))

TypeError: 'numpy.ndarray' object is not an iterator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my mistake, they're both iterable:

iter(np.ndarray((2,) * 1))
<iterator at 0x202471fbdf0>

iter(np.array([]))
<iterator at 0x20247252400>

iter(np.array(2))
Cell In[37], line 1
----> 1 iter(np.array(2))

TypeError: iteration over a 0-d array

so those two can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thank you

@pytest.mark.parametrize(
"obj",
[
MockNumpyLikeArray(np.ndarray((2,) * 1)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be np.array instead of np.ndarray? weird way to call the constructor, and the result here also looks iterable

@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 25, 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 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). Stale Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Enable assert_almost_equal to test numpy-like zero-dimensional arrays
6 participants