File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1+ import math
12from typing import Any
23
34from ..error import INVALID
78
89def is_nullish (value : Any ) -> bool :
910 """Return true if a value is null, undefined, or NaN."""
10- return value is None or value is INVALID or value != value
11+ return (
12+ value is None
13+ or value is INVALID
14+ or (isinstance (value , float ) and math .isnan (value ))
15+ )
Original file line number Diff line number Diff line change 44from graphql .pyutils import is_nullish
55
66
7+ class FakeNumpyArray :
8+ def __eq__ (self , other ):
9+ # Numpy arrays return an array when compared with another numpy array
10+ # containing the pointwise equality of the two
11+ if isinstance (other , FakeNumpyArray ):
12+ return FakeNumpyArray ()
13+ else :
14+ return False
15+
16+ def __bool__ (self ):
17+ raise TypeError (
18+ "The truth value of an array with more than one element is "
19+ "ambiguous. Use a.any() or a.all()"
20+ )
21+
22+
723def describe_is_nullish ():
824 def null_is_nullish ():
925 assert is_nullish (None ) is True
@@ -29,3 +45,6 @@ def undefined_is_nullish():
2945
3046 def nan_is_nullish ():
3147 assert is_nullish (nan )
48+
49+ def numpy_arrays_are_not_nullish ():
50+ assert is_nullish (FakeNumpyArray ()) is False
You can’t perform that action at this time.
0 commit comments