test_npfuncs.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """
  2. Tests for np.foo applied to Series, not necessarily ufuncs.
  3. """
  4. import numpy as np
  5. import pytest
  6. import pandas.util._test_decorators as td
  7. from pandas import Series
  8. import pandas._testing as tm
  9. class TestPtp:
  10. def test_ptp(self):
  11. # GH#21614
  12. N = 1000
  13. arr = np.random.default_rng(2).standard_normal(N)
  14. ser = Series(arr)
  15. assert np.ptp(ser) == np.ptp(arr)
  16. def test_numpy_unique(datetime_series):
  17. # it works!
  18. np.unique(datetime_series)
  19. @pytest.mark.parametrize("index", [["a", "b", "c", "d", "e"], None])
  20. def test_numpy_argwhere(index):
  21. # GH#35331
  22. s = Series(range(5), index=index, dtype=np.int64)
  23. result = np.argwhere(s > 2).astype(np.int64)
  24. expected = np.array([[3], [4]], dtype=np.int64)
  25. tm.assert_numpy_array_equal(result, expected)
  26. @td.skip_if_no("pyarrow")
  27. def test_log_arrow_backed_missing_value():
  28. # GH#56285
  29. ser = Series([1, 2, None], dtype="float64[pyarrow]")
  30. result = np.log(ser)
  31. expected = np.log(Series([1, 2, None], dtype="float64"))
  32. tm.assert_series_equal(result, expected)