MCPcopy Create free account
hub / github.com/apache/arrow / test_to_pandas_zero_copy

Function test_to_pandas_zero_copy

python/pyarrow/tests/test_array.py:289–315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

287
288@pytest.mark.pandas
289def test_to_pandas_zero_copy():
290 import gc
291
292 arr = pa.array(range(10))
293
294 for i in range(10):
295 series = arr.to_pandas()
296 # In Python 3.14 interpreter might avoid some
297 # reference count modifications
298 assert sys.getrefcount(series) in (1, 2)
299 series = None # noqa
300
301 assert sys.getrefcount(arr) in (1, 2)
302
303 for i in range(10):
304 arr = pa.array(range(10))
305 series = arr.to_pandas()
306 arr = None
307 gc.collect()
308
309 # Ensure base is still valid
310
311 # Because of py.test's assert inspection magic, if you put getrefcount
312 # on the line being examined, it will be 1 higher than you expect
313 base_refcount = sys.getrefcount(series.values.base)
314 assert base_refcount == 2
315 series.sum()
316
317
318@pytest.mark.nopandas

Callers

nothing calls this directly

Calls 2

arrayMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected