Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions ibis/expr/tests/test_newrels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,3 +1861,32 @@ def test_analytic_dereference():
assert expr.op().predicates == (
ops.Equals(ops.WindowFunction(ops.RowNumber()), ops.Literal(5, dtype="int8")),
)


def test_drop_null_schema_change():
orig_schema = ibis.schema({"a": "int64", "b": "string", "c": "!float64"})
t = ibis.table(orig_schema)

expr = t.drop_null()
expected_schema = ibis.schema({"a": "!int64", "b": "!string", "c": "!float64"})
assert expr.schema() == expected_schema

expr = t.drop_null("a")
expected_schema = ibis.schema({"a": "!int64", "b": "string", "c": "!float64"})
assert expr.schema() == expected_schema

expr = t.drop_null(["a", "c"])
expected_schema = ibis.schema({"a": "!int64", "b": "string", "c": "!float64"})
assert expr.schema() == expected_schema

expr = t.drop_null(how="all")
expected_schema = orig_schema
assert expr.schema() == expected_schema

expr = t.drop_null("a", how="all")
expected_schema = orig_schema
assert expr.schema() == expected_schema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might have misunderstood, but is this particular test right? if we drop nulls only in column "a", then "a" should be not null, even if how="all" is specified?


expr = t.drop_null(["a", "c"], how="all")
expected_schema = orig_schema
assert expr.schema() == expected_schema
14 changes: 11 additions & 3 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3061,9 +3061,17 @@ def drop_null(
│ 344 │
└─────┘
"""
if subset is not None:
subset = tuple(self.bind(subset))
return ops.DropNull(self, how, subset).to_expr()
subset_columns = None if subset is not None else tuple(self.bind(subset))
result = ops.DropNull(self, how, subset_columns).to_expr()
if how == "any":
# We now know that all columns in `subset` are non-nullable
schema = self.schema()
subset_names = (
schema.names if subset is None else util.promote_tuple(subset)
)
new_types = {col: schema[col].copy(nullable=False) for col in subset_names}
result = result.cast(new_types)
return result

def fill_null(self, replacements: ir.Scalar | Mapping[str, ir.Scalar], /) -> Table:
"""Fill null values in a table expression.
Expand Down
Loading