test_comparison.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import pytest
  2. import pandas as pd
  3. import pandas._testing as tm
  4. from pandas.tests.arrays.masked_shared import (
  5. ComparisonOps,
  6. NumericOps,
  7. )
  8. class TestComparisonOps(NumericOps, ComparisonOps):
  9. @pytest.mark.parametrize("other", [True, False, pd.NA, -1, 0, 1])
  10. def test_scalar(self, other, comparison_op, dtype):
  11. ComparisonOps.test_scalar(self, other, comparison_op, dtype)
  12. def test_compare_to_int(self, dtype, comparison_op):
  13. # GH 28930
  14. op_name = f"__{comparison_op.__name__}__"
  15. s1 = pd.Series([1, None, 3], dtype=dtype)
  16. s2 = pd.Series([1, None, 3], dtype="float")
  17. method = getattr(s1, op_name)
  18. result = method(2)
  19. method = getattr(s2, op_name)
  20. expected = method(2).astype("boolean")
  21. expected[s2.isna()] = pd.NA
  22. tm.assert_series_equal(result, expected)
  23. def test_equals():
  24. # GH-30652
  25. # equals is generally tested in /tests/extension/base/methods, but this
  26. # specifically tests that two arrays of the same class but different dtype
  27. # do not evaluate equal
  28. a1 = pd.array([1, 2, None], dtype="Int64")
  29. a2 = pd.array([1, 2, None], dtype="Int32")
  30. assert a1.equals(a2) is False