Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Contains method is not consistent for subarrays #3016

seberg opened this Issue · 1 comment

2 participants


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.


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
Something went wrong with that request. Please try again.