test_comparison.py 1.2 KB

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