@@ -835,56 +835,6 @@ def if_absent(self, default_value: Expression | CONSTANT_TYPE) -> "Expression":
835835 [self , self ._cast_to_expr_or_convert_to_constant (default_value )],
836836 )
837837
838- @expose_as_static
839- def is_nan (self ) -> "BooleanExpression" :
840- """Creates an expression that checks if this expression evaluates to 'NaN' (Not a Number).
841-
842- Example:
843- >>> # Check if the result of a calculation is NaN
844- >>> Field.of("value").divide(0).is_nan()
845-
846- Returns:
847- A new `Expression` representing the 'isNaN' check.
848- """
849- return BooleanExpression ("is_nan" , [self ])
850-
851- @expose_as_static
852- def is_not_nan (self ) -> "BooleanExpression" :
853- """Creates an expression that checks if this expression evaluates to a non-'NaN' (Not a Number) value.
854-
855- Example:
856- >>> # Check if the result of a calculation is not NaN
857- >>> Field.of("value").divide(1).is_not_nan()
858-
859- Returns:
860- A new `Expression` representing the 'is not NaN' check.
861- """
862- return BooleanExpression ("is_not_nan" , [self ])
863-
864- @expose_as_static
865- def is_null (self ) -> "BooleanExpression" :
866- """Creates an expression that checks if the value of a field is 'Null'.
867-
868- Example:
869- >>> Field.of("value").is_null()
870-
871- Returns:
872- A new `Expression` representing the 'isNull' check.
873- """
874- return BooleanExpression ("is_null" , [self ])
875-
876- @expose_as_static
877- def is_not_null (self ) -> "BooleanExpression" :
878- """Creates an expression that checks if the value of a field is not 'Null'.
879-
880- Example:
881- >>> Field.of("value").is_not_null()
882-
883- Returns:
884- A new `Expression` representing the 'isNotNull' check.
885- """
886- return BooleanExpression ("is_not_null" , [self ])
887-
888838 @expose_as_static
889839 def is_error (self ):
890840 """Creates an expression that checks if a given expression produces an error
@@ -1672,7 +1622,10 @@ def of(value: CONSTANT_TYPE) -> Constant[CONSTANT_TYPE]:
16721622 return Constant (value )
16731623
16741624 def __repr__ (self ):
1675- return f"Constant.of({ self .value !r} )"
1625+ value_str = repr (self .value )
1626+ if isinstance (self .value , float ) and value_str == "nan" :
1627+ value_str = "math.nan"
1628+ return f"Constant.of({ value_str } )"
16761629
16771630 def __hash__ (self ):
16781631 return hash (self .value )
@@ -1846,13 +1799,13 @@ def _from_query_filter_pb(filter_pb, client):
18461799 elif isinstance (filter_pb , Query_pb .UnaryFilter ):
18471800 field = Field .of (filter_pb .field .field_path )
18481801 if filter_pb .op == Query_pb .UnaryFilter .Operator .IS_NAN :
1849- return And (field .exists (), field .is_nan ( ))
1802+ return And (field .exists (), field .equal ( float ( "nan" ) ))
18501803 elif filter_pb .op == Query_pb .UnaryFilter .Operator .IS_NOT_NAN :
1851- return And (field .exists (), field .is_not_nan ( ))
1804+ return And (field .exists (), Not ( field .equal ( float ( "nan" )) ))
18521805 elif filter_pb .op == Query_pb .UnaryFilter .Operator .IS_NULL :
1853- return And (field .exists (), field .is_null ( ))
1806+ return And (field .exists (), field .equal ( None ))
18541807 elif filter_pb .op == Query_pb .UnaryFilter .Operator .IS_NOT_NULL :
1855- return And (field .exists (), field .is_not_null ( ))
1808+ return And (field .exists (), Not ( field .equal ( None ) ))
18561809 else :
18571810 raise TypeError (f"Unexpected UnaryFilter operator type: { filter_pb .op } " )
18581811 elif isinstance (filter_pb , Query_pb .FieldFilter ):
0 commit comments