From 64ff073e4276b6f4b31e63d81189018d7d3b93a0 Mon Sep 17 00:00:00 2001 From: GrammatikakisDimitris Date: Fri, 7 Apr 2023 21:47:40 +0000 Subject: [PATCH 1/3] Add new test for None values on string columns on a Dataframe --- pandas/tests/frame/test_constructors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index cb61a68200411..711df20e44153 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2698,6 +2698,14 @@ def test_frame_from_dict_with_mixed_tzaware_indexes(self): class TestDataFrameConstructorWithDtypeCoercion: + def test_none_values_on_string_columns(self): + # Creating DataFrame with column "a" as string and a None value + data = {"a": ["1", "2", None]} + df = DataFrame(data=data, dtype="str") + + # Checking that the value of the third row in column "a" is actually None + assert isna(df.loc[2, "a"]) + def test_floating_values_integer_dtype(self): # GH#40110 make DataFrame behavior with arraylike floating data and # inty dtype match Series behavior From 2949932b59cf3bdc4d3975bf54e32148b18cb80c Mon Sep 17 00:00:00 2001 From: GrammatikakisDimitris Date: Sat, 8 Apr 2023 17:16:55 +0000 Subject: [PATCH 2/3] Make changes in test for None values --- pandas/tests/frame/test_constructors.py | 8 -------- pandas/tests/indexing/test_loc.py | 7 +++++++ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 711df20e44153..cb61a68200411 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2698,14 +2698,6 @@ def test_frame_from_dict_with_mixed_tzaware_indexes(self): class TestDataFrameConstructorWithDtypeCoercion: - def test_none_values_on_string_columns(self): - # Creating DataFrame with column "a" as string and a None value - data = {"a": ["1", "2", None]} - df = DataFrame(data=data, dtype="str") - - # Checking that the value of the third row in column "a" is actually None - assert isna(df.loc[2, "a"]) - def test_floating_values_integer_dtype(self): # GH#40110 make DataFrame behavior with arraylike floating data and # inty dtype match Series behavior diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 9b01c6b45918c..8a35cff6d471e 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -62,6 +62,13 @@ def test_not_change_nan_loc(series, new_series, expected_ser): class TestLoc: + def test_none_values_on_string_columns(self): + # Issue #32218 + data = {"a": ["1", "2", None]} + df = DataFrame(data=data, dtype="str") + + assert df.loc[2, "a"] is None + @pytest.mark.parametrize("kind", ["series", "frame"]) def test_loc_getitem_int(self, kind, request): # int label From 99f9ff8c15c2695c4b5a1928d3137cd7cfc7d422 Mon Sep 17 00:00:00 2001 From: GrammatikakisDimitris Date: Sat, 8 Apr 2023 20:27:14 +0000 Subject: [PATCH 3/3] Change the Dataframe in test for None values --- pandas/tests/indexing/test_loc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 8a35cff6d471e..b7b371aad4200 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -64,8 +64,7 @@ def test_not_change_nan_loc(series, new_series, expected_ser): class TestLoc: def test_none_values_on_string_columns(self): # Issue #32218 - data = {"a": ["1", "2", None]} - df = DataFrame(data=data, dtype="str") + df = DataFrame(["1", "2", None], columns=["a"], dtype="str") assert df.loc[2, "a"] is None