def reindex(self, *args, **kwargs):
# construct the args
axes, kwargs = self._construct_axes_from_arguments(args, kwargs)
method = missing.clean_reindex_fill_method(kwargs.pop('method', None))
'''
下面的代码,最是精妙
'''
level = kwargs.pop('level', None)copy = kwargs.pop('copy', True)limit = kwargs.pop('limit', None)tolerance = kwargs.pop('tolerance', None)fill_value = kwargs.pop('fill_value', np.nan)ifkwargs:raise TypeError('reindex() got an unexpected keyword ''argument "{0}"'.format(list(kwargs.keys())[0]))
self._consolidate_inplace()
# if all axes that are requested to reindex are equal, then only copy
# if indicated must have index names equal here as well as values
if all([self._get_axis(axis).identical(ax)
for axis, ax in axes.items() if ax isnot None]):
ifcopy:
return self.copy()
return self
# check if we are a multi reindex
ifself._needs_reindex_multi(axes, method, level):try:
return self._reindex_multi(axes, copy, fill_value)
except:
pass
# perform the reindex on the axes
return self._reindex_axes(axes, level, limit, tolerance, method,
fill_value, copy).__finalize__(self)