From 92781f53c3c3f157bb4b72e3d4fed1ae94e45b7d Mon Sep 17 00:00:00 2001 From: tasfia8 Date: Thu, 28 Nov 2024 08:02:14 -0500 Subject: [PATCH 1/3] If check generic fixes bug 60343 --- pandas/core/construction.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/construction.py b/pandas/core/construction.py index 8df4f7e3e08f9..50088804e0245 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -596,6 +596,8 @@ def sanitize_array( # create an extension array from its dtype _sanitize_non_ordered(data) cls = dtype.construct_array_type() + if not hasattr(data, "__array__"): + data = list(data) subarr = cls._from_sequence(data, dtype=dtype, copy=copy) # GH#846 From 283932caaf3876b2ded0bbeb0bfd14e768960cc9 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 3 Jan 2025 13:45:49 +0100 Subject: [PATCH 2/3] add test --- pandas/tests/base/test_constructors.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/base/test_constructors.py b/pandas/tests/base/test_constructors.py index c4b02423f8cf0..dffd2009ef373 100644 --- a/pandas/tests/base/test_constructors.py +++ b/pandas/tests/base/test_constructors.py @@ -179,3 +179,14 @@ def test_constructor_datetime_nonns(self, constructor): arr.flags.writeable = False result = constructor(arr) tm.assert_equal(result, expected) + + def test_constructor_from_dict_keys(self, constructor, using_infer_string): + # https://github.com/pandas-dev/pandas/issues/60343 + d = {"a": 1, "b": 2} + result = constructor(d.keys(), dtype="str") + if using_infer_string: + assert result.dtype == "str" + else: + assert result.dtype == "object" + expected = constructor(list(d.keys()), dtype="str") + tm.assert_equal(result, expected) From c85e29549edbab9147b7ea8d0759e3f16109195d Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 26 Jan 2025 11:32:48 +0100 Subject: [PATCH 3/3] remove fastparquet xfail --- pandas/tests/io/test_fsspec.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/io/test_fsspec.py b/pandas/tests/io/test_fsspec.py index 5340560884afe..2e3e74a9d31ff 100644 --- a/pandas/tests/io/test_fsspec.py +++ b/pandas/tests/io/test_fsspec.py @@ -209,7 +209,6 @@ def test_arrowparquet_options(fsspectest): assert fsspectest.test[0] == "parquet_read" -@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string) fastparquet") def test_fastparquet_options(fsspectest): """Regression test for writing to a not-yet-existent GCS Parquet file.""" pytest.importorskip("fastparquet")