File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change
1
+ import math
1
2
from typing import Any
2
3
3
4
from ..error import INVALID
7
8
8
9
def is_nullish (value : Any ) -> bool :
9
10
"""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 4
4
from graphql .pyutils import is_nullish
5
5
6
6
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
+
7
23
def describe_is_nullish ():
8
24
def null_is_nullish ():
9
25
assert is_nullish (None ) is True
@@ -29,3 +45,6 @@ def undefined_is_nullish():
29
45
30
46
def nan_is_nullish ():
31
47
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