Skip to content

Commit ccc33dd

Browse files
committed
ENH: Provide dict object for to_dict() pandas-dev#16122
1 parent 3070fa3 commit ccc33dd

File tree

5 files changed

+6
-8
lines changed

5 files changed

+6
-8
lines changed

doc/source/whatsnew/v0.20.1.txt

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Highlights include:
1818

1919
Enhancements
2020
~~~~~~~~~~~~
21-
- ``Series.to_dict()`` and ``DataFrame.to_dict()`` now support an ``into`` keyword which allows you to specify the ``collections.Mapping`` subclass that you would like returned. The default is ``dict``, which is backwards compatible. (:issue:`16122`)
2221

2322

2423

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ New features
2626

2727
Other Enhancements
2828
^^^^^^^^^^^^^^^^^^
29+
- ``Series.to_dict()`` and ``DataFrame.to_dict()`` now support an ``into`` keyword which allows you to specify the ``collections.Mapping`` subclass that you would like returned. The default is ``dict``, which is backwards compatible. (:issue:`16122`)
2930

3031

3132

pandas/core/common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,22 @@ def _dict_compat(d):
483483

484484
def _standardize_mapping(into):
485485
"""
486-
Helper function to standardize the supplied mapping so it can
486+
Helper function to standardize the supplied mapping so it can
487487
be passed to the ``Series.to_dict()`` and ``DataFrame.to_dict()``
488488
489489
Parameters
490490
----------
491491
into : instance or subclass of collections.Mapping
492492
The argument supplied to ``to_dict``. Must be a class, an
493493
initialized collections.defaultdict, or an empty instance
494-
of a collections.Mapping subclass.
494+
of a collections.Mapping subclass.
495495
496496
Returns
497497
-------
498498
mapping : a collections.Mapping subclass or other constructor
499499
a callable object that can accept an iterator to create
500500
the desired Mapping.
501-
501+
502502
"""
503503
if not inspect.isclass(into):
504504
if len(into) > 0:

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def to_dict(self, orient='dict', into=dict):
889889
instance of the mapping type you want. If you want a
890890
collections.defaultdict, you must pass an initialized
891891
instance.
892-
.. versionadded:: 0.20.1
892+
.. versionadded:: 0.21.0
893893
894894
Returns
895895
-------

pandas/core/series.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import types
1010
import warnings
1111
from textwrap import dedent
12-
import collections
1312

1413
from numpy import nan, ndarray
1514
import numpy as np
@@ -1086,7 +1085,7 @@ def to_dict(self, into=dict):
10861085
object. Can be the actual class or an empty
10871086
instance of the mapping type you want. If you want a
10881087
collections.defaultdict, you must pass an initialized
1089-
.. versionadded:: 0.20.1
1088+
.. versionadded:: 0.21.0
10901089
10911090
Returns
10921091
-------
@@ -1098,7 +1097,6 @@ def to_dict(self, into=dict):
10981097
into_c = _standardize_mapping(into)
10991098
return into_c(compat.iteritems(self))
11001099

1101-
11021100
def to_frame(self, name=None):
11031101
"""
11041102
Convert Series to DataFrame

0 commit comments

Comments
 (0)