Skip to content

BUG: DataFrame.to_dict when orient=index data loss #22810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 11, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
less verbose whatsnew
  • Loading branch information
jameswinegar committed Oct 8, 2018
commit fb2eff0c7428dd260f6756a08042b76c7d049083
23 changes: 0 additions & 23 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,29 +381,6 @@ Raise ValueError in ``DataFrame.to_dict(orient='index')``
Bug in :func:`DataFrame.to_dict` raises ``ValueError`` when used with
``orient='index'`` and a non-unique index instead of losing data (:issue:`22801`)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a mini-example here (just showing what kind of data frame will raise). the prior example was too long, but I think we need something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an ipython block that will raise the error. @jreback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but now the docs will not work. so, you can do this as an ipython block but you need an :okexcept: to handle the exception.

also show the df after defining it

Previous Behavior:

Calling :func:`DataFrame.to_dict` resulted in data loss when ``orient='index'``
for non-unique indexes

.. code-block:: ipython

In [2]: df = pd.DataFrame({'a': [1, 2], 'b': [0.5, 0.75]}, index=['A', 'A'])

In [3]: df.to_dict(orient='index')
Out [3]: {'A': {'a': 2.0, 'b': 0.75}}

Current Behavior:

Calling :func:`DataFrame.to_dict` will now result in a ValueError being raised
when ``orient='index'`` for non-unique index values

.. ipython:: python

df = pd.DataFrame({'a': [1, 2], 'b': [0.5, 0.75]}, index=['A', 'A'])

df.to_dict(orient='index')

.. _whatsnew_0240.api.datetimelike.normalize:

Tick DateOffset Normalize Restrictions
Expand Down