Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill_null doesn't work after using numpy ufunc #7091

Closed
2 tasks done
alexanderpils opened this issue Feb 22, 2023 · 0 comments · Fixed by #7092
Closed
2 tasks done

fill_null doesn't work after using numpy ufunc #7091

alexanderpils opened this issue Feb 22, 2023 · 0 comments · Fixed by #7092
Labels
bug Something isn't working python Related to Python Polars

Comments

@alexanderpils
Copy link

alexanderpils commented Feb 22, 2023

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

After using a numpy functions on an expression you can't use fill_null because of a SchemaError despite matching dtypes. You can make it work if you cast the expression to the same dtype again.

Reproducible example

import polars as pl
import numpy as np

df = pl.DataFrame({"a": [None,2,3,4,5,]})

df.with_columns(np.exp(pl.col("a")).fill_null(pl.lit(1, pl.Float64)))


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.local/lib/python3.10/site-packages/polars/internals/dataframe/frame.py", line 6022, in with_columns
    self.lazy()
  File "/home/.local/lib/python3.10/site-packages/polars/internals/lazyframe/frame.py", line 1148, in collect
    return pli.wrap_df(ldf.collect())
exceptions.SchemaError: Cannot 'fill_null' a 'Series' of dtype: 'f64' with an argument of dtype: 'f64'

Expected behavior

df.with_columns(np.exp(pl.col("a")).fill_null(pl.lit(1, pl.Float64)))

should not return an error and result in the same as

df.with_columns(np.exp(pl.col("a")).cast(pl.Float64).fill_null(pl.lit(1, pl.Float64)))

shape: (5, 1)
┌────────────┐
│ a          │
│ ---        │
│ f64        │
╞════════════╡
│ 1.0        │
│ 7.389056   │
│ 20.085537  │
│ 54.59815   │
│ 148.413159 │
└────────────┘

Installed versions

---Version info---
Polars: 0.16.7
Index type: UInt32
Platform: Linux-5.19.0-32-generic-x86_64-with-glibc2.35
Python: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
---Optional dependencies---
pyarrow: <not installed>
pandas: <not installed>
numpy: 1.24.2
fsspec: <not installed>
connectorx: <not installed>
xlsx2csv: <not installed>
deltalake: <not installed>
matplotlib: <not installed>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant