1

I am trying to execute the following command:

compare_values =data1.values == data2.values
rows, columns = numpy.where(compare_values == False)

and get validator check:

E712 comparison to False should be 'if cond is False:' or 'if not cond:'

data1 and data2 are of type data frame

rows and columns are arrays.

I tried inserting if statement inside numpy.where() but that does not work.

compare_values =data1.values == data2.values
rows, columns = numpy.where(compare_values == False)

I am getting the following validation check:

E712 comparison to False should be 'if cond is False:' or 'if not cond:'

How to resolve this?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • 1
    Maybe your validator wants `numpy.where(~compare_values)`? Or just create `compare_values` using `!=` instead of `==` in the first place. – Dan Sep 02 '19 at 09:18
  • yes I am looking for elementwise negation to check for True and False. My code is running fime but I get validatior error. @Dan – Siddhesh Shankar Sep 02 '19 at 09:23
  • Probably not a solution to this but in this case I would rather use [numpy.nonzero](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html) instead of numpy.where – Rick M. Sep 02 '19 at 09:27
  • @SiddheshShankar ok... but does `numpy.where(~compare_values)` still give you a validator error? – Dan Sep 02 '19 at 09:28
  • You could also just pass compare_values instead of the condition and it should work – Rick M. Sep 02 '19 at 09:31
  • @RickM. If I just pass compare_values inside the brackets, that does not work – Siddhesh Shankar Sep 02 '19 at 09:41
  • On using the following code :rows, columns = numpy.where(compare_values is False) I get this error: ValueError: not enough values to unpack (expected 2, got 1) – Siddhesh Shankar Sep 02 '19 at 11:41
  • That `E712` is a check against `pep8`, not a Python/numpy error. That's a valid style issue for pure Python, but not for `numpy`. `np.array([False, True,False])==False` perfectly good `numpy`, just as good as the `~`. I've added a better duplicate. – hpaulj Sep 03 '19 at 02:43
  • Keep in mind that the argument to `np.where` (alias `np.nonzero`) is evaluated before being passed to the function. So `compare_values == False` or `~compare_values` has to generate a valid `numpy` boolean array. `data1.values != data2.values` is another way. `np.nonzero` just gives us the indices of the `True` (nonzero) values. – hpaulj Sep 03 '19 at 02:51

0 Answers0