GeezerVison is showing github.com — Add is_nan aliases (#1643) · apache/datafusion-python@4702915
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: python/datafusion/expr.py +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1226,6 +1226,12 @@ def isnan(self) -> Expr: | 1226 | 1226 |
| 1227 | 1227 | return F.isnan(self) | 1228 | 1228 |
| | 1229 | + def is_nan(self) -> Expr: | | 1230 | + """Returns true if a given number is +NaN or -NaN otherwise returns false.""" | | 1231 | + from . import functions as F | | 1232 | + | | 1233 | + return F.is_nan(self) | | 1234 | + | 1229 | 1235 | def degrees(self) -> Expr: | 1230 | 1236 | """Converts the argument from radians to degrees.""" | 1231 | 1237 | from . import functions as F | |
Collapse file Copy file name to clipboardExpand all lines: python/datafusion/functions/__init__.py +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -217,6 +217,7 @@ def _warn_if_expr_for_literal_arg( | 217 | 217 | "initcap", | 218 | 218 | "inner_product", | 219 | 219 | "instr", | | 220 | + "is_nan", | 220 | 221 | "isnan", | 221 | 222 | "iszero", | 222 | 223 | "lag", | @@ -413,6 +414,11 @@ def isnan(expr: Expr) -> Expr: | 413 | 414 | return Expr(f.isnan(expr.expr)) | 414 | 415 |
| 415 | 416 |
| | 417 | +def is_nan(expr: Expr) -> Expr: | | 418 | + """Alias for :func:`isnan`.""" | | 419 | + return isnan(expr) | | 420 | + | | 421 | + | 416 | 422 | def nullif(expr1: Expr, expr2: Expr) -> Expr: | 417 | 423 | """Returns NULL if expr1 equals expr2; otherwise it returns expr1. | 418 | 424 |
| |
Collapse file Copy file name to clipboardExpand all lines: python/tests/test_expr.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -500,6 +500,11 @@ def test_alias_with_metadata(df): | 500 | 500 | pa.array([False, True, False, None], type=pa.bool_()), | 501 | 501 | id="isnan", | 502 | 502 | ), | | 503 | + pytest.param( | | 504 | + col("e").is_nan(), | | 505 | + pa.array([False, True, False, None], type=pa.bool_()), | | 506 | + id="is_nan", | | 507 | + ), | 503 | 508 | pytest.param( | 504 | 509 | functions.round(col("a").degrees(), lit(4)), | 505 | 510 | pa.array([-42.9718, 28.6479, 0.0, None], type=pa.float64()), | |
Collapse file Copy file name to clipboardExpand all lines: python/tests/test_functions.py +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -215,6 +215,15 @@ def test_math_functions(): | 215 | 215 | ) | 216 | 216 |
| 217 | 217 |
| | 218 | +def test_is_nan_alias(): | | 219 | + ctx = SessionContext() | | 220 | + df = ctx.from_pydict({"value": [1.0, np.nan, None]}) | | 221 | + | | 222 | + result = df.select(f.is_nan(column("value")).alias("is_nan")).to_pydict() | | 223 | + | | 224 | + assert result == {"is_nan": [False, True, None]} | | 225 | + | | 226 | + | 218 | 227 | def py_indexof(arr, v): | 219 | 228 | try: | 220 | 229 | return arr.index(v) + 1 | |
|