Skip to content

Commit 2c82446

Browse files
authored
CLN: remove fill_tuple kludge (#33310)
1 parent 66a3d17 commit 2c82446

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

pandas/core/internals/blocks.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ def func(x):
12411241
blocks = [self.make_block_same_class(interp_values)]
12421242
return self._maybe_downcast(blocks, downcast)
12431243

1244-
def take_nd(self, indexer, axis: int, new_mgr_locs=None, fill_tuple=None):
1244+
def take_nd(self, indexer, axis: int, new_mgr_locs=None, fill_value=lib.no_default):
12451245
"""
12461246
Take values according to indexer and return them as a block.bb
12471247
@@ -1252,11 +1252,10 @@ def take_nd(self, indexer, axis: int, new_mgr_locs=None, fill_tuple=None):
12521252

12531253
values = self.values
12541254

1255-
if fill_tuple is None:
1255+
if fill_value is lib.no_default:
12561256
fill_value = self.fill_value
12571257
allow_fill = False
12581258
else:
1259-
fill_value = fill_tuple[0]
12601259
allow_fill = True
12611260

12621261
new_values = algos.take_nd(
@@ -1721,14 +1720,14 @@ def to_native_types(self, na_rep="nan", quoting=None, **kwargs):
17211720
# we are expected to return a 2-d ndarray
17221721
return values.reshape(1, len(values))
17231722

1724-
def take_nd(self, indexer, axis: int = 0, new_mgr_locs=None, fill_tuple=None):
1723+
def take_nd(
1724+
self, indexer, axis: int = 0, new_mgr_locs=None, fill_value=lib.no_default
1725+
):
17251726
"""
17261727
Take values according to indexer and return them as a block.
17271728
"""
1728-
if fill_tuple is None:
1729+
if fill_value is lib.no_default:
17291730
fill_value = None
1730-
else:
1731-
fill_value = fill_tuple[0]
17321731

17331732
# axis doesn't matter; we are really a single-dim object
17341733
# but are passed the axis depending on the calling routing

pandas/core/internals/managers.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -1297,14 +1297,14 @@ def reindex_indexer(
12971297
raise IndexError("Requested axis not found in manager")
12981298

12991299
if axis == 0:
1300-
new_blocks = self._slice_take_blocks_ax0(indexer, fill_tuple=(fill_value,))
1300+
new_blocks = self._slice_take_blocks_ax0(indexer, fill_value=fill_value)
13011301
else:
13021302
new_blocks = [
13031303
blk.take_nd(
13041304
indexer,
13051305
axis=axis,
1306-
fill_tuple=(
1307-
fill_value if fill_value is not None else blk.fill_value,
1306+
fill_value=(
1307+
fill_value if fill_value is not None else blk.fill_value
13081308
),
13091309
)
13101310
for blk in self.blocks
@@ -1315,7 +1315,7 @@ def reindex_indexer(
13151315

13161316
return type(self).from_blocks(new_blocks, new_axes)
13171317

1318-
def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
1318+
def _slice_take_blocks_ax0(self, slice_or_indexer, fill_value=lib.no_default):
13191319
"""
13201320
Slice/take blocks along axis=0.
13211321
@@ -1325,7 +1325,7 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
13251325
-------
13261326
new_blocks : list of Block
13271327
"""
1328-
allow_fill = fill_tuple is not None
1328+
allow_fill = fill_value is not lib.no_default
13291329

13301330
sl_type, slobj, sllen = _preprocess_slice_or_indexer(
13311331
slice_or_indexer, self.shape[0], allow_fill=allow_fill
@@ -1337,16 +1337,15 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
13371337
if sl_type in ("slice", "mask"):
13381338
return [blk.getitem_block(slobj, new_mgr_locs=slice(0, sllen))]
13391339
elif not allow_fill or self.ndim == 1:
1340-
if allow_fill and fill_tuple[0] is None:
1340+
if allow_fill and fill_value is None:
13411341
_, fill_value = maybe_promote(blk.dtype)
1342-
fill_tuple = (fill_value,)
13431342

13441343
return [
13451344
blk.take_nd(
13461345
slobj,
13471346
axis=0,
13481347
new_mgr_locs=slice(0, sllen),
1349-
fill_tuple=fill_tuple,
1348+
fill_value=fill_value,
13501349
)
13511350
]
13521351

@@ -1369,8 +1368,7 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
13691368
blocks = []
13701369
for blkno, mgr_locs in libinternals.get_blkno_placements(blknos, group=True):
13711370
if blkno == -1:
1372-
# If we've got here, fill_tuple was not None.
1373-
fill_value = fill_tuple[0]
1371+
# If we've got here, fill_value was not lib.no_default
13741372

13751373
blocks.append(
13761374
self._make_na_block(placement=mgr_locs, fill_value=fill_value)
@@ -1391,10 +1389,7 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
13911389
else:
13921390
blocks.append(
13931391
blk.take_nd(
1394-
blklocs[mgr_locs.indexer],
1395-
axis=0,
1396-
new_mgr_locs=mgr_locs,
1397-
fill_tuple=None,
1392+
blklocs[mgr_locs.indexer], axis=0, new_mgr_locs=mgr_locs,
13981393
)
13991394
)
14001395

0 commit comments

Comments
 (0)