Skip to content

Commit 0bac57f

Browse files
committed
BUG: inserting dups into blocks ok
CLN: finished duplicate item insert/delete - whoosh! (GH3679) BUG: insert almost working BUG: fixed insertion of dup columns! ENH: added allow_duplicates kw to DataFrame.insert to indicate that inserting of a duplicate column should be allowed (default is False)
1 parent 6ec026c commit 0bac57f

File tree

6 files changed

+250
-67
lines changed

6 files changed

+250
-67
lines changed

RELEASE.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ pandas 0.11.1
102102
GH3675_, GH3676_).
103103
- Deprecated display.height, display.width is now only a formatting option
104104
does not control triggering of summary, similar to < 0.11.0.
105+
- Add the keyword ``allow_duplicates`` to ``DataFrame.insert`` to allow a duplicate column
106+
to be inserted if ``True``, default is ``False`` (same as prior to 0.11.1) (GH3679_)
105107

106108
**Bug Fixes**
107109

@@ -133,6 +135,7 @@ pandas 0.11.1
133135
- Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562_)
134136
- Concat to produce a non-unique columns when duplicates are across dtypes is fixed (GH3602_)
135137
- Non-unique indexing with a slice via ``loc`` and friends fixed (GH3659_)
138+
- Allow insert/delete to non-unique columns (GH3679_)
136139
- Fixed bug in groupby with empty series referencing a variable before assignment. (GH3510_)
137140
- Fixed bug in mixed-frame assignment with aligned series (GH3492_)
138141
- Fixed bug in selecting month/quarter/year from a series would not select the time element
@@ -242,6 +245,8 @@ pandas 0.11.1
242245
.. _GH3606: https://github.com/pydata/pandas/issues/3606
243246
.. _GH3659: https://github.com/pydata/pandas/issues/3659
244247
.. _GH3649: https://github.com/pydata/pandas/issues/3649
248+
.. _GH3679: https://github.com/pydata/pandas/issues/3679
249+
.. _Gh3616: https://github.com/pydata/pandas/issues/3616
245250
.. _GH1818: https://github.com/pydata/pandas/issues/1818
246251
.. _GH3572: https://github.com/pydata/pandas/issues/3572
247252
.. _GH3582: https://github.com/pydata/pandas/issues/3582

doc/source/v0.11.1.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ API changes
7171
``DataFrame.fillna()`` and ``DataFrame.replace()`` instead. (GH3582_,
7272
GH3675_, GH3676_)
7373

74+
- Add the keyword ``allow_duplicates`` to ``DataFrame.insert`` to allow a duplicate column
75+
to be inserted if ``True``, default is ``False`` (same as prior to 0.11.1) (GH3679_)
7476

7577
Enhancements
7678
~~~~~~~~~~~~
@@ -209,6 +211,7 @@ Bug Fixes
209211
and handle missing elements like unique indices (GH3561_)
210212
- Duplicate indexes with and empty DataFrame.from_records will return a correct frame (GH3562_)
211213
- Concat to produce a non-unique columns when duplicates are across dtypes is fixed (GH3602_)
214+
- Allow insert/delete to non-unique columns (GH3679_)
212215

213216
For example you can do
214217

@@ -270,3 +273,4 @@ on GitHub for a complete list.
270273
.. _GH3676: https://github.com/pydata/pandas/issues/3676
271274
.. _GH3675: https://github.com/pydata/pandas/issues/3675
272275
.. _GH3682: https://github.com/pydata/pandas/issues/3682
276+
.. _GH3679: https://github.com/pydata/pandas/issues/3679

pandas/core/frame.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,10 +2162,10 @@ def _set_item(self, key, value):
21622162
value = self._sanitize_column(key, value)
21632163
NDFrame._set_item(self, key, value)
21642164

2165-
def insert(self, loc, column, value):
2165+
def insert(self, loc, column, value, allow_duplicates=False):
21662166
"""
2167-
Insert column into DataFrame at specified location. Raises Exception if
2168-
column is already contained in the DataFrame
2167+
Insert column into DataFrame at specified location.
2168+
if allow_duplicates is False, Raises Exception if column is already contained in the DataFrame
21692169
21702170
Parameters
21712171
----------
@@ -2175,7 +2175,7 @@ def insert(self, loc, column, value):
21752175
value : int, Series, or array-like
21762176
"""
21772177
value = self._sanitize_column(column, value)
2178-
self._data.insert(loc, column, value)
2178+
self._data.insert(loc, column, value, allow_duplicates=allow_duplicates)
21792179

21802180
def _sanitize_column(self, key, value):
21812181
# Need to make sure new columns (which go into the BlockManager as new

0 commit comments

Comments
 (0)