test_npfuncs.py 853 B

12345678910111213141516171819202122232425262728
  1. """
  2. Tests for np.foo applied to DataFrame, not necessarily ufuncs.
  3. """
  4. import numpy as np
  5. from pandas import (
  6. Categorical,
  7. DataFrame,
  8. )
  9. import pandas._testing as tm
  10. class TestAsArray:
  11. def test_asarray_homogenous(self):
  12. df = DataFrame({"A": Categorical([1, 2]), "B": Categorical([1, 2])})
  13. result = np.asarray(df)
  14. # may change from object in the future
  15. expected = np.array([[1, 1], [2, 2]], dtype="object")
  16. tm.assert_numpy_array_equal(result, expected)
  17. def test_np_sqrt(self, float_frame):
  18. with np.errstate(all="ignore"):
  19. result = np.sqrt(float_frame)
  20. assert isinstance(result, type(float_frame))
  21. assert result.index is float_frame.index
  22. assert result.columns is float_frame.columns
  23. tm.assert_frame_equal(result, float_frame.apply(np.sqrt))