Skip to content
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

BUG: Formerly useful behavior now raises. #5185

Closed
danielballan opened this issue Oct 11, 2013 · 3 comments · Fixed by #5187
Closed

BUG: Formerly useful behavior now raises. #5185

danielballan opened this issue Oct 11, 2013 · 3 comments · Fixed by #5187
Labels
Milestone

Comments

@danielballan
Copy link
Contributor

I did this:

In [1]: df1 = DataFrame([1, 2, 3, 4, 5], index=[1, 2, 1, 2, 3])

In [2]: df2 = DataFrame([1, 2, 3], index=[1, 2, 3])

In [3]: df1.sub(df2)
Out[3]:
0
1 0
1 2
2 0
2 2
3 2

which is possible up to and including this commit. Then, this "bug fix" seems to have broken the above usage. It now raises like so:

ValueError                                Traceback (most recent call last)
<ipython-input-12-e7e549a4e818> in <module>()
----> 1 df1.sub(df2)

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/ops.pyc in f(self, other, axis, level, fill_value)
    710     def f(self, other, axis=default_axis, level=None, fill_value=None):
    711         if isinstance(other, pd.DataFrame):    # Another DataFrame
--> 712             return self._combine_frame(other, na_op, fill_value, level)
    713         elif isinstance(other, pd.Series):
    714             return self._combine_series(other, na_op, fill_value, axis, level)

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/frame.pyc in _combine_frame(self, other, func, fill_value, level)
   2759 
   2760     def _combine_frame(self, other, func, fill_value=None, level=None):
-> 2761         this, other = self.align(other, join='outer', level=level, copy=False)
   2762         new_index, new_columns = this.index, this.columns
   2763 

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/generic.pyc in align(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis)
   2331                                      copy=copy, fill_value=fill_value,
   2332                                      method=method, limit=limit,
-> 2333                                      fill_axis=fill_axis)
   2334         elif isinstance(other, Series):
   2335             return self._align_series(other, join=join, axis=axis, level=level,

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/generic.pyc in _align_frame(self, other, join, axis, level, copy, fill_value, method, limit, fill_axis)
   2362         left = self._reindex_with_indexers({0: [join_index,   ilidx],
   2363                                             1: [join_columns, clidx]},
-> 2364                                            copy=copy, fill_value=fill_value)
   2365         right = other._reindex_with_indexers({0: [join_index,   iridx],
   2366                                               1: [join_columns, cridx]},

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/generic.pyc in _reindex_with_indexers(self, reindexers, method, fill_value, limit, copy, allow_dups)
   1320                 indexer = com._ensure_int64(indexer)
   1321                 new_data = new_data.reindex_indexer(index, indexer, axis=baxis,
-> 1322                                                     fill_value=fill_value, allow_dups=allow_dups)
   1323 
   1324             elif baxis == 0 and index is not None and index is not new_data.axes[baxis]:

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/internals.pyc in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups)
   2884         # trying to reindex on an axis with duplicates
   2885         if not allow_dups and not self.axes[axis].is_unique:
-> 2886             raise ValueError("cannot reindex from a duplicate axis")
   2887 
   2888         if axis == 0:

ValueError: cannot reindex from a duplicate axis

I found this very handy. Should it really raise? Can you suggest what I should be doing instead? Thanks.

@jreback
Copy link
Contributor

jreback commented Oct 11, 2013

that is disappointing! let me take a look

@jreback
Copy link
Contributor

jreback commented Oct 11, 2013

@danielballan oversight on that operation....see #5187
look right? (same behavior in 0.12)

@danielballan
Copy link
Contributor Author

Yes, all fixed. Glad it has a test now. Thanks for handling this promptly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants