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).
(obj, col=None)
| 7 | |
| 8 | |
| 9 | def get_array(obj, col=None): |
| 10 | """ |
| 11 | Helper method to get array for a DataFrame column or a Series. |
| 12 | |
| 13 | Equivalent of df[col].values, but without going through normal getitem, |
| 14 | which triggers tracking references / CoW (and we might be testing that |
| 15 | this is done by some other operation). |
| 16 | """ |
| 17 | if isinstance(obj, Index): |
| 18 | arr = obj._values |
| 19 | elif isinstance(obj, Series) and (col is None or obj.name == col): |
| 20 | arr = obj._values |
| 21 | else: |
| 22 | assert col is not None |
| 23 | icol = obj.columns.get_loc(col) |
| 24 | assert isinstance(icol, int) |
| 25 | arr = obj._get_column_array(icol) |
| 26 | if isinstance(arr, BaseMaskedArray): |
| 27 | return arr._data |
| 28 | elif isinstance(arr, Categorical): |
| 29 | return arr |
| 30 | return getattr(arr, "_ndarray", arr) |
searching dependent graphs…