10000 ENH: Let initialisation from dicts use insertion order for python >= 3.6 (part III) by topper-123 · Pull Request #19884 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: Let initialisation from dicts use insertion order for python >= 3.6 (part III) #19884

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 3 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
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
doc
  • Loading branch information
jreback committed Mar 2, 2018
commit 473f564268d8c6c14590b5fddd226864ceea81cc
20 changes: 10 additions & 10 deletions doc/source/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ Series can be instantiated from dicts:

.. note::
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this note a bit below? It seems strange to start this "from dict" section with a note without first explaining what it actually is.
So I would give an example first, and only afterwards noting that the output depends on the python version


When the data is a dict, and index is not passed, the Series index
When the data is a dict, and an index is not passed, the ``Series`` index
will be ordered by the dict's insertion order, if you're using Python
version >= 3.6 and Pandas version >= 0.23.

If you're using Python < 3.6 or Pandas < 0.23, and index is not passed,
the Series index will be the lexically ordered list of dict keys.
If you're using Python < 3.6 or Pandas < 0.23, and an index is not passed,
the ``Series`` index will be the lexically ordered list of dict keys.

So, in the example above, if you were on a Python version lower than 3.6 or a
Pandas lower than 0.23, the Series would be ordered by the lexical order of the
dict keys (i.e. ['a', 'b', 'c'] rather than ['b', 'a', 'c']).
In the example above, if you were on a Python version lower than 3.6 or a
Pandas version lower than 0.23, the ``Series`` would be ordered by the lexical
order of the dict keys (i.e. ``['a', 'b', 'c']`` rather than ``['b', 'a', 'c']``).

If an index is passed, the values in data corresponding to the labels in the
index will be pulled out.
Expand Down Expand Up @@ -264,12 +264,12 @@ based on common sense rules.

.. note::

When the data is a dict, and ``columns`` is not specified, the DataFrame
columns will be ordered by the dict's insertion order, if you're using
When the data is a dict, and ``columns`` is not specified, the ``DataFrame``
columns will be ordered by the dict's insertion order, if you are using
Python version >= 3.6 and Pandas >= 0.23.

If you're using Python < 3.6 or Pandas < 0.23, and ``columns`` is not
specified, the DataFrame columns will be the lexically ordered list of dict
If you are using Python < 3.6 or Pandas < 0.23, and ``columns`` is not
specified, the ``DataFrame`` columns will be the lexically ordered list of dict
keys.

From dict of Series or dicts
8000 Expand Down
8 changes: 4 additions & 4 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ Instantation from dicts preserves dict insertion order for python 3.6+
Until Python 3.6, dicts in Python had no formally defined ordering. For Python
version 3.6 and later, dicts are ordered by insertion order, see
`PEP 468 <https://www.python.org/dev/peps/pep-0468/>`_.
Pandas will use the dict's insertion order, when creating Series or
DataFrames from dicts (:issue:`19018`) and you're using Python version 3.6 or
higher.
Pandas will use the dict's insertion order, when creating a ``Series`` or
``DataFrame`` from a dict and you're using Python version 3.6 or
higher. (:issue:`19884`)

Previous Behavior (and current behavior if on Python < 3.6):

Expand Down Expand Up @@ -403,7 +403,7 @@ used for all relevant pandas types (``Series``, ``DataFrame``, ``SparseSeries``
and ``SparseDataFrame``).

If you wish to retain the old behavior while using Python >= 3.6, you can use
``sort_index``:
``.sort_index()``:

.. ipython:: python

Expand Down
0