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

Cannot initialize series with empty 2D numpy array #18369

Open
2 tasks done
Oreilles opened this issue Aug 26, 2024 · 1 comment
Open
2 tasks done

Cannot initialize series with empty 2D numpy array #18369

Oreilles opened this issue Aug 26, 2024 · 1 comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@Oreilles
Copy link

Oreilles commented Aug 26, 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

data = np.array([], dtype="2f")
# array([], shape=(0, 2), dtype=float32)

pl.Series(data)

Log output

No response

Issue description

Trying to create a Series from a empty numpy 2D array results in InvalidOperationError: cannot reshape empty array into shape (0, 2).

This kinda looks like #16522, but I believe is a different bug since the error message differs.

Expected behavior

The Series creation should succeed, resulting in an empty series with matching type (in that example, pl.Array(pl.Float64, 2) )

Installed versions

--------Version info---------
Polars:               1.4.1
Index type:           UInt32
Platform:             macOS-14.5-arm64-arm-64bit
Python:               3.12.5 (main, Aug  6 2024, 19:08:49) [Clang 15.0.0 (clang-1500.3.9.4)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         1.6.0
numpy:                2.0.1
openpyxl:             <not installed>
pandas:               2.2.2
pyarrow:              17.0.0
pydantic:             2.8.2
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@Oreilles Oreilles added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Aug 26, 2024
@hexane360
Copy link

As of Polars 1.9.0 this is fixed:

>>> pl.Series(np.array([], dtype="2f"))
shape: (0,)
Series: '' [array[f32, 2]]
[
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@hexane360 @Oreilles and others