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

DataFrame rename method is extremely slow for dictionary argument #17336

Closed
2 tasks done
etrotta opened this issue Jul 1, 2024 · 0 comments · Fixed by #18890
Closed
2 tasks done

DataFrame rename method is extremely slow for dictionary argument #17336

etrotta opened this issue Jul 1, 2024 · 0 comments · Fixed by #18890
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer performance Performance issues or improvements python Related to Python Polars

Comments

@etrotta
Copy link
Contributor

etrotta commented Jul 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

import time
import polars as pl
df = pl.DataFrame({f"column_{i}": ['x', 'y', 'z'] for i in range(100_000)})
cols_map = {f"column_{i}": f"renamed_{i}" for i in range(100_000)}
start = time.perf_counter()
_ = df.rename(cols_map)
end = time.perf_counter()
print(f"Time for rename(): {end - start} | Version: {pl.__version__}")

Time for rename(): 117.57077859994024 | Version: 1.0.0

Log output

No response

Issue description

The example code takes around two minutes to run, tested in versions 0.20.31 and 1.0.0

Expected behavior

It shouldn't be that slow.
Passing a function is much faster, even lambda col: cols_map.get(col, col):

import time
import polars as pl
df = pl.DataFrame({f"column_{i}": ['x', 'y', 'z'] for i in range(100_000)})
cols_map = {f"column_{i}": f"renamed_{i}" for i in range(100_000)}
start = time.perf_counter()
_ = df.rename(lambda col: cols_map.get(col, col))
end = time.perf_counter()
print(f"Time for rename(): {end - start} | Version: {pl.__version__}")

Time for rename(): 0.4511210999917239 | Version: 1.0.0

Installed versions

--------Version info---------
Polars:               1.0.0
Index type:           UInt32
Platform:             Windows-11-10.0.22631-SP0
Python:               3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            0.9.0
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           3.8.2
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             3.1.2
pandas:               2.2.2
pyarrow:              15.0.0
pydantic:             2.5.2
pyiceberg:            <not installed>
sqlalchemy:           2.0.29
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@etrotta etrotta added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jul 1, 2024
@stinodego stinodego added the performance Performance issues or improvements label Jul 1, 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 performance Performance issues or improvements python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants