From ce3617b846463c6071f3e6e5042f025cdec5506b Mon Sep 17 00:00:00 2001 From: Aadharsh Acharya Date: Fri, 22 Apr 2022 09:20:58 -0400 Subject: [PATCH 1/5] TST: GH32822 data types in frame manip --- pandas/tests/frame/test_arithmetic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 7c33242192d2e..7ac1976f6c098 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -2040,3 +2040,13 @@ def _constructor_sliced(self): result = sdf + sdf tm.assert_frame_equal(result, expected) + + +def test_frame_sub_dtype(): + # GH 32822 + s = Series([1, 2, np.nan], dtype='Int64') + t = Series([1, 2, 3], dtype='Int64') + + expected = (s - t).dtype + result = (s.to_frame() - t.to_frame())[0].dtype + assert expected is result From caaddb1fcf05052d3676ff08e8097a25658626f2 Mon Sep 17 00:00:00 2001 From: Aadharsh Acharya Date: Fri, 22 Apr 2022 11:06:59 -0400 Subject: [PATCH 2/5] edited style --- pandas/tests/frame/test_arithmetic.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 7ac1976f6c098..49fe99ae5e6e0 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -2006,6 +2006,15 @@ def test_bool_frame_mult_float(): tm.assert_frame_equal(result, expected) +def test_frame_sub_dtype(): + # GH 32822 + series1 = Series([1, 2, np.nan], dtype="Int64") + series2 = Series([1, 2, 3], dtype="Int64") + expected = DataFrame([0, 0, np.nan], dtype="Int64") + result = (series1.to_frame() - series2.to_frame()) + tm.assert_frame_equal(result, expected) + + def test_frame_op_subclass_nonclass_constructor(): # GH#43201 subclass._constructor is a function, not the subclass itself @@ -2040,13 +2049,3 @@ def _constructor_sliced(self): result = sdf + sdf tm.assert_frame_equal(result, expected) - - -def test_frame_sub_dtype(): - # GH 32822 - s = Series([1, 2, np.nan], dtype='Int64') - t = Series([1, 2, 3], dtype='Int64') - - expected = (s - t).dtype - result = (s.to_frame() - t.to_frame())[0].dtype - assert expected is result From 3bbc5d600d3013f5b97acd81603f66420fad9283 Mon Sep 17 00:00:00 2001 From: Aadharsh Acharya Date: Fri, 22 Apr 2022 11:59:03 -0400 Subject: [PATCH 3/5] parametrize dtype --- pandas/tests/frame/test_arithmetic.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 49fe99ae5e6e0..3bb47db9a3ba3 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -2006,12 +2006,13 @@ def test_bool_frame_mult_float(): tm.assert_frame_equal(result, expected) -def test_frame_sub_dtype(): +@pytest.mark.parametrize("d_type", ['int8', 'int16', 'int32', 'int64']) +def test_frame_sub_dtype(d_type): # GH 32822 - series1 = Series([1, 2, np.nan], dtype="Int64") - series2 = Series([1, 2, 3], dtype="Int64") - expected = DataFrame([0, 0, np.nan], dtype="Int64") - result = (series1.to_frame() - series2.to_frame()) + series1 = Series([1, 2, np.nan], dtype=d_type) + series2 = Series([1, 2, 3], dtype=d_type) + expected = DataFrame([0, 0, np.nan], dtype=d_type) + result = series1.to_frame() - series2.to_frame() tm.assert_frame_equal(result, expected) From b054ea1de6791c60cd8544fbbc20f1103113634f Mon Sep 17 00:00:00 2001 From: Aadharsh Acharya Date: Fri, 22 Apr 2022 15:30:25 -0400 Subject: [PATCH 4/5] fix integration tests --- pandas/tests/frame/test_arithmetic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 3bb47db9a3ba3..80d64f375e1e0 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -2006,7 +2006,7 @@ def test_bool_frame_mult_float(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("d_type", ['int8', 'int16', 'int32', 'int64']) +@pytest.mark.parametrize("d_type", ["int8", "int16", "int32", "int64"]) def test_frame_sub_dtype(d_type): # GH 32822 series1 = Series([1, 2, np.nan], dtype=d_type) From 56f90e455361a98495a536adb7c0dbea768fb3b2 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 3 Jun 2022 10:06:29 -0700 Subject: [PATCH 5/5] Rename test, use any_int_dtype fixture --- pandas/tests/frame/test_arithmetic.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 4b7fbb22e38f3..3adc63e1a27f6 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -2007,12 +2007,11 @@ def test_bool_frame_mult_float(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize("d_type", ["int8", "int16", "int32", "int64"]) -def test_frame_sub_dtype(d_type): +def test_frame_sub_nullable_int(any_int_dtype): # GH 32822 - series1 = Series([1, 2, np.nan], dtype=d_type) - series2 = Series([1, 2, 3], dtype=d_type) - expected = DataFrame([0, 0, np.nan], dtype=d_type) + series1 = Series([1, 2, np.nan], dtype=any_int_dtype) + series2 = Series([1, 2, 3], dtype=any_int_dtype) + expected = DataFrame([0, 0, np.nan], dtype=any_int_dtype) result = series1.to_frame() - series2.to_frame() tm.assert_frame_equal(result, expected)