Skip to content

BUG: Bug in DataFrame.dropna with duplicate indices (GH6355) #6388

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 1 commit into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Bug Fixes
- Bug in interpolate changing dtypes (:issue:`6290`)
- Bug in Series.get, was using a buggy access method (:issue:`6383`)
- Bug in hdfstore queries of the form ``where=[('date', '>=', datetime(2013,1,1)), ('date', '<=', datetime(2014,1,1))]`` (:issue:`6313`)
- Bug in DataFrame.dropna with duplicate indices (:issue:`6355`)

pandas 0.13.1
-------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2414,8 +2414,8 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,

agg_obj = self
if subset is not None:
agg_axis_name = self._get_axis_name(agg_axis)
agg_obj = self.reindex(**{agg_axis_name: subset})
ax = self._get_axis(agg_axis)
agg_obj = self.take(ax.get_indexer_for(subset),axis=agg_axis)

count = agg_obj.count(axis=agg_axis)

Expand Down
6 changes: 6 additions & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,12 @@ def get_indexer_non_unique(self, target, **kwargs):
indexer, missing = self._engine.get_indexer_non_unique(tgt_values)
return Index(indexer), missing

def get_indexer_for(self, target, **kwargs):
""" guaranteed return of an indexer even when non-unique """
if self.is_unique:
return self.get_indexer(target, **kwargs)
return self.get_indexer_non_unique(target, **kwargs)[0]

def _possibly_promote(self, other):
# A hack, but it works
from pandas.tseries.index import DatetimeIndex
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3256,6 +3256,23 @@ def test_column_dups2(self):
result = df2.drop('C',axis=1)
assert_frame_equal(result, expected)

# dropna
df = DataFrame({'A' : np.random.randn(5),
'B' : np.random.randn(5),
'C' : np.random.randn(5),
'D' : ['a','b','c','d','e'] })
df.iloc[2,[0,1,2]] = np.nan
df.iloc[0,0] = np.nan
df.iloc[1,1] = np.nan
df.iloc[:,3] = np.nan
expected = df.dropna(subset=['A','B','C'],how='all')
expected.columns = ['A','A','B','C']

df.columns = ['A','A','B','C']

result = df.dropna(subset=['A','C'],how='all')
assert_frame_equal(result, expected)

def test_column_dups_indexing(self):

def check(result, expected=None):
Expand Down