conftest.py 909 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import numpy as np
  2. import pytest
  3. from pandas.core.arrays.numpy_ import PandasArray
  4. @pytest.fixture
  5. def allow_in_pandas(monkeypatch):
  6. """
  7. A monkeypatch to tell pandas to let us in.
  8. By default, passing a PandasArray to an index / series / frame
  9. constructor will unbox that PandasArray to an ndarray, and treat
  10. it as a non-EA column. We don't want people using EAs without
  11. reason.
  12. The mechanism for this is a check against ABCPandasArray
  13. in each constructor.
  14. But, for testing, we need to allow them in pandas. So we patch
  15. the _typ of PandasArray, so that we evade the ABCPandasArray
  16. check.
  17. """
  18. with monkeypatch.context() as m:
  19. m.setattr(PandasArray, '_typ', 'extension')
  20. yield
  21. @pytest.fixture
  22. def na_value():
  23. return np.nan
  24. @pytest.fixture
  25. def na_cmp():
  26. def cmp(a, b):
  27. return np.isnan(a) and np.isnan(b)
  28. return cmp