Skip to content

Commit 067b830

Browse files
committed
ruff
1 parent 8ded755 commit 067b830

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

pandas/core/dtypes/inference.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def is_named_tuple(obj: object) -> bool:
376376
return isinstance(obj, abc.Sequence) and hasattr(obj, "_fields")
377377

378378

379-
def is_hashable(obj: object, allow_slice: bool=None) -> TypeGuard[Hashable]:
379+
def is_hashable(obj: object, allow_slice: bool | None = None) -> TypeGuard[Hashable]:
380380
"""
381381
Return True if hash(obj) will succeed, False otherwise.
382382
@@ -391,9 +391,10 @@ def is_hashable(obj: object, allow_slice: bool=None) -> TypeGuard[Hashable]:
391391
obj : object
392392
The object to check for hashability. Any Python object can be passed here.
393393
allow_slice: bool or None
394-
- If True: return True if the object is hashable (including slices).
395-
- If False: return True if the object is hashable and not a slice.
396-
- If None: return True if the object is hashable. without checking for slice type.
394+
If True: return True if the object is hashable (including slices).
395+
If False: return True if the object is hashable and not a slice.
396+
If None: return True if the object is hashable. without checking
397+
for slice type.
397398
398399
Returns
399400
-------
@@ -429,7 +430,7 @@ def is_hashable(obj: object, allow_slice: bool=None) -> TypeGuard[Hashable]:
429430
def _contains_slice(x: object) -> bool:
430431
# Check if object is a slice or a tuple containing a slice
431432
if isinstance(x, tuple):
432-
return any(isinstance(v, slice) for v in x)
433+
return any(isinstance(v, slice) for v in x)
433434
elif isinstance(x, slice):
434435
return True
435436
return False
@@ -438,7 +439,7 @@ def _contains_slice(x: object) -> bool:
438439
hash(obj)
439440
except TypeError:
440441
return False
441-
else:
442+
else:
442443
if allow_slice is False and _contains_slice(obj):
443444
return False
444445
return True

pandas/tests/dtypes/test_inference.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ class UnhashableClass1:
451451
class UnhashableClass2:
452452
def __hash__(self):
453453
raise TypeError("Not hashable")
454-
454+
455455
class HashableSlice:
456456
def __init__(self, start, stop, step=None):
457457
self.slice = slice(start, stop, step)
@@ -463,8 +463,10 @@ def __hash__(self):
463463
return hash((self.slice.start, self.slice.stop, self.slice.step))
464464

465465
def __repr__(self):
466-
return f"HashableSlice({self.slice.start}, {self.slice.stop}, {self.slice.step})"
467-
466+
return (
467+
f"HashableSlice({self.slice.start}, {self.slice.stop}, "
468+
f"{self.slice.step})"
469+
)
468470

469471
hashable = (1, 3.14, np.float64(3.14), "a", (), (1,), HashableClass())
470472
not_hashable = ([], UnhashableClass1(), slice(1, 2, 3))
@@ -486,9 +488,9 @@ def __repr__(self):
486488
assert not inference.is_hashable(i, allow_slice=False)
487489
for i in hashable_slice:
488490
assert inference.is_hashable(i)
489-
assert inference.is_hashable(i, allow_slice=True)
491+
assert inference.is_hashable(i, allow_slice=True)
490492
assert inference.is_hashable(i, allow_slice=False)
491-
493+
492494
assert not inference.is_hashable(tuple_with_slice)
493495
assert not inference.is_hashable(tuple_with_slice, allow_slice=True)
494496
assert not inference.is_hashable(tuple_with_slice, allow_slice=False)

0 commit comments

Comments
 (0)