Skip to content

ENH: make array_equal+array_equiv work for record arrays/structured arrays - #146

Closed
dhomeier wants to merge 2 commits into
numpy:masterfrom
dhomeier:recarray_eq
Closed

dhomeier wants to merge 2 commits into
numpy:masterfrom
dhomeier:recarray_eq

Conversation

@dhomeier

Copy link
Copy Markdown
Contributor

Derek Homeier added 2 commits August 26, 2011 15:03
Modified array_equiv to consider structured arrays with differently
named fields, but equivalent data, to be equivalent.
@dhomeier

Copy link
Copy Markdown
Contributor Author

That would make the difference between array_equal and array_equiv - but structure array comparison seems to behave similar to both, so maybe it's really a matter of taste:

>>> x = np.array([(0,1),(2,3)], dtype=[('a', 'i4'), ('b', 'i4')])
>>> y = np.array([(0,1),(2,3)], dtype=[('a', 'i4'), ('b', 'i4')]).reshape(1,-1)
>>> x == y
array([[ True,  True]], dtype=bool)

I was not aware that '==' did work already, so maybe most of the array_equal code could simply be replaced by

return bool((a1 == a2).all())

?

@mwiebe

mwiebe commented Sep 1, 2011

Copy link
Copy Markdown
Member

I actually fixed the == in 1.6. It had already been implemented, but incorrectly. I think even just

return (a1 == a2).all()

should be fine, but it's worth having tests which confirm this. One thing to think about for the future, is that I think == for struct dtypes should return a struct dtype with matching names but all 'bool' dtypes, and all() should be extended to reduce the bool-struct to a single value as well... The above line of code would still work correctly with these changes, so that's good.

@charris

charris commented May 3, 2013

Copy link
Copy Markdown
Member

@dhomeier How does this story end?

@charris

charris commented May 13, 2013

Copy link
Copy Markdown
Member

Closed by #3322.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants