Skip to content

BUG: fix construction of Series / Index from dict keys when "str" dtype is specified explicitly #60436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/base/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion pandas/tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading