-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: high memory consumption for unstack #54373
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
Comments
Hm I can't reproduce this. Also on an ARM Mac
Can you provide a simple reproducer? Less columns and without groupby |
@phofl I will try to find a simpler reproducer. May I ask how |
I added one line to activate/deactivate CoW. Otherwise this was copied as is. Examples should always be as simple as possible, e.g. no unnecessary operations. If your problem occurs in unstack, then groupby is unnecessary |
@phofl what about the following code? import pandas as pd
from memory_profiler import profile
@profile
def main():
df = pd.read_parquet("reproducer.parquet")
df.unstack("F")
if __name__ == "__main__":
main() I put reproducer.parquet in archiv.zip.
Still getting huge memory consumption for unstack. |
Nope, still can't reproduce
|
That is strange. What version of Pandas do you use? |
tried on main and 2.0.3 |
Hi @phofl, I tried to reproduce the issue independently, and I think I succeeded. See the following runs in my public repo. Ubuntu: https://github.com/hkad98/pandas-reproducer/actions/runs/5784679774/job/15675843719 Note that both runners use x86 Unstack increment for:
Unfortunately, GitHub does not provide runners with ARM architecture. I tried locally running the same script with Ubuntu + ARM, and the results were the same as Ubuntu with x86. I think that issue is in the combination of macOS13 with ARM. |
Seems like the original issue wasn't directly reproducible so closing. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this issue exists on the latest version of pandas.
I have confirmed this issue exists on the main branch of pandas.
Reproducible Example
I use memory_profiler. Run
mprof run file_name
to measure memory consumption on each line of code.Memory usage for unstack:
I tried to improve memory consumption with the following changes:
category
instead ofstring
pivot_table
instead ofgroupby
+unstack
reset_index
+pivot
instead ofunstack
None of the things above worked.
I tried to turn on CoW, but it made it worse.
I am aware that CoW does not support unstack yet (#49473), but I would not expect that turning it on will make unstack worse.
Installed Versions
INSTALLED VERSIONS
commit : 0f43794
python : 3.10.8.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : None.UTF-8
pandas : 2.0.3
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 63.2.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
Prior Performance
No response
The text was updated successfully, but these errors were encountered: