def extract_array(obj: AnyArrayLike, extract_numpy: bool=False) -> ArrayLike:
    "\n    Extract the ndarray or ExtensionArray from a Series or Index.\n\n    For all other types, `obj` is just returned as is.\n\n    Parameters\n    ----------\n    obj : object\n        For Series / Index, the underlying ExtensionArray is unboxed.\n        For Numpy-backed ExtensionArrays, the ndarray is extracted.\n\n    extract_numpy : bool, default False\n        Whether to extract the ndarray from a PandasArray\n\n    Returns\n    -------\n    arr : object\n\n    Examples\n    --------\n    >>> extract_array(pd.Series(['a', 'b', 'c'], dtype='category'))\n    ['a', 'b', 'c']\n    Categories (3, object): ['a', 'b', 'c']\n\n    Other objects like lists, arrays, and DataFrames are just passed through.\n\n    >>> extract_array([1, 2, 3])\n    [1, 2, 3]\n\n    For an ndarray-backed Series / Index a PandasArray is returned.\n\n    >>> extract_array(pd.Series([1, 2, 3]))\n    <PandasArray>\n    [1, 2, 3]\n    Length: 3, dtype: int64\n\n    To extract all the way down to the ndarray, pass ``extract_numpy=True``.\n\n    >>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True)\n    array([1, 2, 3])\n    "
    if isinstance(obj, (ABCIndexClass, ABCSeries)):
        obj = obj.array
    if (extract_numpy and isinstance(obj, ABCPandasArray)):
        obj = obj.to_numpy()
    return obj
Extract the ndarray or ExtensionArray from a Series or Index.

For all other types, `obj` is just returned as is.

Parameters
----------
obj : object
    For Series / Index, the underlying ExtensionArray is unboxed.
    For Numpy-backed ExtensionArrays, the ndarray is extracted.

extract_numpy : bool, default False
    Whether to extract the ndarray from a PandasArray

Returns
-------
arr : object

Examples
--------
>>> extract_array(pd.Series(['a', 'b', 'c'], dtype='category'))
['a', 'b', 'c']
Categories (3, object): ['a', 'b', 'c']

Other objects like lists, arrays, and DataFrames are just passed through.

>>> extract_array([1, 2, 3])
[1, 2, 3]

For an ndarray-backed Series / Index a PandasArray is returned.

>>> extract_array(pd.Series([1, 2, 3]))
<PandasArray>
[1, 2, 3]
Length: 3, dtype: int64

To extract all the way down to the ndarray, pass ``extract_numpy=True``.

>>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True)
array([1, 2, 3])
def extract_array(obj: AnyArrayLike, extract_numpy: bool=False) -> ArrayLike:
    "\n    Extract the ndarray or ExtensionArray from a Series or Index.\n\n    For all other types, `obj` is just returned as is.\n\n    Parameters\n    ----------\n    obj : object\n        For Series / Index, the underlying ExtensionArray is unboxed.\n        For Numpy-backed ExtensionArrays, the ndarray is extracted.\n\n    extract_numpy : bool, default False\n        Whether to extract the ndarray from a PandasArray\n\n    Returns\n    -------\n    arr : object\n\n    Examples\n    --------\n    >>> extract_array(pd.Series(['a', 'b', 'c'], dtype='category'))\n    ['a', 'b', 'c']\n    Categories (3, object): ['a', 'b', 'c']\n\n    Other objects like lists, arrays, and DataFrames are just passed through.\n\n    >>> extract_array([1, 2, 3])\n    [1, 2, 3]\n\n    For an ndarray-backed Series / Index a PandasArray is returned.\n\n    >>> extract_array(pd.Series([1, 2, 3]))\n    <PandasArray>\n    [1, 2, 3]\n    Length: 3, dtype: int64\n\n    To extract all the way down to the ndarray, pass ``extract_numpy=True``.\n\n    >>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True)\n    array([1, 2, 3])\n    "
    if isinstance(obj, (ABCIndexClass, ABCSeries)):
        obj = obj.array
    if (extract_numpy and isinstance(obj, ABCPandasArray)):
        obj = obj.to_numpy()
    return obj