Code Monkey home page Code Monkey logo

Comments (5)

asmeurer avatar asmeurer commented on June 16, 2024

We also have

>>> ndindex(False) == ndindex(0)
False
>>> False == 0
True

because

>>> ndindex(False).raw
array(False)

Not to mention this behavior

>>> ndindex([0, 1]) == np.array([0, 1])
True
>>> np.array([0, 1]) == ndindex([0, 1])
array([False, False])

which we can't do anything about. The best recommendation is to always convert any index object into an ndindex object, and manipulate that, and only use a raw index type (.raw) at the end when you actually index an array.

from ndindex.

asmeurer avatar asmeurer commented on June 16, 2024

Fix at #93

from ndindex.

telamonian avatar telamonian commented on June 16, 2024

Not to mention this behavior

>>> ndindex([0, 1]) == np.array([0, 1])
True
>>> np.array([0, 1]) == ndindex([0, 1])
array([False, False])

@asmeurer In your ideal world, which of the following would be the behavior for ndarray vs NDIndex equality?

A)

ndindex([0, 1]) == np.array([0, 1])
> array([True, True])
np.array([0, 1]) == ndindex([0, 1])
> array([True, True])

or B)

ndindex([0, 1]) == np.array([0, 1])
> True
np.array([0, 1]) == ndindex([0, 1])
> True

Both can be done. I'd argue for A), since that's now the expected behavior for "array-like" objects (as defined by numpy as of 1.17, I think?). B) is also doable, but it will have to have the side-effect that isinstance(ndindex([0, 1]), np.ndarray) is True

from ndindex.

asmeurer avatar asmeurer commented on June 16, 2024

I would prefer it if I could make them both give True. == giving an array makes very basic things like checking if an index is in a list or dictionary difficult, because bool() fails on arrays. And anyway, an ndindex array index object is not an array-like. See https://quansight.github.io/ndindex/type-confusion.html#integerarray-and-booleanarray

from ndindex.

telamonian avatar telamonian commented on June 16, 2024

I opened a new issue for this over at #95. Let's continue the conversation there

from ndindex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.