Repository: pandas-dev/pandas
File: pandas/tests/series/test_arithmetic.py (Python)

Code before:

    @pytest.mark.parametrize("val", [3, 3.5])
    def test_add_list_to_masked_array(self, val):
        # GH#22962, behavior changed by GH#62552
        ser = Series([1, None, 3], dtype="Int64")
        result = ser + [1, None, val]  # noqa: RUF005
        expected = Series([2, pd.NA, 3 + val], dtype="Float64")
        tm.assert_series_equal(result, expected)

        result = [1, None, val] + ser  # noqa: RUF005
        tm.assert_series_equal(result, expected)

    def test_add_list_to_masked_array_boolean(self):
        # GH#22962
        ser = Series([True, None, False], dtype="boolean")
        result = ser + [True, None, True]  # noqa: RUF005
        expected = Series([2, pd.NA, 1], dtype=object)
        tm.assert_series_equal(result, expected)

        result = [True, None, True] + ser  # noqa: RUF005
        tm.assert_series_equal(result, expected)

    def test_subtraction_index_name_type_mismatch_regression(self):
        # GH#57524
        s1 = Series([1, 2], index=Index([0, 1], name="a"))
        s2 = Series([1, 1], index=Index([0, 1], name=0))

        result = s1 - s2
        expected = Series([0, 1], index=s1.index)

        tm.assert_series_equal(result, expected)


# ------------------------------------------------------------------
# Comparisons


class TestSeriesFlexComparison:
    @pytest.mark.parametrize("axis", [0, None, "index"])
    def test_comparison_flex_basic(self, axis, comparison_op):
        left = Series(np.random.default_rng(2).standard_normal(10))
        right = Series(np.random.default_rng(2).standard_normal(10))
        result = getattr(left, comparison_op.__name__)(right, axis=axis)
        expected = comparison_op(left, right)
        tm.assert_series_equal(result, expected)

    def test_comparison_bad_axis(self, comparison_op):
        left = Series(np.random.default_rng(2).standard_normal(10))
        right = Series(np.random.default_rng(2).standard_normal(10))

        msg = "No axis named 1 for object type"

Review comment (suggestion):
These series do not have the same `dtype` as the original issue

Code after:

    @pytest.mark.parametrize("val", [3, 3.5])
    def test_add_list_to_masked_array(self, val):
        # GH#22962, behavior changed by GH#62552
        ser = Series([1, None, 3], dtype="Int64")
        result = ser + [1, None, val]  # noqa: RUF005
        expected = Series([2, pd.NA, 3 + val], dtype="Float64")
        tm.assert_series_equal(result, expected)

        result = [1, None, val] + ser  # noqa: RUF005
        tm.assert_series_equal(result, expected)

    def test_add_list_to_masked_array_boolean(self):
        # GH#22962
        ser = Series([True, None, False], dtype="boolean")
        result = ser + [True, None, True]  # noqa: RUF005
        expected = Series([2, pd.NA, 1], dtype=object)
        tm.assert_series_equal(result, expected)

        result = [True, None, True] + ser  # noqa: RUF005
        tm.assert_series_equal(result, expected)

    def test_subtraction_index_name_type_mismatch_regression(self):
        # GH#57524
        s1 = Series(
            [23, 22, 21],
            index=Index(["a", "b", "c"], name="index a"),
            dtype="Int64",
        )
        s2 = Series(
            [21, 22, 23],
            index=Index(
                ["a", "b", "c"],
                name="index b",
                dtype="string",
            ),
            dtype="Int64",
        )

        result = s1 - s2
        expected = Series([2, 0, -2], index=s1.index, dtype="Int64")

        tm.assert_series_equal(result, expected)


# ------------------------------------------------------------------
# Comparisons


class TestSeriesFlexComparison:
    @pytest.mark.parametrize("axis", [0, None, "index"])