conftest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import numpy as np
  2. import pytest
  3. import pandas as pd
  4. from pandas.core.arrays.floating import (
  5. Float32Dtype,
  6. Float64Dtype,
  7. )
  8. @pytest.fixture(params=[Float32Dtype, Float64Dtype])
  9. def dtype(request):
  10. """Parametrized fixture returning a float 'dtype'"""
  11. return request.param()
  12. @pytest.fixture
  13. def data(dtype):
  14. """Fixture returning 'data' array according to parametrized float 'dtype'"""
  15. return pd.array(
  16. list(np.arange(0.1, 0.9, 0.1))
  17. + [pd.NA]
  18. + list(np.arange(1, 9.8, 0.1))
  19. + [pd.NA]
  20. + [9.9, 10.0],
  21. dtype=dtype,
  22. )
  23. @pytest.fixture
  24. def data_missing(dtype):
  25. """
  26. Fixture returning array with missing data according to parametrized float
  27. 'dtype'.
  28. """
  29. return pd.array([np.nan, 0.1], dtype=dtype)
  30. @pytest.fixture(params=["data", "data_missing"])
  31. def all_data(request, data, data_missing):
  32. """Parametrized fixture returning 'data' or 'data_missing' float arrays.
  33. Used to test dtype conversion with and without missing values.
  34. """
  35. if request.param == "data":
  36. return data
  37. elif request.param == "data_missing":
  38. return data_missing