Skip to content

Commit

Permalink
refactor(bigquery): remove zeroifnull
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `zeroifnull` is removed; use `fillna(0)` instead
  • Loading branch information
cpcloud authored and gforsyth committed Dec 19, 2023
1 parent 22e5ada commit 8be3c25
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 33 deletions.
16 changes: 5 additions & 11 deletions ibis/backends/impala/tests/test_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def test_builtins(con, alltypes):
i4 % 10,
20 % i1,
d % 5,
pytest.warns(FutureWarning, i1.zeroifnull),
pytest.warns(FutureWarning, i4.zeroifnull),
pytest.warns(FutureWarning, i8.zeroifnull),
i1.fillna(0),
i4.fillna(0),
i8.fillna(0),
i4.to_timestamp("s"),
i4.to_timestamp("ms"),
i4.to_timestamp("us"),
Expand All @@ -72,8 +72,7 @@ def test_builtins(con, alltypes):
d.log2(),
d.log10(),
d.notnull(),
pytest.warns(FutureWarning, d.zeroifnull),
pytest.warns(FutureWarning, d.nullifzero),
d.nullif(0),
d.round(),
d.round(2),
d.round(i1),
Expand All @@ -86,7 +85,6 @@ def test_builtins(con, alltypes):
i8.convert_base(10, 2),
s.convert_base(10, 2),
d.sqrt(),
pytest.warns(FutureWarning, d.zeroifnull),
# nullif cases
5 / i1.nullif(0),
5 / i1.nullif(i4),
Expand Down Expand Up @@ -265,11 +263,7 @@ def approx_equal(a, b, eps):
pytest.param(lambda dc: dc.log2(), "2.39094", id="log2"),
pytest.param(lambda dc: dc.log10(), "0.71975", id="log10"),
pytest.param(lambda dc: dc.sqrt(), "2.29019", id="sqrt"),
pytest.param(
lambda dc: pytest.warns(FutureWarning, dc.zeroifnull),
"5.245",
id="zeroifnull",
),
pytest.param(lambda dc: dc.fillna(0), "5.245", id="zero_ifnull"),
pytest.param(lambda dc: -dc, "-5.245", id="neg"),
],
)
Expand Down
5 changes: 1 addition & 4 deletions ibis/backends/impala/tests/test_unary_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def table(mockcon):
lambda x: pytest.warns(FutureWarning, lambda y: y.nullifzero(), x),
id="nullifzero",
),
param(
lambda x: pytest.warns(FutureWarning, lambda y: y.zeroifnull(), x),
id="zeroifnull",
),
param(lambda x: x.fillna(0), id="zero_ifnull"),
],
)
@pytest.mark.parametrize("cname", ["double_col", "int_col"])
Expand Down
13 changes: 5 additions & 8 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,16 +703,13 @@ def test_logical_negation_column(backend, alltypes, df, op):
("dtype", "zero", "expected"),
[("int64", 0, 1), ("float64", 0.0, 1.0)],
)
def test_zeroifnull_literals(con, dtype, zero, expected):
with pytest.warns(FutureWarning):
assert con.execute(ibis.NA.cast(dtype).zeroifnull()) == zero
with pytest.warns(FutureWarning):
assert con.execute(ibis.literal(expected, type=dtype).zeroifnull()) == expected
def test_zero_ifnull_literals(con, dtype, zero, expected):
assert con.execute(ibis.NA.cast(dtype).fillna(0)) == zero
assert con.execute(ibis.literal(expected, type=dtype).fillna(0)) == expected


def test_zeroifnull_column(backend, alltypes, df):
with pytest.warns(FutureWarning):
expr = alltypes.int_col.nullif(1).zeroifnull().name("tmp")
def test_zero_ifnull_column(backend, alltypes, df):
expr = alltypes.int_col.nullif(1).fillna(0).name("tmp")
result = expr.execute().astype("int32")
expected = df.int_col.replace(1, 0).rename("tmp").astype("int32")
backend.assert_series_equal(result, expected)
Expand Down
5 changes: 0 additions & 5 deletions ibis/expr/types/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,6 @@ def nullifzero(self) -> NumericValue:
"""DEPRECATED: Use `nullif(0)` instead."""
return self.nullif(0)

@util.deprecated(instead="use fillna(0)", as_of="7.0", removed_in="8.0")
def zeroifnull(self) -> NumericValue:
"""DEPRECATED: Use `fillna(0)` instead."""
return self.fillna(0)

def acos(self) -> NumericValue:
"""Compute the arc cosine of `self`.
Expand Down
8 changes: 3 additions & 5 deletions ibis/tests/expr/test_sql_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ def test_group_concat(functional_alltypes):
assert op.where is None


def test_zeroifnull(functional_alltypes):
with pytest.warns(FutureWarning):
dresult = functional_alltypes.double_col.zeroifnull()
def test_zero_ifnull(functional_alltypes):
dresult = functional_alltypes.double_col.fillna(0)

with pytest.warns(FutureWarning):
iresult = functional_alltypes.int_col.zeroifnull()
iresult = functional_alltypes.int_col.fillna(0)

assert type(dresult.op()) == ops.Coalesce
assert type(dresult) == ir.FloatingColumn
Expand Down

0 comments on commit 8be3c25

Please sign in to comment.