Skip to content

Commit ee07ee0

Browse files
Fix styling issues.
1 parent 2bb9fbb commit ee07ee0

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

pandas/core/indexing.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pandas._config.config import option_context
1818

1919
from pandas._libs.indexing import NDFrameIndexerBase
20-
from pandas._libs.lib import item_from_zerodim, infer_dtype
20+
from pandas._libs.lib import item_from_zerodim
2121
from pandas.errors import (
2222
AbstractMethodError,
2323
InvalidIndexError,
@@ -966,11 +966,12 @@ def _validate_key(self, key, axis: int):
966966
# slice of integers (only if in the labels)
967967
# boolean not in slice and with boolean index
968968
if not is_bool_dtype(self.obj.index) and isinstance(key, bool):
969-
raise TypeError('Boolean label can not be used without a boolean index')
969+
raise TypeError("Boolean label can not be used without a boolean index")
970970

971-
if isinstance(key, slice) and \
972-
(isinstance(key.start, bool) or isinstance(key.stop, bool)):
973-
raise TypeError('Boolean values can not be used in a slice')
971+
if isinstance(key, slice) and (
972+
isinstance(key.start, bool) or isinstance(key.stop, bool)
973+
):
974+
raise TypeError("Boolean values can not be used in a slice")
974975

975976
def _has_valid_setitem_indexer(self, indexer) -> bool:
976977
return True

pandas/tests/indexing/test_loc.py

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
DatetimeIndex,
2424
Index,
2525
IndexSlice,
26+
Int64Index,
2627
MultiIndex,
2728
Period,
2829
RangeIndex,
@@ -37,7 +38,6 @@
3738
to_timedelta,
3839
)
3940
import pandas._testing as tm
40-
from pandas.errors import InvalidIndexError
4141
from pandas.api.types import is_scalar
4242
from pandas.tests.indexing.common import Base
4343

@@ -2092,56 +2092,51 @@ class TestLocBooleanLabelsAndSlices(Base):
20922092
@pytest.mark.parametrize(
20932093
"index",
20942094
[
2095-
pd.RangeIndex(4),
2096-
pd.Int64Index(range(4)),
2097-
pd.UInt64Index(range(4)),
2095+
RangeIndex(4),
2096+
Int64Index(range(4)),
2097+
UInt64Index(range(4)),
20982098
pd.Float64Index(range(4)),
2099-
pd.CategoricalIndex(range(4)),
2100-
pd.date_range(0, periods=4, freq="ns"),
2101-
pd.timedelta_range(0, periods=4, freq="ns"),
2099+
CategoricalIndex(range(4)),
2100+
date_range(0, periods=4, freq="ns"),
2101+
timedelta_range(0, periods=4, freq="ns"),
21022102
pd.interval_range(0, periods=4),
2103-
pd.Index([0, 1, 2, 3], dtype=object),
2104-
pd.MultiIndex.from_product([[0, 1], [0, 1]]),
2105-
pd.period_range("2018Q1", freq="Q", periods=4)
2106-
]
2103+
Index([0, 1, 2, 3], dtype=object),
2104+
MultiIndex.from_product([[0, 1], [0, 1]]),
2105+
pd.period_range("2018Q1", freq="Q", periods=4),
2106+
],
21072107
)
21082108
def test_loc_bool_incompatible_index_raises(self, index, frame_or_series):
21092109
# GH20432
2110-
message = 'Boolean label can not be used without a boolean index'
2110+
message = "Boolean label can not be used without a boolean index"
21112111
obj = frame_or_series(range(4), index=index)
21122112
with pytest.raises(TypeError, match=message):
21132113
obj.loc[True]
21142114

2115-
@pytest.mark.parametrize(
2116-
"index",
2117-
[
2118-
pd.Index([True, False], dtype="boolean")
2119-
]
2120-
)
2115+
@pytest.mark.parametrize("index", [Index([True, False], dtype="boolean")])
21212116
def test_loc_bool_should_not_raise(self, index, frame_or_series):
21222117
obj = frame_or_series(range(2), index=index)
21232118
obj.loc[True]
21242119

21252120
@pytest.mark.parametrize(
21262121
"index",
21272122
[
2128-
pd.RangeIndex(4),
2129-
pd.Int64Index(range(4)),
2130-
pd.UInt64Index(range(4)),
2123+
RangeIndex(4),
2124+
Int64Index(range(4)),
2125+
UInt64Index(range(4)),
21312126
pd.Float64Index(range(4)),
2132-
pd.CategoricalIndex(range(4)),
2133-
pd.date_range(0, periods=4, freq="ns"),
2134-
pd.timedelta_range(0, periods=4, freq="ns"),
2127+
CategoricalIndex(range(4)),
2128+
date_range(0, periods=4, freq="ns"),
2129+
timedelta_range(0, periods=4, freq="ns"),
21352130
pd.interval_range(0, periods=4),
2136-
pd.Index([0, 1, 2, 3], dtype=object),
2137-
pd.Index([True, True, False, False], dtype=object),
2138-
pd.MultiIndex.from_product([[0, 1], [0, 1]]),
2139-
pd.period_range("2018Q1", freq="Q", periods=4)
2140-
]
2131+
Index([0, 1, 2, 3], dtype=object),
2132+
Index([True, True, False, False], dtype=object),
2133+
MultiIndex.from_product([[0, 1], [0, 1]]),
2134+
pd.period_range("2018Q1", freq="Q", periods=4),
2135+
],
21412136
)
21422137
def test_loc_bool_slice_raises(self, index, frame_or_series):
21432138
# GH20432
2144-
message = 'Boolean values can not be used in a slice'
2139+
message = "Boolean values can not be used in a slice"
21452140
obj = frame_or_series(range(4), index=index)
21462141
with pytest.raises(TypeError, match=message):
21472142
obj.loc[True:False]

0 commit comments

Comments
 (0)