Skip to content

Commit a4ca1db

Browse files
author
y-p
committed
ENH: df.from_records should accept values deriving from ABC collection.Mapping, GH3000
1 parent 1572735 commit a4ca1db

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

doc/source/v0.11.0.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ Enhancements
280280
- value_counts() now accepts a "normalize" argument, for normalized
281281
histograms. (GH2710_).
282282

283+
- DataFrame.from_records now accepts not only dicts but any instance of
284+
the collections.Mapping ABC.
285+
286+
283287

284288
Bug Fixes
285289
~~~~~~~~~

pandas/core/frame.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import csv
1818
import operator
1919
import sys
20+
import collections
2021

2122
from numpy import nan as NA
2223
import numpy as np
@@ -413,7 +414,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
413414
if index is None and isinstance(data[0], Series):
414415
index = _get_names_from_index(data)
415416

416-
if isinstance(data[0], (list, tuple, dict, Series)):
417+
if isinstance(data[0], (list, tuple, collections.Mapping, Series)):
417418
arrays, columns = _to_arrays(data, columns, dtype=dtype)
418419
columns = _ensure_index(columns)
419420

@@ -5527,7 +5528,7 @@ def _to_arrays(data, columns, coerce_float=False, dtype=None):
55275528
if isinstance(data[0], (list, tuple)):
55285529
return _list_to_arrays(data, columns, coerce_float=coerce_float,
55295530
dtype=dtype)
5530-
elif isinstance(data[0], dict):
5531+
elif isinstance(data[0], collections.Mapping):
55315532
return _list_of_dict_to_arrays(data, columns,
55325533
coerce_float=coerce_float,
55335534
dtype=dtype)

0 commit comments

Comments
 (0)