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

Can't filter Series with NumPy arrays #14154

Open
2 tasks done
Wainberg opened this issue Feb 1, 2024 · 1 comment · May be fixed by #20431
Open
2 tasks done

Can't filter Series with NumPy arrays #14154

Wainberg opened this issue Feb 1, 2024 · 1 comment · May be fixed by #20431
Labels
A-input-parsing Area: parsing input arguments A-interop-numpy Area: interoperability with NumPy bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@Wainberg
Copy link
Contributor

Wainberg commented Feb 1, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

>>> pl.Series([1]).filter([True])
shape: (1,)
Series: '' [i64]
[
        1
]
>>> pl.Series([1]).filter(pl.Series([True]))
shape: (1,)
Series: '' [i64]
[
        1
]
>>> pl.Series([1]).filter(np.array([True]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "polars/series/series.py", line 3250, in filter
    return self._from_pyseries(self._s.filter(predicate._s))
                                              ^^^^^^^^^^^^
AttributeError: 'numpy.ndarray' object has no attribute '_s'

Log output

No response

Issue description

Filtering a Series with a NumPy array gives an error, even though it works with a list and a Series. DataFrames work in all three cases:

>>> pl.DataFrame([1]).filter([True])
 column_0
 1
shape: (1, 1)
>>> pl.DataFrame([1]).filter(pl.Series([True]))
 column_0
 1
shape: (1, 1)
>>> pl.DataFrame([1]).filter(np.array([True]))
 column_0
 1
shape: (1, 1)

Expected behavior

Filtering with NumPy arrays should work for Series like it works for DataFrames.

Installed versions

--------Version info---------
Polars:               0.20.6
Index type:           UInt32
Platform:             Linux-4.18.0-513.5.1.el8_9.x86_64-x86_64-with-glibc2.28
Python:               3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:03:24) [GCC 12.3.0]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           3.8.2
numpy:                1.26.3
openpyxl:             3.1.2
pandas:               2.2.0
pyarrow:              14.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
xlsx2csv:             0.8.1
xlsxwriter:           3.1.9
@Wainberg Wainberg added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Feb 1, 2024
@stinodego stinodego added P-low Priority: low and removed needs triage Awaiting prioritization by a maintainer labels Feb 1, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Feb 1, 2024
@stinodego
Copy link
Member

This should work and it's already up on my whiteboard 👍

@stinodego stinodego self-assigned this Feb 1, 2024
@stinodego stinodego moved this from Ready to Next in Backlog Feb 1, 2024
@stinodego stinodego added the A-interop-numpy Area: interoperability with NumPy label May 22, 2024
@stinodego stinodego removed their assignment May 22, 2024
@stinodego stinodego added the A-input-parsing Area: parsing input arguments label May 27, 2024
@stinodego stinodego moved this from Next to Ready in Backlog May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-input-parsing Area: parsing input arguments A-interop-numpy Area: interoperability with NumPy bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Status: Ready
Development

Successfully merging a pull request may close this issue.

2 participants