conftest.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import numpy as np
  2. import pytest
  3. import pandas as pd
  4. from pandas.core.arrays.integer import (
  5. Int8Dtype,
  6. Int16Dtype,
  7. Int32Dtype,
  8. Int64Dtype,
  9. UInt8Dtype,
  10. UInt16Dtype,
  11. UInt32Dtype,
  12. UInt64Dtype,
  13. )
  14. @pytest.fixture(
  15. params=[
  16. Int8Dtype,
  17. Int16Dtype,
  18. Int32Dtype,
  19. Int64Dtype,
  20. UInt8Dtype,
  21. UInt16Dtype,
  22. UInt32Dtype,
  23. UInt64Dtype,
  24. ]
  25. )
  26. def dtype(request):
  27. """Parametrized fixture returning integer 'dtype'"""
  28. return request.param()
  29. @pytest.fixture
  30. def data(dtype):
  31. """
  32. Fixture returning 'data' array with valid and missing values according to
  33. parametrized integer 'dtype'.
  34. Used to test dtype conversion with and without missing values.
  35. """
  36. return pd.array(
  37. list(range(8)) + [np.nan] + list(range(10, 98)) + [np.nan] + [99, 100],
  38. dtype=dtype,
  39. )
  40. @pytest.fixture
  41. def data_missing(dtype):
  42. """
  43. Fixture returning array with exactly one NaN and one valid integer,
  44. according to parametrized integer 'dtype'.
  45. Used to test dtype conversion with and without missing values.
  46. """
  47. return pd.array([np.nan, 1], dtype=dtype)
  48. @pytest.fixture(params=["data", "data_missing"])
  49. def all_data(request, data, data_missing):
  50. """Parametrized fixture returning 'data' or 'data_missing' integer arrays.
  51. Used to test dtype conversion with and without missing values.
  52. """
  53. if request.param == "data":
  54. return data
  55. elif request.param == "data_missing":
  56. return data_missing