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

include_index ignored in pl.from_pandas(pd.Series) #18859

Open
2 tasks done
gab23r opened this issue Sep 23, 2024 · 0 comments
Open
2 tasks done

include_index ignored in pl.from_pandas(pd.Series) #18859

gab23r opened this issue Sep 23, 2024 · 0 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@gab23r
Copy link
Contributor

gab23r commented Sep 23, 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

pd_series = pd.Series({"a": 1, "b":2}, name = "number").rename_axis(["letter"])
pd_series
# letter
# a    1
# b    2
# Name: number, dtype: int64

pl.from_pandas(pd_series, include_index=True)
shape: (2,)
# shape: (2,)
# Series: 'number' [i64]
# [
# 	1
# 	2
# ]

Log output

No response

Issue description

include_index is ignored if data is a pd.Series.
I think we should reset the index in pandas before converting to polars (or at least warn the user the include_index is ignored if a series is passed)

it is all in python, if the new behaviour is accepted, I can propose a PR.

Expected behavior

I would expect: pl.from_pandas(pd_series.reset_index()) to match pl.from_pandas(pd_series, include_index=True)

pl.from_pandas(pd_series.reset_index())
# shape: (2, 2)
# ┌────────┬────────┐
# │ letter ┆ number │
# │ ---    ┆ ---    │
# │ str    ┆ i64    │
# ╞════════╪════════╡
# │ a      ┆ 1      │
# │ b      ┆ 2      │
# └────────┴────────┘

Installed versions

--------Version info---------
Polars:              1.7.1
Index type:          UInt32
Platform:            macOS-14.1.1-x86_64-i386-64bit
Python:              3.11.6 (v3.11.6:8b6ee5ba3b, Oct  2 2023, 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         <not installed>
numpy                2.1.1
openpyxl             <not installed>
pandas               2.2.3
pyarrow              <not installed>
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>```

</details>
@gab23r gab23r added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 23, 2024
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

No branches or pull requests

1 participant