From e559a1b35cf9ed3c70e7416414452d09d744a2a2 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Sat, 16 Nov 2024 10:25:45 -0500 Subject: [PATCH 1/9] TST (string dtype): resolve xfails for frame methods --- pandas/core/frame.py | 4 ++++ pandas/core/internals/blocks.py | 3 ++- pandas/tests/frame/methods/test_astype.py | 11 ++--------- pandas/tests/frame/methods/test_combine_first.py | 7 +------ pandas/tests/frame/methods/test_cov_corr.py | 7 +------ pandas/tests/frame/methods/test_dropna.py | 6 +----- pandas/tests/frame/methods/test_dtypes.py | 8 +------- pandas/tests/frame/methods/test_interpolate.py | 1 - pandas/tests/frame/methods/test_reset_index.py | 3 --- pandas/tests/frame/methods/test_to_dict_of_blocks.py | 3 --- 10 files changed, 12 insertions(+), 41 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 34b448a0d8d1c..bef474b949094 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6273,6 +6273,10 @@ class max type else: to_insert = ((self.index, None),) + if len(new_obj.columns) == 0 and names: + target_dtype = Index(names).dtype + new_obj.columns = new_obj.columns.astype(target_dtype) + multi_col = isinstance(self.columns, MultiIndex) for j, (lev, lab) in enumerate(to_insert, start=1): i = self.index.nlevels - j diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index f44ad926dda5c..639d5a410213f 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2361,5 +2361,6 @@ def external_values(values: ArrayLike) -> ArrayLike: values.flags.writeable = False # TODO(CoW) we should also mark our ExtensionArrays as read-only - + if isinstance(values, ExtensionArray): + ... # this is why test_to_dict_of_blocks_item_cache fails return values diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index ab3743283ea13..b3fe7460d2da9 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -3,8 +3,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - import pandas.util._test_decorators as td import pandas as pd @@ -745,7 +743,6 @@ def test_astype_tz_object_conversion(self, tz): result = result.astype({"tz": "datetime64[ns, Europe/London]"}) tm.assert_frame_equal(result, expected) - @pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_astype_dt64_to_string( self, frame_or_series, tz_naive_fixture, using_infer_string ): @@ -767,13 +764,9 @@ def test_astype_dt64_to_string( if frame_or_series is DataFrame: item = item.iloc[0] if using_infer_string: - assert item is np.nan - else: assert item is pd.NA - - # For non-NA values, we should match what we get for non-EA str - alt = obj.astype(str) - assert np.all(alt.iloc[1:] == result.iloc[1:]) + else: + assert item is np.nan def test_astype_td64_to_string(self, frame_or_series): # GH#41409 diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index 87b7d5052a345..210394e33bd3b 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -3,8 +3,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas.core.dtypes.cast import find_common_type from pandas.core.dtypes.common import is_dtype_equal @@ -32,7 +30,6 @@ def test_combine_first_mixed(self): combined = f.combine_first(g) tm.assert_frame_equal(combined, exp) - @pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_combine_first(self, float_frame, using_infer_string): # disjoint head, tail = float_frame[:5], float_frame[5:] @@ -79,9 +76,7 @@ def test_combine_first(self, float_frame, using_infer_string): tm.assert_series_equal(combined["A"].reindex(g.index), g["A"]) # corner cases - warning = FutureWarning if using_infer_string else None - with tm.assert_produces_warning(warning, match="empty entries"): - comb = float_frame.combine_first(DataFrame()) + comb = float_frame.combine_first(DataFrame()) tm.assert_frame_equal(comb, float_frame) comb = DataFrame().combine_first(float_frame) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index c15952339ef18..02e0932eaaf82 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - import pandas.util._test_decorators as td import pandas as pd @@ -320,7 +318,6 @@ def test_corrwith_non_timeseries_data(self): for row in index[:4]: tm.assert_almost_equal(correls[row], df1.loc[row].corr(df2.loc[row])) - @pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_corrwith_with_objects(self, using_infer_string): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), @@ -334,9 +331,7 @@ def test_corrwith_with_objects(self, using_infer_string): df2["obj"] = "bar" if using_infer_string: - import pyarrow as pa - - with pytest.raises(pa.lib.ArrowNotImplementedError, match="has no kernel"): + with pytest.raises(TypeError, match="Cannot perform reduction"): df1.corrwith(df2) else: with pytest.raises(TypeError, match="Could not convert"): diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 4a60dc09cfe07..7da4149bd4ca8 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -4,8 +4,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - import pandas as pd from pandas import ( DataFrame, @@ -184,13 +182,11 @@ def test_dropna_multiple_axes(self): with pytest.raises(TypeError, match="supplying multiple axes"): inp.dropna(how="all", axis=(0, 1), inplace=True) - @pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_dropna_tz_aware_datetime(self): # GH13407 - df = DataFrame() dt1 = datetime.datetime(2015, 1, 1, tzinfo=dateutil.tz.tzutc()) dt2 = datetime.datetime(2015, 2, 2, tzinfo=dateutil.tz.tzutc()) - df["Time"] = [dt1] + df = DataFrame({"Time": [dt1]}) result = df.dropna(axis=0) expected = DataFrame({"Time": [dt1]}) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_dtypes.py b/pandas/tests/frame/methods/test_dtypes.py index 1685f9ee331f5..dd8afccf2e25c 100644 --- a/pandas/tests/frame/methods/test_dtypes.py +++ b/pandas/tests/frame/methods/test_dtypes.py @@ -3,8 +3,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas.core.dtypes.dtypes import DatetimeTZDtype import pandas as pd @@ -135,13 +133,9 @@ def test_dtypes_timedeltas(self): ) tm.assert_series_equal(result, expected) - @pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_frame_apply_np_array_return_type(self, using_infer_string): # GH 35517 df = DataFrame([["foo"]]) result = df.apply(lambda col: np.array("bar")) - if using_infer_string: - expected = Series([np.array(["bar"])]) - else: - expected = Series(["bar"]) + expected = Series(np.array(["bar"]), dtype=object) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index b8a34d5eaa226..7b206cc67d40d 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -64,7 +64,6 @@ def test_interpolate_inplace(self, frame_or_series, request): assert np.shares_memory(orig, obj.values) assert orig.squeeze()[1] == 1.5 - # TODO(infer_string) raise proper TypeError in case of string dtype @pytest.mark.xfail( using_string_dtype(), reason="interpolate doesn't work for string" ) diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index 88e43b678a7e4..80da849cc59d4 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -4,8 +4,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas.core.dtypes.common import ( is_float_dtype, is_integer_dtype, @@ -644,7 +642,6 @@ def test_rest_index_multiindex_categorical_with_missing_values(self, codes): tm.assert_frame_equal(res, expected) -@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") @pytest.mark.parametrize( "array, dtype", [ diff --git a/pandas/tests/frame/methods/test_to_dict_of_blocks.py b/pandas/tests/frame/methods/test_to_dict_of_blocks.py index 4f621b4643b70..0f1f643209db0 100644 --- a/pandas/tests/frame/methods/test_to_dict_of_blocks.py +++ b/pandas/tests/frame/methods/test_to_dict_of_blocks.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas import ( DataFrame, MultiIndex, @@ -27,7 +25,6 @@ def test_no_copy_blocks(self, float_frame): assert _last_df is not None and not _last_df[column].equals(df[column]) -@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_to_dict_of_blocks_item_cache(): # Calling to_dict_of_blocks should not poison item_cache df = DataFrame({"a": [1, 2, 3, 4], "b": ["a", "b", "c", "d"]}) From ee46751c1b6323ae0ea1f8a182c45ccb53e72778 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 13 Dec 2024 11:42:46 -0500 Subject: [PATCH 2/9] feedback --- pandas/core/arrays/arrow/array.py | 4 +++- pandas/core/frame.py | 4 ---- pandas/core/internals/blocks.py | 2 -- pandas/tests/frame/methods/test_astype.py | 10 +++++++++- pandas/tests/frame/methods/test_combine_first.py | 2 +- pandas/tests/frame/methods/test_dtypes.py | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index afa219f611992..311de77799260 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -2160,7 +2160,9 @@ def interpolate( """ # NB: we return type(self) even if copy=False if not self.dtype._is_numeric: - raise ValueError("Values must be numeric.") + raise NotImplementedError( + f"interpolate is not implemented for dtype={self.dtype}" + ) if ( not pa_version_under13p0 diff --git a/pandas/core/frame.py b/pandas/core/frame.py index bef474b949094..34b448a0d8d1c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6273,10 +6273,6 @@ class max type else: to_insert = ((self.index, None),) - if len(new_obj.columns) == 0 and names: - target_dtype = Index(names).dtype - new_obj.columns = new_obj.columns.astype(target_dtype) - multi_col = isinstance(self.columns, MultiIndex) for j, (lev, lab) in enumerate(to_insert, start=1): i = self.index.nlevels - j diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 639d5a410213f..e3f8eb5ff46fd 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2361,6 +2361,4 @@ def external_values(values: ArrayLike) -> ArrayLike: values.flags.writeable = False # TODO(CoW) we should also mark our ExtensionArrays as read-only - if isinstance(values, ExtensionArray): - ... # this is why test_to_dict_of_blocks_item_cache fails return values diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index b3fe7460d2da9..76df4e28eb5a2 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -765,7 +765,15 @@ def test_astype_dt64_to_string( item = item.iloc[0] if using_infer_string: assert item is pd.NA - else: + + # Check that Series/DataFrame.astype matches DatetimeArray.astype + expected = frame_or_series(dta.astype("str")) + tm.assert_equal(result, expected) + + item = result.iloc[0] + if frame_or_series is DataFrame: + item = item.iloc[0] + if using_infer_string: assert item is np.nan def test_astype_td64_to_string(self, frame_or_series): diff --git a/pandas/tests/frame/methods/test_combine_first.py b/pandas/tests/frame/methods/test_combine_first.py index 210394e33bd3b..a70876b5a96ca 100644 --- a/pandas/tests/frame/methods/test_combine_first.py +++ b/pandas/tests/frame/methods/test_combine_first.py @@ -30,7 +30,7 @@ def test_combine_first_mixed(self): combined = f.combine_first(g) tm.assert_frame_equal(combined, exp) - def test_combine_first(self, float_frame, using_infer_string): + def test_combine_first(self, float_frame): # disjoint head, tail = float_frame[:5], float_frame[5:] diff --git a/pandas/tests/frame/methods/test_dtypes.py b/pandas/tests/frame/methods/test_dtypes.py index dd8afccf2e25c..bf01ec73cf72b 100644 --- a/pandas/tests/frame/methods/test_dtypes.py +++ b/pandas/tests/frame/methods/test_dtypes.py @@ -137,5 +137,5 @@ def test_frame_apply_np_array_return_type(self, using_infer_string): # GH 35517 df = DataFrame([["foo"]]) result = df.apply(lambda col: np.array("bar")) - expected = Series(np.array(["bar"]), dtype=object) + expected = Series(np.array("bar")) tm.assert_series_equal(result, expected) From 40db2ea656417f65e2b98906e4025207059565c4 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Mon, 23 Dec 2024 15:27:18 -0500 Subject: [PATCH 3/9] Fixed test failures --- pandas/tests/extension/test_arrow.py | 2 +- pandas/tests/frame/methods/test_astype.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 6dd1f3f15bc15..be75530ff8f66 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -3451,7 +3451,7 @@ def test_string_to_datetime_parsing_cast(): ) def test_interpolate_not_numeric(data): if not data.dtype._is_numeric: - with pytest.raises(ValueError, match="Values must be numeric."): + with pytest.raises(NotImplementedError, match="interpolate is not implemented"): pd.Series(data).interpolate() diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 76df4e28eb5a2..1bc5debd3f4db 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -767,6 +767,7 @@ def test_astype_dt64_to_string( assert item is pd.NA # Check that Series/DataFrame.astype matches DatetimeArray.astype + result = obj.astype("str") expected = frame_or_series(dta.astype("str")) tm.assert_equal(result, expected) From d3dc93036b289dc229108598905e89df727dd1c0 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 2 Jan 2025 11:59:27 +0100 Subject: [PATCH 4/9] remove interpolate changes --- pandas/core/arrays/arrow/array.py | 4 +--- pandas/tests/extension/test_arrow.py | 2 +- pandas/tests/frame/methods/test_interpolate.py | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/arrow/array.py b/pandas/core/arrays/arrow/array.py index 311de77799260..afa219f611992 100644 --- a/pandas/core/arrays/arrow/array.py +++ b/pandas/core/arrays/arrow/array.py @@ -2160,9 +2160,7 @@ def interpolate( """ # NB: we return type(self) even if copy=False if not self.dtype._is_numeric: - raise NotImplementedError( - f"interpolate is not implemented for dtype={self.dtype}" - ) + raise ValueError("Values must be numeric.") if ( not pa_version_under13p0 diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index be75530ff8f66..6dd1f3f15bc15 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -3451,7 +3451,7 @@ def test_string_to_datetime_parsing_cast(): ) def test_interpolate_not_numeric(data): if not data.dtype._is_numeric: - with pytest.raises(NotImplementedError, match="interpolate is not implemented"): + with pytest.raises(ValueError, match="Values must be numeric."): pd.Series(data).interpolate() diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index 7b206cc67d40d..b8a34d5eaa226 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -64,6 +64,7 @@ def test_interpolate_inplace(self, frame_or_series, request): assert np.shares_memory(orig, obj.values) assert orig.squeeze()[1] == 1.5 + # TODO(infer_string) raise proper TypeError in case of string dtype @pytest.mark.xfail( using_string_dtype(), reason="interpolate doesn't work for string" ) From 572d62c1d46281650a49dc00480dbe0725e9c9f9 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 22 Jan 2025 15:47:36 -0500 Subject: [PATCH 5/9] Remove using_infer_string from astype("string") --- pandas/tests/frame/methods/test_astype.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index 1bc5debd3f4db..e5c6b76f81141 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -763,8 +763,8 @@ def test_astype_dt64_to_string( item = result.iloc[0] if frame_or_series is DataFrame: item = item.iloc[0] - if using_infer_string: - assert item is pd.NA + + assert item is pd.NA # Check that Series/DataFrame.astype matches DatetimeArray.astype result = obj.astype("str") From b8beead98e54f7aa7378cb7a09386f2edc28919c Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 22 Jan 2025 16:02:25 -0500 Subject: [PATCH 6/9] Use string_dtype_no_object fixture --- pandas/tests/frame/methods/test_astype.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index e5c6b76f81141..ea9c33c31bdcf 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -744,7 +744,10 @@ def test_astype_tz_object_conversion(self, tz): tm.assert_frame_equal(result, expected) def test_astype_dt64_to_string( - self, frame_or_series, tz_naive_fixture, using_infer_string + self, + frame_or_series, + tz_naive_fixture, + string_dtype_no_object, ): # GH#41409 tz = tz_naive_fixture @@ -754,28 +757,17 @@ def test_astype_dt64_to_string( dta[0] = NaT obj = frame_or_series(dta) - result = obj.astype("string") + result = obj.astype(string_dtype_no_object) # Check that Series/DataFrame.astype matches DatetimeArray.astype - expected = frame_or_series(dta.astype("string")) + expected = frame_or_series(dta.astype(string_dtype_no_object)) tm.assert_equal(result, expected) item = result.iloc[0] if frame_or_series is DataFrame: item = item.iloc[0] - assert item is pd.NA - - # Check that Series/DataFrame.astype matches DatetimeArray.astype - result = obj.astype("str") - expected = frame_or_series(dta.astype("str")) - tm.assert_equal(result, expected) - - item = result.iloc[0] - if frame_or_series is DataFrame: - item = item.iloc[0] - if using_infer_string: - assert item is np.nan + assert item is string_dtype_no_object.na_value def test_astype_td64_to_string(self, frame_or_series): # GH#41409 From 28ce5f0e9274fce3a29e239fbec66da403fa21d1 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 22 Jan 2025 17:01:22 -0500 Subject: [PATCH 7/9] Xfail test with empty index --- pandas/tests/frame/methods/test_reset_index.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/frame/methods/test_reset_index.py b/pandas/tests/frame/methods/test_reset_index.py index 80da849cc59d4..0b320075ed2d2 100644 --- a/pandas/tests/frame/methods/test_reset_index.py +++ b/pandas/tests/frame/methods/test_reset_index.py @@ -4,6 +4,8 @@ import numpy as np import pytest +from pandas._config import using_string_dtype + from pandas.core.dtypes.common import ( is_float_dtype, is_integer_dtype, @@ -642,6 +644,7 @@ def test_rest_index_multiindex_categorical_with_missing_values(self, codes): tm.assert_frame_equal(res, expected) +@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string) - GH#60338") @pytest.mark.parametrize( "array, dtype", [ From d2d17740009b30c81c081d9bea2fbc9cc581bd4c Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Wed, 22 Jan 2025 18:36:15 -0500 Subject: [PATCH 8/9] Revert test_to_dict_of_blocks --- pandas/tests/frame/methods/test_to_dict_of_blocks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/frame/methods/test_to_dict_of_blocks.py b/pandas/tests/frame/methods/test_to_dict_of_blocks.py index 0f1f643209db0..4f621b4643b70 100644 --- a/pandas/tests/frame/methods/test_to_dict_of_blocks.py +++ b/pandas/tests/frame/methods/test_to_dict_of_blocks.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas._config import using_string_dtype + from pandas import ( DataFrame, MultiIndex, @@ -25,6 +27,7 @@ def test_no_copy_blocks(self, float_frame): assert _last_df is not None and not _last_df[column].equals(df[column]) +@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") def test_to_dict_of_blocks_item_cache(): # Calling to_dict_of_blocks should not poison item_cache df = DataFrame({"a": [1, 2, 3, 4], "b": ["a", "b", "c", "d"]}) From 20f6b261d415f2696da4c8c41e97c42fb8d08627 Mon Sep 17 00:00:00 2001 From: Will Ayd Date: Fri, 21 Feb 2025 14:55:38 -0500 Subject: [PATCH 9/9] Remove empty column related test fixes --- pandas/core/internals/blocks.py | 1 + pandas/tests/frame/methods/test_dropna.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 4b56a6ead193f..d1a9081b234de 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2360,4 +2360,5 @@ def external_values(values: ArrayLike) -> ArrayLike: values.flags.writeable = False # TODO(CoW) we should also mark our ExtensionArrays as read-only + return values diff --git a/pandas/tests/frame/methods/test_dropna.py b/pandas/tests/frame/methods/test_dropna.py index 4a7c2d019d10f..11893d7fac1a4 100644 --- a/pandas/tests/frame/methods/test_dropna.py +++ b/pandas/tests/frame/methods/test_dropna.py @@ -187,7 +187,7 @@ def test_dropna_tz_aware_datetime(self): df = DataFrame() dt1 = datetime.datetime(2015, 1, 1, tzinfo=dateutil.tz.tzutc()) dt2 = datetime.datetime(2015, 2, 2, tzinfo=dateutil.tz.tzutc()) - df = DataFrame({"Time": [dt1]}) + df["Time"] = [dt1] result = df.dropna(axis=0) expected = DataFrame({"Time": [dt1]}) tm.assert_frame_equal(result, expected)