diff --git a/doc/source/whatsnew/v1.5.3.rst b/doc/source/whatsnew/v1.5.3.rst index e0bcd81805cc1..cf079f43f6457 100644 --- a/doc/source/whatsnew/v1.5.3.rst +++ b/doc/source/whatsnew/v1.5.3.rst @@ -14,6 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ - Fixed performance regression in :meth:`Series.isin` when ``values`` is empty (:issue:`49839`) +- Fixed regression in :meth:`DataFrame.memory_usage` showing unnecessary ``FutureWarning`` when :class:`DataFrame` is empty (:issue:`50066`) - Fixed regression in :meth:`DataFrameGroupBy.transform` when used with ``as_index=False`` (:issue:`49834`) - Enforced reversion of ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` in function :meth:`DataFrame.plot.scatter` (:issue:`49732`) - Fixed regression in :meth:`SeriesGroupBy.apply` setting a ``name`` attribute on the result if the result was a :class:`DataFrame` (:issue:`49907`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 84d45b9e105c2..4bced8f93e3ea 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3552,6 +3552,7 @@ def memory_usage(self, index: bool = True, deep: bool = False) -> Series: result = self._constructor_sliced( [c.memory_usage(index=False, deep=deep) for col, c in self.items()], index=self.columns, + dtype=np.intp, ) if index: index_memory_usage = self._constructor_sliced( diff --git a/pandas/tests/io/formats/test_info.py b/pandas/tests/io/formats/test_info.py index 54b5e699cd034..1657327dd7344 100644 --- a/pandas/tests/io/formats/test_info.py +++ b/pandas/tests/io/formats/test_info.py @@ -20,6 +20,7 @@ date_range, option_context, ) +import pandas._testing as tm @pytest.fixture @@ -491,3 +492,12 @@ def test_info_int_columns(): """ ) assert result == expected + + +def test_memory_usage_empty_no_warning(): + # GH#50066 + df = DataFrame(index=["a", "b"]) + with tm.assert_produces_warning(None): + result = df.memory_usage() + expected = Series(16 if IS64 else 8, index=["Index"]) + tm.assert_series_equal(result, expected)