@@ -1674,6 +1674,15 @@ def to_records(self, index=True, convert_datetime64=None,
1674
1674
for i , v in enumerate (arrays ):
1675
1675
index = i
1676
1676
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 length 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.
1677
1686
if index < index_len :
1678
1687
dtype_mapping = index_dtypes
1679
1688
name = index_names [index ]
@@ -1682,6 +1691,11 @@ def to_records(self, index=True, convert_datetime64=None,
1682
1691
dtype_mapping = column_dtypes
1683
1692
name = self .columns [index ]
1684
1693
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.
1685
1699
if is_dict_like (dtype_mapping ):
1686
1700
if name in dtype_mapping :
1687
1701
dtype_mapping = dtype_mapping [name ]
@@ -1690,6 +1704,11 @@ def to_records(self, index=True, convert_datetime64=None,
1690
1704
else :
1691
1705
dtype_mapping = None
1692
1706
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.
1693
1712
if dtype_mapping is None :
1694
1713
formats .append (v .dtype )
1695
1714
elif isinstance (dtype_mapping , (type , compat .string_types )):
0 commit comments