Skip to content

Commit 5289000

Browse files
committed
BUG: GH36928 Allow dict_keys to be used as column names by read_csv
1 parent ec8c1c4 commit 5289000

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pandas/_libs/lib.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ cdef inline bint c_is_list_like(object obj, bint allow_sets) except -1:
10191019
and not (util.is_array(obj) and obj.ndim == 0)
10201020
# exclude sets if allow_sets is False
10211021
and not (allow_sets is False and isinstance(obj, abc.Set))
1022+
# allow dict_keys objects
1023+
or isinstance(obj, abc.KeysView)
10221024
)
10231025

10241026

pandas/tests/io/parser/test_common.py

+9
Original file line numberDiff line numberDiff line change
@@ -2221,3 +2221,12 @@ def test_read_table_delim_whitespace_non_default_sep(all_parsers):
22212221
)
22222222
with pytest.raises(ValueError, match=msg):
22232223
parser.read_table(f, delim_whitespace=True, sep=",")
2224+
2225+
2226+
def test_dict_keys_as_names(all_parsers):
2227+
data = "a,b\n1,2"
2228+
2229+
keys = {"a": int, "b": int}.keys()
2230+
parser = all_parsers
2231+
2232+
parser.read_csv(StringIO(data), names=keys)

0 commit comments

Comments
 (0)