Skip to content

Commit 52bf3ca

Browse files
MAINT: apply ruff/Pycodestyle rule E711
E711 Comparison to `None` should be `cond is None`
1 parent 563ec5b commit 52bf3ca

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

numpy/_core/tests/test_numeric.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,12 +2201,12 @@ def test_array_equal_different_scalar_types(self):
22012201

22022202
def test_none_compares_elementwise(self):
22032203
a = np.array([None, 1, None], dtype=object)
2204-
assert_equal(a == None, [True, False, True])
2205-
assert_equal(a != None, [False, True, False])
2204+
assert_equal(a == None, [True, False, True]) # noqa: E711
2205+
assert_equal(a != None, [False, True, False]) # noqa: E711
22062206

22072207
a = np.ones(3)
2208-
assert_equal(a == None, [False, False, False])
2209-
assert_equal(a != None, [True, True, True])
2208+
assert_equal(a == None, [False, False, False]) # noqa: E711
2209+
assert_equal(a != None, [True, True, True]) # noqa: E711
22102210

22112211
def test_array_equiv(self):
22122212
res = np.array_equiv(np.array([1, 2]), np.array([1, 2]))

numpy/_core/tests/test_regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,9 +2313,9 @@ def test_correct_hash_dict(self):
23132313
try:
23142314
hash(val)
23152315
except TypeError as e:
2316-
assert_equal(t.__hash__, None)
2316+
assert_(t.__hash__ is None)
23172317
else:
2318-
assert_(t.__hash__ != None)
2318+
assert_(t.__hash__ is not None)
23192319

23202320
def test_scalar_copy(self):
23212321
scalar_types = set(np._core.sctypeDict.values())

numpy/_core/tests/test_scalarmath.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,15 @@ def test_scalar_comparison_to_none(self):
588588
# The comparisons are flagged by pep8, ignore that.
589589
with warnings.catch_warnings(record=True) as w:
590590
warnings.filterwarnings('always', '', FutureWarning)
591-
assert_(not np.float32(1) == None)
592-
assert_(not np.str_('test') == None)
591+
assert_(not np.float32(1) == None) # noqa: E711
592+
assert_(not np.str_('test') == None) # noqa: E711
593593
# This is dubious (see below):
594-
assert_(not np.datetime64('NaT') == None)
594+
assert_(not np.datetime64('NaT') == None) # noqa: E711
595595

596-
assert_(np.float32(1) != None)
597-
assert_(np.str_('test') != None)
596+
assert_(np.float32(1) != None) # noqa: E711
597+
assert_(np.str_('test') != None) # noqa: E711
598598
# This is dubious (see below):
599-
assert_(np.datetime64('NaT') != None)
599+
assert_(np.datetime64('NaT') != None) # noqa: E711
600600
assert_(len(w) == 0)
601601

602602
# For documentation purposes, this is why the datetime is dubious.

numpy/lib/tests/test_polynomial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ def test_zero_poly_dtype(self):
265265
def test_poly_eq(self):
266266
p = np.poly1d([1, 2, 3])
267267
p2 = np.poly1d([1, 2, 4])
268-
assert_equal(p == None, False)
269-
assert_equal(p != None, True)
268+
assert_equal(p == None, False) # noqa: E711
269+
assert_equal(p != None, True) # noqa: E711
270270
assert_equal(p == p, True)
271271
assert_equal(p == p2, False)
272272
assert_equal(p != p2, True)

numpy/ma/tests/test_core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,20 +1868,20 @@ def test_eq_with_None(self):
18681868
with suppress_warnings() as sup:
18691869
sup.filter(FutureWarning, "Comparison to `None`")
18701870
a = array([None, 1], mask=[0, 1])
1871-
assert_equal(a == None, array([True, False], mask=[0, 1]))
1872-
assert_equal(a.data == None, [True, False])
1873-
assert_equal(a != None, array([False, True], mask=[0, 1]))
1871+
assert_equal(a == None, array([True, False], mask=[0, 1])) # noqa: E711
1872+
assert_equal(a.data == None, [True, False]) # noqa: E711
1873+
assert_equal(a != None, array([False, True], mask=[0, 1])) # noqa: E711
18741874
# With nomask
18751875
a = array([None, 1], mask=False)
1876-
assert_equal(a == None, [True, False])
1877-
assert_equal(a != None, [False, True])
1876+
assert_equal(a == None, [True, False]) # noqa: E711
1877+
assert_equal(a != None, [False, True]) # noqa: E711
18781878
# With complete mask
18791879
a = array([None, 2], mask=True)
1880-
assert_equal(a == None, array([False, True], mask=True))
1881-
assert_equal(a != None, array([True, False], mask=True))
1880+
assert_equal(a == None, array([False, True], mask=True)) # noqa: E711
1881+
assert_equal(a != None, array([True, False], mask=True)) # noqa: E711
18821882
# Fully masked, even comparison to None should return "masked"
18831883
a = masked
1884-
assert_equal(a == None, masked)
1884+
assert_equal(a == None, masked) # noqa: E711
18851885

18861886
def test_eq_with_scalar(self):
18871887
a = array(1)

0 commit comments

Comments
 (0)