test_tolist.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import pytest
  2. import pandas.util._test_decorators as td
  3. from pandas import (
  4. Interval,
  5. Period,
  6. Series,
  7. Timedelta,
  8. Timestamp,
  9. )
  10. @pytest.mark.parametrize(
  11. "values, dtype, expected_dtype",
  12. (
  13. ([1], "int64", int),
  14. ([1], "Int64", int),
  15. ([1.0], "float64", float),
  16. ([1.0], "Float64", float),
  17. (["abc"], "object", str),
  18. (["abc"], "string", str),
  19. ([Interval(1, 3)], "interval", Interval),
  20. ([Period("2000-01-01", "D")], "period[D]", Period),
  21. ([Timedelta(days=1)], "timedelta64[ns]", Timedelta),
  22. ([Timestamp("2000-01-01")], "datetime64[ns]", Timestamp),
  23. pytest.param([1], "int64[pyarrow]", int, marks=td.skip_if_no("pyarrow")),
  24. pytest.param([1.0], "float64[pyarrow]", float, marks=td.skip_if_no("pyarrow")),
  25. pytest.param(["abc"], "string[pyarrow]", str, marks=td.skip_if_no("pyarrow")),
  26. ),
  27. )
  28. def test_tolist_scalar_dtype(values, dtype, expected_dtype):
  29. # GH49890
  30. ser = Series(values, dtype=dtype)
  31. result_dtype = type(ser.tolist()[0])
  32. assert result_dtype == expected_dtype