Skip to content

Commit f4752fc

Browse files
jbrockmendeljreback
authored andcommitted
CLN: remove unnecessary fastpath, transpose kwargs in internals (#27260)
1 parent 679dbd0 commit f4752fc

File tree

4 files changed

+23
-96
lines changed

4 files changed

+23
-96
lines changed

pandas/core/generic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9175,7 +9175,6 @@ def _where(
91759175
errors=errors,
91769176
try_cast=try_cast,
91779177
axis=block_axis,
9178-
transpose=self._AXIS_REVERSED,
91799178
)
91809179

91819180
return self._constructor(new_data).__finalize__(self)

pandas/core/internals/blocks.py

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _check_ndim(self, values, ndim):
143143
ndim = values.ndim
144144

145145
if self._validate_ndim and values.ndim != ndim:
146-
msg = "Wrong number of dimensions. values.ndim != ndim " "[{} != {}]"
146+
msg = "Wrong number of dimensions. values.ndim != ndim [{} != {}]"
147147
raise ValueError(msg.format(values.ndim, ndim))
148148

149149
return ndim
@@ -259,7 +259,7 @@ def make_block_same_class(self, values, placement=None, ndim=None, dtype=None):
259259
if dtype is not None:
260260
# issue 19431 fastparquet is passing this
261261
warnings.warn(
262-
"dtype argument is deprecated, will be removed " "in a future release.",
262+
"dtype argument is deprecated, will be removed in a future release.",
263263
FutureWarning,
264264
)
265265
if placement is None:
@@ -399,7 +399,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
399399
raise ValueError("Limit must be greater than 0")
400400
if self.ndim > 2:
401401
raise NotImplementedError(
402-
"number of dimensions for 'fillna' " "is currently limited to 2"
402+
"number of dimensions for 'fillna' is currently limited to 2"
403403
)
404404
mask[mask.cumsum(self.ndim - 1) > limit] = False
405405

@@ -533,7 +533,7 @@ def downcast(self, dtypes=None):
533533

534534
if not (dtypes == "infer" or isinstance(dtypes, dict)):
535535
raise ValueError(
536-
"downcast must have a dictionary or 'infer' as " "its argument"
536+
"downcast must have a dictionary or 'infer' as its argument"
537537
)
538538

539539
# operate column-by-column
@@ -1025,7 +1025,7 @@ def putmask(self, mask, new, align=True, inplace=False, axis=0, transpose=False)
10251025
or mask[mask].shape[-1] == len(new)
10261026
or len(new) == 1
10271027
):
1028-
raise ValueError("cannot assign mismatch " "length to masked array")
1028+
raise ValueError("cannot assign mismatch length to masked array")
10291029

10301030
np.putmask(new_values, mask, new)
10311031

@@ -1381,16 +1381,7 @@ def shift(self, periods, axis=0, fill_value=None):
13811381

13821382
return [self.make_block(new_values)]
13831383

