Skip to content

Commit e0b111b

Browse files
authored
REGR: memory_usage showing unnecessary FutureWarning (#50068)
1 parent 0ad74d7 commit e0b111b

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v1.5.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ including other versions of pandas.
1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
1616
- Fixed performance regression in :meth:`Series.isin` when ``values`` is empty (:issue:`49839`)
17+
- Fixed regression in :meth:`DataFrame.memory_usage` showing unnecessary ``FutureWarning`` when :class:`DataFrame` is empty (:issue:`50066`)
1718
- Fixed regression in :meth:`DataFrameGroupBy.transform` when used with ``as_index=False`` (:issue:`49834`)
1819
- Enforced reversion of ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` in function :meth:`DataFrame.plot.scatter` (:issue:`49732`)
1920
- Fixed regression in :meth:`SeriesGroupBy.apply` setting a ``name`` attribute on the result if the result was a :class:`DataFrame` (:issue:`49907`)

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,7 @@ def memory_usage(self, index: bool = True, deep: bool = False) -> Series:
35613561
result = self._constructor_sliced(
35623562
[c.memory_usage(index=False, deep=deep) for col, c in self.items()],
35633563
index=self.columns,
3564+
dtype=np.intp,
35643565
)
35653566
if index:
35663567
index_memory_usage = self._constructor_sliced(

pandas/tests/io/formats/test_info.py

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
date_range,
2121
option_context,
2222
)
23+
import pandas._testing as tm
2324

2425

2526
@pytest.fixture
@@ -491,3 +492,12 @@ def test_info_int_columns():
491492
"""
492493
)
493494
assert result == expected
495+
496+
497+
def test_memory_usage_empty_no_warning():
498+
# GH#50066
499+
df = DataFrame(index=["a", "b"])
500+
with tm.assert_produces_warning(None):
501+
result = df.memory_usage()
502+
expected = Series(16 if IS64 else 8, index=["Index"])
503+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)