Contains method is not consistent for subarrays #3016

seberg opened this Issue Feb 25, 2013 · 1 comment


None yet
2 participants

seberg commented Feb 25, 2013

The __contains__ method is written to be used for a single array element. However for example in list of list, __contains__ does a check more equivalent to subarrays. in must return a single boolean. After some discussion on the list, there are three main possibilities:

  1. The first item must be an element. That means that an array a for a in b will normally be a simple error. (As nathaniel mentioned on the list).
  2. Do a list of list like comparison. I.e. in operates on the first dimension.
  3. Do some kind of subarray matching (there are many different versions of this allowing different things)

Point 2. seems wrong, since arrays are not list of lists. Point 3. has some merit, it can go as far as allowing things similar to strings 'a' in 'cat', however there are some problems with the details. Point 1. is the simplest and safest solution. One problem with 2. is that for object arrays it can be not quite clear how to interpret for example a tuple/list.

At this time (there was not much discussion yet though), it seems that the best solution is to just raise an error (i.e. solution 1.). Finding subarrays is better suited for a dedicated function.


charris commented Feb 25, 2013

This might be worth raising on the list.

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