-
Notifications
You must be signed in to change notification settings - Fork 4
ndarray deep comparison fix. #13
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
base: main
Are you sure you want to change the base?
Conversation
…d python complained about their truth 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.
Pull Request Overview
This PR introduces a fix for deep comparison of numpy ndarrays with object dtype in the set_attributes_all function. The standard np.array_equal function doesn't handle nested ndarrays (object arrays containing ndarrays) properly, so this change implements a custom deep comparison function.
Key changes:
- Added new
deep_array_equalfunction for robust comparison of object arrays containing ndarrays - Updated
set_attributes_allto use the new deep comparison function instead ofnp.array_equal
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| This is a more robust version of np.array_equal that works for object arrays | ||
| that contain ndarrays. | ||
| """ | ||
| if isinstance(a, np.ndarray) and isinstance(b, np.ndarray) and (a.dtype == object or b.dtype == object): |
Copilot
AI
Aug 13, 2025
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 condition should check that both arrays have object dtype, not just one of them. Using or could lead to incorrect comparisons when one array is object dtype and the other isn't. Consider changing to a.dtype == object and b.dtype == object
| if isinstance(a, np.ndarray) and isinstance(b, np.ndarray) and (a.dtype == object or b.dtype == object): | |
| if isinstance(a, np.ndarray) and isinstance(b, np.ndarray) and (a.dtype == object and b.dtype == object): |
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 don't believe we want this, as comparisons can still be valid even if only one is an object.
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 this shouldn't matter either way, since if one is an object and the other isn't then the existing np.array_equal should do the right thing and return false.
|
So, there's a couple of things:
|
jclds139
left a comment
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.
Would need test cases and probably some kind of safeguard to prevent recursion loops, otherwise ready. See previous comment on whether or not we should just kick this upstream.
Need to decide whether to keep this PR or not before worrying about updating.
This just changes the np.array_equal to a new version that works for ndarrays of ndarrays (object dtype) in set_attribute_all.
All tests pass, though this should probably have a new test to prevent regressions.