1384-
def where(
1385-
self,
1386-
other,
1387-
cond,
1388-
align=True,
1389-
errors="raise",
1390-
try_cast=False,
1391-
axis=0,
1392-
transpose=False,
1393-
):
1384+
def where(self, other, cond, align=True, errors="raise", try_cast=False, axis=0):
13941385
"""
13951386
evaluate the block; return result block(s) from the result
13961387
@@ -1402,10 +1393,7 @@ def where(
14021393
errors : str, {'raise', 'ignore'}, default 'raise'
14031394
- ``raise`` : allow exceptions to be raised
14041395
- ``ignore`` : suppress exceptions. On error return original object
1405-
14061396
axis : int
1407-
transpose : boolean
1408-
Set to True if self is stored with axes reversed
14091397
14101398
Returns
14111399
-------
@@ -1414,6 +1402,7 @@ def where(
14141402
import pandas.core.computation.expressions as expressions
14151403

14161404
assert errors in ["raise", "ignore"]
1405+
transpose = self.ndim == 2
14171406

14181407
values = self.values
14191408
orig_other = other
@@ -1432,7 +1421,7 @@ def where(
14321421
cond = cond.T
14331422

14341423
if not hasattr(cond, "shape"):
1435-
raise ValueError("where must have a condition that is ndarray " "like")
1424+
raise ValueError("where must have a condition that is ndarray like")
14361425

14371426
# our where function
14381427
def func(cond, values, other):
@@ -1473,7 +1462,6 @@ def func(cond, values, other):
14731462
errors=errors,
14741463
try_cast=try_cast,
14751464
axis=axis,
1476-
transpose=transpose,
14771465
)
14781466
return self._maybe_downcast(blocks, "infer")
14791467

@@ -1917,7 +1905,7 @@ def _slice(self, slicer):
19171905

19181906
if isinstance(slicer, tuple) and len(slicer) == 2:
19191907
if not com.is_null_slice(slicer[0]):
1920-
raise AssertionError("invalid slicing for a 1-ndim " "categorical")
1908+
raise AssertionError("invalid slicing for a 1-ndim categorical")
19211909
slicer = slicer[1]
19221910

19231911
return self.values[slicer]
@@ -2004,16 +1992,7 @@ def shift(
20041992
)
20051993
]
20061994

2007-
def where(
2008-
self,
2009-
other,
2010-
cond,
2011-
align=True,
2012-
errors="raise",
2013-
try_cast=False,
2014-
axis=0,
2015-
transpose=False,
2016-
):
1995+
def where(self, other, cond, align=True, errors="raise", try_cast=False, axis=0):
20171996
if isinstance(other, ABCDataFrame):
20181997
# ExtensionArrays are 1-D, so if we get here then
20191998
# `other` should be a DataFrame with a single column.
@@ -2321,9 +2300,7 @@ def _try_coerce_args(self, other):
23212300
elif isinstance(other, (datetime, np.datetime64, date)):
23222301
other = self._box_func(other)
23232302
if getattr(other, "tz") is not None:
2324-
raise TypeError(
2325-
"cannot coerce a Timestamp with a tz on a " "naive Block"
2326-
)
2303+
raise TypeError("cannot coerce a Timestamp with a tz on a naive Block")
23272304
other = other.asm8.view("i8")
23282305
elif hasattr(other, "dtype") and is_datetime64_dtype(other):
23292306
other = other.astype("i8", copy=False).view("i8")
@@ -2997,7 +2974,7 @@ def _replace_single(
29972974
# only one will survive
29982975
if to_rep_re and regex_re:
29992976
raise AssertionError(
3000-
"only one of to_replace and regex can be " "regex compilable"
2977+
"only one of to_replace and regex can be regex compilable"
30012978
)
30022979

30032980
# if regex was passed as something that can be a regex (rather than a
@@ -3181,16 +3158,7 @@ def concat_same_type(self, to_concat, placement=None):
31813158
values, placement=placement or slice(0, len(values), 1), ndim=self.ndim
31823159
)
31833160

3184-
def where(
3185-
self,
3186-
other,
3187-
cond,
3188-
align=True,
3189-
errors="raise",
3190-
try_cast=False,
3191-
axis=0,
3192-
transpose=False,
3193-
):
3161+
def where(self, other, cond, align=True, errors="raise", try_cast=False, axis=0):
31943162
# TODO(CategoricalBlock.where):
31953163
# This can all be deleted in favor of ExtensionBlock.where once
31963164
# we enforce the deprecation.
@@ -3205,19 +3173,11 @@ def where(
32053173
)
32063174
try:
32073175
# Attempt to do preserve categorical dtype.
3208-
result = super().where(
3209-
other, cond, align, errors, try_cast, axis, transpose
3210-
)
3176+
result = super().where(other, cond, align, errors, try_cast, axis)
32113177
except (TypeError, ValueError):
32123178
warnings.warn(object_msg, FutureWarning, stacklevel=6)
32133179
result = self.astype(object).where(
3214-
other,
3215-
cond,
3216-
align=align,
3217-
errors=errors,
3218-
try_cast=try_cast,
3219-
axis=axis,
3220-
transpose=transpose,
3180+
other, cond, align=align, errors=errors, try_cast=try_cast, axis=axis
32213181
)
32223182
return result
32233183

@@ -3286,7 +3246,7 @@ def make_block(values, placement, klass=None, ndim=None, dtype=None, fastpath=No
32863246
if fastpath is not None:
32873247
# GH#19265 pyarrow is passing this
32883248
warnings.warn(
3289-
"fastpath argument is deprecated, will be removed " "in a future release.",
3249+
"fastpath argument is deprecated, will be removed in a future release.",
32903250
FutureWarning,
32913251
)
32923252
if klass is None:

pandas/core/internals/managers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def _consolidate_inplace(self):
936936
self._known_consolidated = True
937937
self._rebuild_blknos_and_blklocs()
938938

939-
def get(self, item, fastpath=True):
939+
def get(self, item):
940940
"""
941941
Return values for selected item (ndarray or BlockManager).
942942
"""
@@ -954,7 +954,7 @@ def get(self, item, fastpath=True):
954954
else:
955955
raise ValueError("cannot label index with a null key")
956956

957-
return self.iget(loc, fastpath=fastpath)
957+
return self.iget(loc)
958958
else:
959959

960960
if isna(item):
@@ -965,18 +965,18 @@ def get(self, item, fastpath=True):
965965
new_axis=self.items[indexer], indexer=indexer, axis=0, allow_dups=True
966966
)
967967

968-
def iget(self, i, fastpath=True):
968+
def iget(self, i):
969969
"""
970-
Return the data as a SingleBlockManager if fastpath=True and possible
970+
Return the data as a SingleBlockManager if possible
971971
972972
Otherwise return as a ndarray
973973
"""
974974
block = self.blocks[self._blknos[i]]
975975
values = block.iget(self._blklocs[i])
976-
if not fastpath or values.ndim != 1:
976+
if values.ndim != 1:
977977
return values
978978

979-
# fastpath shortcut for select a single-dim from a 2-dim BM
979+
# shortcut for select a single-dim from a 2-dim BM
980980
return SingleBlockManager(
981981
[
982982
block.make_block_same_class(

pandas/tests/internals/test_internals.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ def test_get(self):
418418
block = make_block(values=values.copy(), placement=np.arange(3))
419419
mgr = BlockManager(blocks=[block], axes=[cols, np.arange(3)])
420420

421-
assert_almost_equal(mgr.get("a", fastpath=False), values[0])
422-
assert_almost_equal(mgr.get("b", fastpath=False), values[1])
423-
assert_almost_equal(mgr.get("c", fastpath=False), values[2])
424421
assert_almost_equal(mgr.get("a").internal_values(), values[0])
425422
assert_almost_equal(mgr.get("b").internal_values(), values[1])
426423
assert_almost_equal(mgr.get("c").internal_values(), values[2])
@@ -701,6 +698,7 @@ def test_consolidate_ordering_issues(self, mgr):
701698
)
702699

703700
def test_reindex_index(self):
701+
# TODO: should this be pytest.skip?
704702
pass
705703

706704
def test_reindex_items(self):
@@ -710,18 +708,6 @@ def test_reindex_items(self):
710708
reindexed = mgr.reindex_axis(["g", "c", "a", "d"], axis=0)
711709
assert reindexed.nblocks == 2
712710
tm.assert_index_equal(reindexed.items, pd.Index(["g", "c", "a", "d"]))
713-
assert_almost_equal(
714-
mgr.get("g", fastpath=False), reindexed.get("g", fastpath=False)
715-
)
716-
assert_almost_equal(
717-
mgr.get("c", fastpath=False), reindexed.get("c", fastpath=False)
718-
)
719-
assert_almost_equal(
720-
mgr.get("a", fastpath=False), reindexed.get("a", fastpath=False)
721-
)
722-
assert_almost_equal(
723-
mgr.get("d", fastpath=False), reindexed.get("d", fastpath=False)
724-
)
725711
assert_almost_equal(
726712
mgr.get("g").internal_values(), reindexed.get("g").internal_values()
727713
)
@@ -747,18 +733,12 @@ def test_get_numeric_data(self):
747733
tm.assert_index_equal(
748734
numeric.items, pd.Index(["int", "float", "complex", "bool"])
749735
)
750-
assert_almost_equal(
751-
mgr.get("float", fastpath=False), numeric.get("float", fastpath=False)
752-
)
753736
assert_almost_equal(
754737
mgr.get("float").internal_values(), numeric.get("float").internal_values()
755738
)
756739

757740
# Check sharing
758741
numeric.set("float", np.array([100.0, 200.0, 300.0]))
759-
assert_almost_equal(
760-
mgr.get("float", fastpath=False), np.array([100.0, 200.0, 300.0])
761-
)
762742
assert_almost_equal(
763743
mgr.get("float").internal_values(), np.array([100.0, 200.0, 300.0])
764744
)
@@ -768,9 +748,6 @@ def test_get_numeric_data(self):
768748
numeric.items, pd.Index(["int", "float", "complex", "bool"])
769749
)
770750
numeric2.set("float", np.array([1000.0, 2000.0, 3000.0]))
771-
assert_almost_equal(
772-
mgr.get("float", fastpath=False), np.array([100.0, 200.0, 300.0])
773-
)
774751
assert_almost_equal(
775752
mgr.get("float").internal_values(), np.array([100.0, 200.0, 300.0])
776753
)
@@ -785,27 +762,18 @@ def test_get_bool_data(self):
785762

786763
bools = mgr.get_bool_data()
787764
tm.assert_index_equal(bools.items, pd.Index(["bool"]))
788-
assert_almost_equal(
789-
mgr.get("bool", fastpath=False), bools.get("bool", fastpath=False)
790-
)
791765
assert_almost_equal(
792766
mgr.get("bool").internal_values(), bools.get("bool").internal_values()
793767
)
794768

795769
bools.set("bool", np.array([True, False, True]))
796-
tm.assert_numpy_array_equal(
797-
mgr.get("bool", fastpath=False), np.array([True, False, True])
798-
)
799770
tm.assert_numpy_array_equal(
800771
mgr.get("bool").internal_values(), np.array([True, False, True])
801772
)
802773

803774
# Check sharing
804775
bools2 = mgr.get_bool_data(copy=True)
805776
bools2.set("bool", np.array([False, True, False]))
806-
tm.assert_numpy_array_equal(
807-
mgr.get("bool", fastpath=False), np.array([True, False, True])
808-
)
809777
tm.assert_numpy_array_equal(
810778
mgr.get("bool").internal_values(), np.array([True, False, True])
811779
)

0 commit comments

Comments
 (0)