PERF: memory usage discrepancy pandas
vs psutil
#52329
Labels
Arrow
pyarrow functionality
Performance
Memory or execution speed performance
Strings
String extension data type and string data
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'm trying to measure Pandas dataframe memory usage with
string[pyarrow]
vsobject
. While.memory_usage(deep=True)
showsstring[pyarrow]
occupying less memory thanobject
, the results are very different when measuring memory usage withpsutil
. Repro script:This produces the following output:
pandas
tells me thatstring[pyarrow]
Series consumes 56Mb of memory, whilepsutil
reports increase of 117Mb.With
object
dtype,pandas
andpsutil
memory usage is very close. But if not all strings in my dataset are unique, the picture is different:Nothing changed with
string[pyarrow]
.pandas
still reports 2x less memory usage thanpsutil
.With
object
,pandas
now tells me that memory usage is 106Mb, whilepsutil
sees only a 34Mb increase, and only 7Mb is released aftergc.collect()
.What is going on here, and how can I explain these results?
I saw these as well, they are possibly related:
Installed Versions
INSTALLED VERSIONS
commit : c2a7f1a
python : 3.11.0.final.0
python-bits : 64
OS : Darwin
OS-release : 22.4.0
Version : Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:58 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.0rc1
numpy : 1.24.2
pytz : 2023.2
dateutil : 2.8.2
setuptools : 67.6.0
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.11.0
pandas_datareader: None
bs4 : 4.12.0
bottleneck : None
brotli :
fastparquet : None
fsspec : 2023.3.0
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2023.3.0
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : None
qtpy : None
pyqt5 : None
Prior Performance
No response
The text was updated successfully, but these errors were encountered: