compat.py 658 B

1234567891011121314151617181920212223242526272829
  1. """
  2. Helpers for sharing tests between DataFrame/Series
  3. """
  4. from __future__ import annotations
  5. from typing import TYPE_CHECKING
  6. from pandas import DataFrame
  7. if TYPE_CHECKING:
  8. from pandas._typing import DtypeObj
  9. def get_dtype(obj) -> DtypeObj:
  10. if isinstance(obj, DataFrame):
  11. # Note: we are assuming only one column
  12. return obj.dtypes.iat[0]
  13. else:
  14. return obj.dtype
  15. def get_obj(df: DataFrame, klass):
  16. """
  17. For sharing tests using frame_or_series, either return the DataFrame
  18. unchanged or return it's first column as a Series.
  19. """
  20. if klass is DataFrame:
  21. return df
  22. return df._ixs(0, axis=1)