Skip to content

Add {*Frame,Series,Expr}.drop_nans #3366

@dangotbanned

Description

@dangotbanned

Spotted that I never followed up on (#3031 (comment)), (#3031 (comment)).

I think we can make this easier by introducing drop_nans, aligning our support of {drop,fill}_{nans,nulls}

## What's the difference?
Most data tools except pandas make a clear distinction between:
- Null values, representing missing data.
- NaN values, resulting from "illegal" mathematical operations like `0/0`.
In Narwhals, this is reflected in separate methods for Null/NaN values:
| Operation | Null | NaN |
| --------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| is | [`Expr.is_null`][narwhals.Expr.is_null] | [`Expr.is_nan`][narwhals.Expr.is_nan] |
| fill | [`Expr.fill_null`][narwhals.Expr.fill_null] | [`Expr.fill_nan`][narwhals.Expr.fill_nan] |
| drop | [`Expr.drop_nulls`][narwhals.Expr.drop_nulls] | *Not yet implemented (See [discussion](https://github.com/narwhals-dev/narwhals/issues/3031#issuecomment-3219910366))*<br>[`polars.Expr.drop_nans`](https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.drop_nans.html) |
| count | [`Expr.null_count`][narwhals.Expr.null_count] | *No upstream equivalent* |

The *Frame-level variants seem the most useful for lazy backends, to avoid issues with checking for NaN against a non-float

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions