Files
anders 16c54c6653 Tilføjet venv med docling og afhængigheder
Testfiler opdelt i PNG og previews
2026-10-27 12:20:23 +01:00

27 lines
865 B
Python

import pandas as pd
from pandas.core.arrays import BaseMaskedArray
def get_array(obj, col=None):
"""
Helper method to get array for a DataFrame column or a Series.
Equivalent of df[col].values, but without going through normal getitem,
which triggers tracking references / CoW (and we might be testing that
this is done by some other operation).
"""
if isinstance(obj, pd.Index):
arr = obj._values
elif isinstance(obj, pd.Series) and (col is None or obj.name == col):
arr = obj._values
else:
assert col is not None
icol = obj.columns.get_loc(col)
assert isinstance(icol, int)
arr = obj._get_column_array(icol)
if isinstance(arr, BaseMaskedArray):
return arr._data
elif isinstance(arr, pd.Categorical):
return arr
return getattr(arr, "_ndarray", arr)