Skip to content

Commit 2b42ea0

Browse files
Move test, sort whatsnew
1 parent 50322fe commit 2b42ea0

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

doc/source/whatsnew/v3.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ Performance improvements
332332
- Performance improvement in :meth:`Index.take` when ``indices`` is a full range indexer from zero to length of index (:issue:`56806`)
333333
- Performance improvement in :meth:`Index.to_frame` returning a :class:`RangeIndex` columns of a :class:`Index` when possible. (:issue:`58018`)
334334
- Performance improvement in :meth:`MultiIndex.equals` for equal length indexes (:issue:`56990`)
335+
- Performance improvement in :meth:`MultiIndex.memory_usage` to ignore the index engine when it isn't already cached. (:issue:`58385`)
335336
- Performance improvement in :meth:`RangeIndex.__getitem__` with a boolean mask or integers returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57588`)
336337
- Performance improvement in :meth:`RangeIndex.append` when appending the same index (:issue:`57252`)
337338
- Performance improvement in :meth:`RangeIndex.argmin` and :meth:`RangeIndex.argmax` (:issue:`57823`)
@@ -345,7 +346,6 @@ Performance improvements
345346
- Performance improvement in ``DataFrameGroupBy.__len__`` and ``SeriesGroupBy.__len__`` (:issue:`57595`)
346347
- Performance improvement in indexing operations for string dtypes (:issue:`56997`)
347348
- Performance improvement in unary methods on a :class:`RangeIndex` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57825`)
348-
- Performance improvement in :meth:`MultiIndex.memory_usage` to ignore the index engine when it isn't already cached. (:issue:`58385`)
349349

350350
.. ---------------------------------------------------------------------------
351351
.. _whatsnew_300.bug_fixes:

pandas/tests/base/test_misc.py

-25
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,6 @@ def test_memory_usage_components_narrow_series(any_real_numpy_dtype):
142142
assert total_usage == non_index_usage + index_usage
143143

144144

145-
def test_memory_usage_doesnt_trigger_engine(index):
146-
index._cache.clear()
147-
assert "_engine" not in index._cache
148-
149-
res_without_engine = index.memory_usage()
150-
assert "_engine" not in index._cache
151-
152-
# explicitly load and cache the engine
153-
_ = index._engine
154-
assert "_engine" in index._cache
155-
156-
res_with_engine = index.memory_usage()
157-
158-
# the engine doesn't affect the result even when initialized with values, because
159-
# index._engine.sizeof() doesn't consider the content of index._engine.values
160-
assert res_with_engine == res_without_engine
161-
162-
if len(index) == 0:
163-
assert res_without_engine == 0
164-
assert res_with_engine == 0
165-
else:
166-
assert res_without_engine > 0
167-
assert res_with_engine > 0
168-
169-
170145
def test_searchsorted(request, index_or_series_obj):
171146
# numpy.searchsorted calls obj.searchsorted under the hood.
172147
# See gh-12238

pandas/tests/indexes/test_old_base.py

+24
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,30 @@ def test_memory_usage(self, index):
326326
if index.inferred_type == "object":
327327
assert result3 > result2
328328

329+
def test_memory_usage_doesnt_trigger_engine(self, index):
330+
index._cache.clear()
331+
assert "_engine" not in index._cache
332+
333+
res_without_engine = index.memory_usage()
334+
assert "_engine" not in index._cache
335+
336+
# explicitly load and cache the engine
337+
_ = index._engine
338+
assert "_engine" in index._cache
339+
340+
res_with_engine = index.memory_usage()
341+
342+
# the empty engine doesn't affect the result even when initialized with values,
343+
# because engine.sizeof() doesn't consider the content of engine.values
344+
assert res_with_engine == res_without_engine
345+
346+
if len(index) == 0:
347+
assert res_without_engine == 0
348+
assert res_with_engine == 0
349+
else:
350+
assert res_without_engine > 0
351+
assert res_with_engine > 0
352+
329353
def test_argsort(self, index):
330354
if isinstance(index, CategoricalIndex):
331355
pytest.skip(f"{type(self).__name__} separately tested")

0 commit comments

Comments
 (0)