-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix issue with inserting duplicate columns in a dataframe (GH14291) #14384
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -302,7 +302,12 @@ def fillna(self, value=None, method=None, axis=0, inplace=False, | |
# ---------------------------------------------------------------------- | ||
# Support different internal representation of SparseDataFrame | ||
|
||
def _sanitize_column(self, key, value): | ||
def _sanitize_column(self, key, value, broadcast=True): | ||
""" | ||
The "broadcast" parameter was added to match the method signature of | ||
DataFrame._sanitize_column. However, this method does not make use of | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here (you can use a shared_doc to avoid repeating things) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these files import shared_doc from pandas.core.generic, but pandas.core.generic doesn't have it's own definition for _sanitize_column. I can't find any other instances of someone adding to the shared_doc without immediately using the docstring, but I can do that if that's what you want. For now, I just updated the docs in both places. |
||
broadcasting. | ||
""" | ||
sp_maker = lambda x, index=None: SparseArray( | ||
x, index=index, fill_value=self._default_fill_value, | ||
kind=self._default_kind) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,15 @@ def test_insert(self): | |
exp = DataFrame(data={'X': ['x', 'y', 'z']}, index=['A', 'B', 'C']) | ||
assert_frame_equal(df, exp) | ||
|
||
# GH 14291 | ||
df = DataFrame() | ||
df.insert(0, 'A', ['a', 'b', 'c'], allow_duplicates=True) | ||
df.insert(0, 'A', ['a', 'b', 'c'], allow_duplicates=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a different value each time so its clear that its not copying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is more appropriate in test_nonunique_indexes file. |
||
df.insert(0, 'A', ['a', 'b', 'c'], allow_duplicates=True) | ||
exp = DataFrame([['a', 'a', 'a'], ['b', 'b', 'b'], | ||
['c', 'c', 'c']], columns=['A', 'A', 'A']) | ||
assert_frame_equal(df, exp) | ||
|
||
def test_delitem(self): | ||
del self.frame['A'] | ||
self.assertNotIn('A', self.frame) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add a Parameters section