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

ENH: Enable assert_almost_equal to test numpy-like zero-dimensional arrays #48919

Open
1 of 3 tasks
andrewgsavage opened this issue Oct 3, 2022 · 7 comments
Open
1 of 3 tasks
Assignees
Labels
Enhancement Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). Testing pandas testing functions or related to the test suite

Comments

@andrewgsavage
Copy link

andrewgsavage commented Oct 3, 2022

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

is_list_like was updated to return False for scalars of numpy-like array implementations. #35131 This has helped pass more extensionarray in pint-pandas .

Some tests now fail at assert_..._equal instead of at is_list_like, as isiterable in assert_almost_equal recognises pint-pandas' scalar, a Quantity, as iterable since it has an __iter__ method. The Quantity will TypeError since it isn't iterable.

cdef bint isiterable(obj):
    return hasattr(obj, '__iter__')

I've had a go at this #48920

Feature Description

Add a check for ndim == 0, like was done for is_list_like

cdef bint isiterable(obj):
    if hasattr(obj, '__iter__'):
        if hasattr(obj, "ndim") and obj.ndim == 0:
            return False
        return True
    return False

Alternative Solutions

Currently these tests are xpassed.

Additional Context

No response

@andrewgsavage andrewgsavage added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 3, 2022
@lithomas1 lithomas1 added Testing pandas testing functions or related to the test suite Nested Data Data where the values are collections (lists, sets, dicts, objects, etc.). and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 20, 2023
@kvn4
Copy link
Contributor

kvn4 commented Aug 3, 2023

take

@kvn4
Copy link
Contributor

kvn4 commented Aug 3, 2023

Hey @andrewgsavage I am taking this issue. I was wondering why your original CR wasn't accepted. What needed to be changed?

@andrewgsavage
Copy link
Author

I made requested changes and was waiting on review.

@kvn4
Copy link
Contributor

kvn4 commented Aug 7, 2023

@andrewgsavage Did you still want to make the changes and submit another CR? If not, do you mind if I make them for you?

@andrewgsavage
Copy link
Author

andrewgsavage commented Aug 7, 2023 via email

@kvn4
Copy link
Contributor

kvn4 commented Aug 23, 2023

Hi @andrewgsavage, in your test:
(MockNumpyLikeArray(np.ndarray((2,) * 1)), "duck-ndarray-1d"), (MockNumpyLikeArray(np.array([])), "duck-ndarray-1d-empty"),
why aren't these considered iterable?

@andrewgsavage
Copy link
Author

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

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.). Testing pandas testing functions or related to the test suite
Projects
None yet
3 participants