Skip to content

BUG: Computing sys.getsizeof a DataFrame with no columns results in an irrelevant FutureWarning #50066

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

Closed
3 tasks done
andrew-benz opened this issue Dec 5, 2022 · 1 comment · Fixed by #50068
Closed
3 tasks done
Labels
Bug DataFrame DataFrame data structure Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@andrew-benz
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

df = pd.DataFrame(
    index=['a', 'b'],
)

sys.getsizeof(df)

Issue Description

The line sys.getsizeof(df) above correctly evaluates to the size of the DataFrame, but it also gives warning:

/tmp/ipykernel_6588/3506259561.py:7: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning.
  sys.getsizeof(df)

I came across this bug while using the package anndata, which facilitates storing metadata for the rows and columns of numpy arrays. This metadata is stored in pandas DataFrames, and it's common to have a metadata DataFrame with only an index and no columns. Hence computing sys.getsizeof() of an anndata.AnnData() object with no metadata for either its rows or columns produces this warning.

Expected Behavior

Calling sys.getsizeof() shouldn't display this irrelevant warning.

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.9.13.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.219-126.411.amzn2.x86_64
Version : #1 SMP Wed Nov 2 17:44:17 UTC 2022
machine : x86_64
processor :
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.2
numpy : 1.23.0
pytz : 2022.1
dateutil : 2.8.2
setuptools : 59.5.0
pip : 22.1.2
Cython : 0.29.30
pytest : 7.1.2
hypothesis : None
sphinx : 5.0.2
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : 2022.11.0
fsspec : 2022.5.0
gcsfs : None
matplotlib : 3.5.2
numba : 0.53.1
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.1
snappy : None
sqlalchemy : 1.4.37
tables : 3.7.0
tabulate : 0.8.10
xarray : None
xlrd : 1.2.0
xlwt : None
zstandard : None
tzdata : None

@andrew-benz andrew-benz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 5, 2022
@MarcoGorelli
Copy link
Member

thanks for the report

this is fine on the main branch, it doesn't raise any warning

if you wanted to dig into where sys.getsizeof goes and silence this warning where appropriate for the next version in the 1.5.x series, that'd be welcome

@phofl phofl added this to the 1.5.3 milestone Dec 5, 2022
@phofl phofl added Regression Functionality that used to work in a prior pandas version DataFrame DataFrame data structure labels Dec 5, 2022
@phofl phofl removed the Needs Triage Issue that has not been reviewed by a pandas team member label Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DataFrame DataFrame data structure Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants