Skip to content

Commit 1115bec

Browse files
author
pilkibun
committed
move to v1.0.0
1 parent 56a5d6f commit 1115bec

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ Other enhancements
235235
- :func:`read_excel` can now use ``openpyxl`` to read Excel files via the ``engine='openpyxl'`` argument. This will become the default in a future release (:issue:`11499`)
236236
- :func:`pandas.io.excel.read_excel` supports reading OpenDocument tables. Specify ``engine='odf'`` to enable. Consult the :ref:`IO User Guide <io.ods>` for more details (:issue:`9070`)
237237
- :class:`Interval`, :class:`IntervalIndex`, and :class:`~arrays.IntervalArray` have gained an :attr:`~Interval.is_empty` attribute denoting if the given interval(s) are empty (:issue:`27219`)
238-
- :class:`DataFrame` now treats lists of typing.NameTuple equivalently to lists of nametuples. The behavior of the latter has changed in this release, please see the relevant section in "Breaking Changes".
239238

240239
.. _whatsnew_0250.api_breaking:
241240

@@ -804,57 +803,6 @@ order of the resulting DataFrame has changed compared to previous pandas verison
804803
805804
pd.DataFrame(data)
806805
807-
DataFrame constructor treats list of namedtuple/dict in the same way
808-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
809-
810-
Previously, only the first element in the list was checked and if it was a
811-
namedtuple, the field names of that single tuple were used as the column names.
812-
Subsequent tuples were assumed to be of the same type, and their values were
813-
looked up by position. As a consequence, if subsequent tuples of different types
814-
were included, any additional fields were ignored, and if similarly named fields
815-
appeard in a different order, alignment was not performed.
816-
817-
This behavior has now changed so that namedtuples are treated much as list of
818-
dict behaves, i.e as a "list of records".
819-
820-
Additionaly, this change implies a change in the semantics of the `columns`
821-
argument to :class:`DataFrame` when passing a list of namedtuples. Previously,
822-
`columns` has "rename" semantics, now it has the same "lookup" semantics as a
823-
list of records. Meaning that any name given in `columns` which doesn't appear
824-
as a key in the record will be assigned a NaN value.
825-
826-
Due to this change, The performance of constructing frames from a list
827-
of namedtuples is now roughly 50% slower.
828-
829-
This change affects all supported python versions.
830-
831-
.. ipython:: python
832-
833-
from collections import namedtuple
834-
Foo = namedtuple("Foo", list("ab"))
835-
tuples = [Foo(1, 3), Foo(2, 4)]
836-
837-
*Previous Behavior*:
838-
839-
The columns were lexicographically sorted previously,
840-
841-
.. code-block:: python
842-
843-
In [1]: pd.DataFrame(tuples, columns=['y', 'z'])
844-
Out[1]:
845-
y z
846-
0 1 3
847-
1 2 4
848-
849-
*New Behavior*:
850-
851-
The column order now matches the insertion-order of the keys in the ``dict``,
852-
considering all the records from top to bottom.
853-
854-
.. ipython:: python
855-
856-
pd.DataFrame(tuples, columns=['Q', 'a'])
857-
858806
.. _whatsnew_0250.api_breaking.deps:
859807
860808
Increased minimum versions for dependencies

doc/source/whatsnew/v1.0.0.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,61 @@ Backwards incompatible API changes
4242
- :class:`pandas.core.groupby.GroupBy.transform` now raises on invalid operation names (:issue:`27489`).
4343
-
4444

45+
DataFrame constructor treats list of namedtuple/dict in the same way
46+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
48+
Lists of typing.NameTuple are now treated the same way as lists of :class:`collections.namedtuple.`
49+
by the :class:`DataFrame` constructor.
50+
51+
The treatment of such lists has also changed in this release. Previously, only
52+
the first element in the list was checked, and if it was a namedtuple, the
53+
field names of that single tuple were used as the column names. Subsequent
54+
tuples were assumed to be of the same type, and their values were looked up by
55+
position. As a consequence, if subsequent tuples of different types were
56+
included, any additional fields were dropped, and if similarly named fields
57+
appeared in a different order, alignment was not performed.
58+
59+
This behavior has now changed so that namedtuples are treated in the same way
60+
as list of dict behaves, i.e as a "list of records" (:issue:`27329`) (:issue:`27494`).
61+
62+
Additionally, this change implies a change in the semantics of the `columns`
63+
argument to :class:`DataFrame` when passing a list of namedtuples. Previously,
64+
`columns` has "rename" semantics, now it has the same "lookup" semantics as a
65+
list of records. Meaning that any name given in `columns` which doesn't appear
66+
as a key in the record will be assigned a NaN value.
67+
68+
Due to this change, The performance of constructing frames from a list of
69+
namedtuples is now roughly 50% slower.
70+
71+
This change affects all supported python versions.
72+
73+
.. ipython:: python
74+
75+
from collections import namedtuple
76+
Foo = namedtuple("Foo", list("ab"))
77+
tuples = [Foo(1, 3), Foo(2, 4)]
78+
79+
*Previous Behavior*:
80+
81+
The columns were lexicographically sorted previously,
82+
83+
.. code-block:: python
84+
85+
In [1]: pd.DataFrame(tuples, columns=['y', 'z'])
86+
Out[1]:
87+
y z
88+
0 1 3
89+
1 2 4
90+
91+
*New Behavior*:
92+
93+
The column order now matches the insertion-order of the keys in the ``dict``,
94+
considering all the records from top to bottom.
95+
96+
.. ipython:: python
97+
98+
pd.DataFrame(tuples, columns=['Q', 'a'])
99+
45100
Other API changes
46101
^^^^^^^^^^^^^^^^^
47102

0 commit comments

Comments
 (0)