Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
CLN: revisit & simplify Block/BlockManager, remove axes #6745
Merged
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
Jump to file or symbol
Failed to load files and symbols.
| @@ -565,7 +565,7 @@ def f(x): | ||
| f = _get_rename_function(v) | ||
| baxis = self._get_block_manager_axis(axis) | ||
| - result._data = result._data.rename(f, axis=baxis, copy=copy) | ||
| + result._data = result._data.rename_axis(f, axis=baxis, copy=copy) | ||
| result._clear_item_cache() | ||
| if inplace: | ||
| @@ -1217,21 +1217,9 @@ def take(self, indices, axis=0, convert=True, is_copy=True): | ||
| taken : type of caller | ||
| """ | ||
| - # check/convert indicies here | ||
| - if convert: | ||
| - axis = self._get_axis_number(axis) | ||
| - indices = _maybe_convert_indices( | ||
| - indices, len(self._get_axis(axis))) | ||
| - | ||
| - baxis = self._get_block_manager_axis(axis) | ||
| - if baxis == 0: | ||
| - labels = self._get_axis(axis) | ||
| - new_items = labels.take(indices) | ||
| - new_data = self._data.reindex_axis(new_items, indexer=indices, | ||
| - axis=baxis) | ||
| - else: | ||
| - new_data = self._data.take(indices, axis=baxis) | ||
| - | ||
| + new_data = self._data.take(indices, | ||
| + axis=self._get_block_manager_axis(axis), | ||
| + convert=True, verify=True) | ||
| result = self._constructor(new_data).__finalize__(self) | ||
| # maybe set copy if we didn't actually change the index | ||
| @@ -1701,7 +1689,7 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True, | ||
| labels, method, level, limit=limit, copy_if_needed=True) | ||
| return self._reindex_with_indexers( | ||
| {axis: [new_index, indexer]}, method=method, fill_value=fill_value, | ||
| - limit=limit, copy=copy).__finalize__(self) | ||
| + limit=limit, copy=copy) | ||
| def _reindex_with_indexers(self, reindexers, method=None, | ||
| fill_value=np.nan, limit=None, copy=False, | ||
| @@ -1716,30 +1704,16 @@ def _reindex_with_indexers(self, reindexers, method=None, | ||
| if index is None: | ||
| continue | ||
| - index = _ensure_index(index) | ||
| - # reindex the axis | ||
| - if method is not None: | ||
| - new_data = new_data.reindex_axis( | ||
| - index, indexer=indexer, method=method, axis=baxis, | ||
| - fill_value=fill_value, limit=limit, copy=copy) | ||
| - | ||
| - elif indexer is not None: | ||
| - # TODO: speed up on homogeneous DataFrame objects | ||
| + index = _ensure_index(index) | ||
| + if indexer is not None: | ||
| indexer = com._ensure_int64(indexer) | ||
| - new_data = new_data.reindex_indexer(index, indexer, axis=baxis, | ||
| - fill_value=fill_value, | ||
| - allow_dups=allow_dups) | ||
| - | ||
| - elif (baxis == 0 and index is not None and | ||
| - index is not new_data.axes[baxis]): | ||
| - new_data = new_data.reindex_items(index, copy=copy, | ||
| - fill_value=fill_value) | ||
| - | ||
| - elif (baxis > 0 and index is not None and | ||
| - index is not new_data.axes[baxis]): | ||
| - new_data = new_data.copy(deep=copy) | ||
| - new_data.set_axis(baxis, index) | ||
| + | ||
immerrr
Contributor
|
||
| + # TODO: speed up on homogeneous DataFrame objects | ||
| + new_data = new_data.reindex_indexer(index, indexer, axis=baxis, | ||
| + fill_value=fill_value, | ||
| + allow_dups=allow_dups, | ||
| + copy=copy) | ||
| if copy and new_data is self._data: | ||
| new_data = new_data.copy() | ||
Oops, something went wrong.
Is copy handled in BlockManager.reindex_indexers ?
I don't think this is well tested and most of the time it should prob copy unless identical indexes