Skip to content

Commit f7998d3

Browse files
committed
WIP on adding to_dict
1 parent 344687f commit f7998d3

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

doc/source/whatsnew/v1.1.0.rst

-22
Original file line numberDiff line numberDiff line change
@@ -269,28 +269,6 @@ change, as ``fsspec`` will still bring in the same packages as before.
269269

270270
.. _fsspec docs: https://filesystem-spec.readthedocs.io/en/latest/
271271

272-
.. _whatsnew_110.dict_tight:
273-
274-
DataFrame.from_dict and DataFrame.to_dict have new ``'tight'`` option
275-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
276-
277-
A new ``'tight'`` dictionary format that preserves :class:`MultiIndex` entries and names
278-
is now available with the :meth:`DataFrame.from_dict` and :meth:`DataFrame.to_dict` methods
279-
and can be used with the standard ``json`` library to produce a tight
280-
representation of :class:`DataFrame` objects (:issue:`4889`).
281-
282-
.. ipython:: python
283-
284-
df = pd.DataFrame.from_records(
285-
[[1, 3], [2, 4]],
286-
index=pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")],
287-
names=["n1", "n2"]),
288-
columns=pd.MultiIndex.from_tuples([("x", 1), ("y", 2)],
289-
names=["z1", "z2"]),
290-
)
291-
df
292-
df.to_dict(orient='tight')
293-
294272
.. _whatsnew_110.enhancements.other:
295273

296274
Other enhancements

doc/source/whatsnew/v1.2.0.rst

+22
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ Beginning with this version, the default is now to use the more accurate parser
109109
``floating_precision="legacy"`` to use the legacy parser. The change to using the higher precision
110110
parser by default should have no impact on performance. (:issue:`17154`)
111111

112+
.. _whatsnew_120.dict_tight:
113+
114+
DataFrame.from_dict and DataFrame.to_dict have new ``'tight'`` option
115+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116+
117+
A new ``'tight'`` dictionary format that preserves :class:`MultiIndex` entries and names
118+
is now available with the :meth:`DataFrame.from_dict` and :meth:`DataFrame.to_dict` methods
119+
and can be used with the standard ``json`` library to produce a tight
120+
representation of :class:`DataFrame` objects (:issue:`4889`).
121+
122+
.. ipython:: python
123+
124+
df = pd.DataFrame.from_records(
125+
[[1, 3], [2, 4]],
126+
index=pd.MultiIndex.from_tuples([("a", "b"), ("a", "c")],
127+
names=["n1", "n2"]),
128+
columns=pd.MultiIndex.from_tuples([("x", 1), ("y", 2)],
129+
names=["z1", "z2"]),
130+
)
131+
df
132+
df.to_dict(orient='tight')
133+
112134
.. _whatsnew_120.enhancements.other:
113135

114136
Other enhancements

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ def from_dict(cls, data, orient="columns", dtype=None, columns=None) -> DataFram
12401240
If 'tight', assume a dict with keys ['index', 'columns', 'data',
12411241
'index_names', 'column_names'].
12421242
1243-
.. versionadded:: 1.1.0
1243+
.. versionadded:: 1.2.0
12441244
'tight' as an allowed value for the ``orient`` argument
12451245
12461246
dtype : dtype, default None
@@ -1431,7 +1431,7 @@ def to_dict(self, orient="dict", into=dict):
14311431
Abbreviations are allowed. `s` indicates `series` and `sp`
14321432
indicates `split`.
14331433
1434-
.. versionadded:: 1.1.0
1434+
.. versionadded:: 1.2.0
14351435
'tight' as an allowed value for the ``orient`` argument
14361436
14371437
into : class, default dict

test_fast.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
:: test on windows
22
set PYTHONHASHSEED=314159265
3-
pytest --skip-slow --skip-network --skip-db -m "not single" -n 4 -r sXX --strict pandas
3+
pytest --skip-slow --skip-network --skip-db -m "not single" -n 8 -r sXX --strict pandas

0 commit comments

Comments
 (0)