aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pandas/py3/pandas/_testing/compat.py
blob: bb3bb99a4c6e49026080133721efe39df0305e93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Helpers for sharing tests between DataFrame/Series
"""
from pandas._typing import DtypeObj

from pandas import DataFrame


def get_dtype(obj) -> DtypeObj:
    if isinstance(obj, DataFrame):
        # Note: we are assuming only one column
        return obj.dtypes.iat[0]
    else:
        return obj.dtype


def get_obj(df: DataFrame, klass):
    """
    For sharing tests using frame_or_series, either return the DataFrame
    unchanged or return it's first column as a Series.
    """
    if klass is DataFrame:
        return df
    return df._ixs(0, axis=1)