-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: clarify level argument of reindex #15590
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
Comments
There is one example in the tutorial docs: http://pandas.pydata.org/pandas-docs/stable/advanced.html#advanced-reindexing-and-alignment What is not clear about the argument, is that it seems to work for both the passed and calling index:
|
Right... while In [22]: s_multi.reindex(s_multi.drop(('A', 'a')).index, level=1)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-9e6994e0de21> in <module>()
----> 1 s_multi.reindex(s_multi.drop(('A', 'a')).index, level=1)
/home/pietro/nobackup/repo/pandas/pandas/core/series.py in reindex(self, index, **kwargs)
2372 @Appender(generic._shared_docs['reindex'] % _shared_doc_kwargs)
2373 def reindex(self, index=None, **kwargs):
-> 2374 return super(Series, self).reindex(index=index, **kwargs)
2375
2376 @Appender(generic._shared_docs['fillna'] % _shared_doc_kwargs)
/home/pietro/nobackup/repo/pandas/pandas/core/generic.py in reindex(self, *args, **kwargs)
2331 # perform the reindex on the axes
2332 return self._reindex_axes(axes, level, limit, tolerance, method,
-> 2333 fill_value, copy).__finalize__(self)
2334
2335 def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,
/home/pietro/nobackup/repo/pandas/pandas/core/generic.py in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
2344 ax = self._get_axis(a)
2345 new_index, indexer = ax.reindex(labels, level=level, limit=limit,
-> 2346 tolerance=tolerance, method=method)
2347
2348 axis = self._get_axis_number(a)
/home/pietro/nobackup/repo/pandas/pandas/indexes/multi.py in reindex(self, target, method, level, limit, tolerance)
1652 target, indexer, _ = self._join_level(target, level, how='right',
1653 return_indexers=True,
-> 1654 keep_order=False)
1655 else:
1656 target = _ensure_index(target)
/home/pietro/nobackup/repo/pandas/pandas/indexes/base.py in _join_level(self, other, level, how, return_indexers, keep_order)
2995
2996 if isinstance(self, MultiIndex) and isinstance(other, MultiIndex):
-> 2997 raise TypeError('Join on level between two MultiIndex objects '
2998 'is ambiguous')
2999
TypeError: Join on level between two MultiIndex objects is ambiguous |
@toobaz yes, but I think that is to be expected? Presuming that it specifies level=1 for both calling and passed index, it is indeed not clear what the result should be (therefore " is ambiguous") |
Yes, you are right, I just think it is worth mentioning it in the docstring (users might expect something from it when the specified level of either of the two indexes is unique). |
The current docstring explanation of the
level
argument:is not very clarifying (match what on what?).
So it would be good to update that description and also add an example.
The text was updated successfully, but these errors were encountered: