Skip to content

Commit 2857f87

Browse files
committed
MAINT: Address final comments
1 parent 3b100c3 commit 2857f87

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pandas/core/frame.py

+19
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,15 @@ def to_records(self, index=True, convert_datetime64=None,
16741674
for i, v in enumerate(arrays):
16751675
index = i
16761676

1677+
# When the names and arrays are collected, we
1678+
# first collect those in the DataFrame's index,
1679+
# followed by those in its columns.
1680+
#
1681+
# Thus, the total lenth of the array is:
1682+
# len(index_names) + len(DataFrame.columns).
1683+
#
1684+
# This check allows us to see whether we are
1685+
# handling a name / array in the index or column.
16771686
if index < index_len:
16781687
dtype_mapping = index_dtypes
16791688
name = index_names[index]
@@ -1682,6 +1691,11 @@ def to_records(self, index=True, convert_datetime64=None,
16821691
dtype_mapping = column_dtypes
16831692
name = self.columns[index]
16841693

1694+
# We have a dictionary, so we get the data type
1695+
# associated with the index or column (which can
1696+
# be denoted by its name in the DataFrame or its
1697+
# position in DataFrame's array of indices or
1698+
# columns, whichever is applicable.
16851699
if is_dict_like(dtype_mapping):
16861700
if name in dtype_mapping:
16871701
dtype_mapping = dtype_mapping[name]
@@ -1690,6 +1704,11 @@ def to_records(self, index=True, convert_datetime64=None,
16901704
else:
16911705
dtype_mapping = None
16921706

1707+
# If no mapping can be found, use the array's
1708+
# dtype attribute for formatting.
1709+
#
1710+
# A valid dtype must either be a type or
1711+
# string naming a type.
16931712
if dtype_mapping is None:
16941713
formats.append(v.dtype)
16951714
elif isinstance(dtype_mapping, (type, compat.string_types)):

pandas/tests/dtypes/test_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_is_dict_like_fails(ll):
181181
@pytest.mark.parametrize("has_keys", [True, False])
182182
@pytest.mark.parametrize("has_getitem", [True, False])
183183
@pytest.mark.parametrize("has_contains", [True, False])
184-
def test_is_dict_like_duct_type(has_keys, has_getitem, has_contains):
184+
def test_is_dict_like_duck_type(has_keys, has_getitem, has_contains):
185185
class DictLike(object):
186186
def __init__(self, d):
187187
self.d = d

0 commit comments

Comments
 (0)