Skip to content

_sanitize_column now reports proper duplicate error #7442

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
Jun 13, 2014
Merged

_sanitize_column now reports proper duplicate error #7442

merged 1 commit into from
Jun 13, 2014

Conversation

roblevy
Copy link
Contributor

@roblevy roblevy commented Jun 12, 2014

closes #7432
A very simple fix for GH7432. internals.py (line 3240) actually raises the correct exception (ValueError: cannot reindex from a duplicate axis) but the except: doesn't allow it to be raised. Here I've just allowed the exception itself to be raised since it's more useful to the user than the weird TypeError message.

@roblevy
Copy link
Contributor Author

roblevy commented Jun 12, 2014

Here's what the situation in Issue 7432 now looks like:

In [4]: df['newcol'] = ser
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-acaa0ccb832e> in <module>()
----> 1 df['hello'] = ser

/home/rob/pandas_roblevy/pandas/core/frame.py in __setitem__(self, key, value)
   1853         else:
   1854             # set column
-> 1855             self._set_item(key, value)
   1856 
   1857     def _setitem_slice(self, key, value):

/home/rob/pandas_roblevy/pandas/core/frame.py in _set_item(self, key, value)
   1921         is_existing = key in self.columns
   1922         self._ensure_valid_index(value)
-> 1923         value = self._sanitize_column(key, value)
   1924         NDFrame._set_item(self, key, value)
   1925 

/home/rob/pandas_roblevy/pandas/core/frame.py in _sanitize_column(self, key, value)
   1964                     value = value.reindex(self.index).values
   1965                 except ValueError as e:
-> 1966                     raise e
   1967                 except:
   1968                     raise TypeError('incompatible index of inserted column '

ValueError: cannot reindex from a duplicate axis

@jreback
Copy link
Contributor

jreback commented Jun 12, 2014

yep..looks trivial...can you rebase (so that travis will then run).

@jreback jreback added this to the 0.14.1 milestone Jun 12, 2014
@jreback jreback removed the Bug label Jun 12, 2014
@jreback jreback merged commit b3f9151 into pandas-dev:master Jun 13, 2014
@jreback
Copy link
Contributor

jreback commented Jun 13, 2014

thanks!

@jreback
Copy link
Contributor

jreback commented Jun 13, 2014

the importance of testing! turns out their are some other error messages here that are effectively raising as TypeError, fixed up here: 7ef4efa

@roblevy roblevy deleted the issue_7432_resolve branch June 14, 2014 10:54
@roblevy
Copy link
Contributor Author

roblevy commented Jun 14, 2014

Amazing. Next time I do a pull request I'll add a test for whatever I add. This is a good learning experience for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing error message on frame.__set_item__ with duplicate index entries
2 participants