Skip to content

Commit 402de2e

Browse files
jbrockmendeljreback
authored andcommitted
remove BlockManager.reindex (#19338)
1 parent 7e429d8 commit 402de2e

File tree

3 files changed

+14
-41
lines changed

3 files changed

+14
-41
lines changed

pandas/core/internals.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,42 +4407,6 @@ def _blklocs(self):
44074407
""" compat with BlockManager """
44084408
return None
44094409

4410-
def reindex(self, new_axis, indexer=None, method=None, fill_value=None,
4411-
limit=None, copy=True):
4412-
# if we are the same and don't copy, just return
4413-
if self.index.equals(new_axis):
4414-
if copy:
4415-
return self.copy(deep=True)
4416-
else:
4417-
return self
4418-
4419-
values = self._block.get_values()
4420-
4421-
if indexer is None:
4422-
indexer = self.items.get_indexer_for(new_axis)
4423-
4424-
if fill_value is None:
4425-
fill_value = np.nan
4426-
4427-
new_values = algos.take_1d(values, indexer, fill_value=fill_value)
4428-
4429-
# fill if needed
4430-
if method is not None or limit is not None:
4431-
new_values = missing.interpolate_2d(new_values,
4432-
method=method,
4433-
limit=limit,
4434-
fill_value=fill_value)
4435-
4436-
if self._block.is_sparse:
4437-
make_block = self._block.make_block_same_class
4438-
4439-
block = make_block(new_values, copy=copy,
4440-
placement=slice(0, len(new_axis)))
4441-
4442-
mgr = SingleBlockManager(block, new_axis)
4443-
mgr._consolidate_inplace()
4444-
return mgr
4445-
44464410
def get_slice(self, slobj, axis=0):
44474411
if axis >= self.ndim:
44484412
raise IndexError("Requested axis not found in manager")

pandas/core/series.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,13 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
197197
elif isinstance(data, SingleBlockManager):
198198
if index is None:
199199
index = data.index
200-
else:
201-
data = data.reindex(index, copy=copy)
200+
elif not data.index.equals(index) or copy:
201+
# GH#19275 SingleBlockManager input should only be called
202+
# internally
203+
raise AssertionError('Cannot pass both SingleBlockManager '
204+
'`data` argument and a different '
205+
'`index` argument. `copy` must '
206+
'be False.')
202207
elif isinstance(data, Categorical):
203208
# GH12574: Allow dtype=category only, otherwise error
204209
if ((dtype is not None) and

pandas/core/sparse/series.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,13 @@ def __init__(self, data=None, index=None, sparse_index=None, kind='block',
166166
data = data.astype(dtype)
167167
if index is None:
168168
index = data.index.view()
169-
else:
170-
171-
data = data.reindex(index, copy=False)
169+
elif not data.index.equals(index) or copy: # pragma: no cover
170+
# GH#19275 SingleBlockManager input should only be called
171+
# internally
172+
raise AssertionError('Cannot pass both SingleBlockManager '
173+
'`data` argument and a different '
174+
'`index` argument. `copy` must '
175+
'be False.')
172176

173177
else:
174178
length = len(index)

0 commit comments

Comments
 (0)