Skip to content

Commit 0e85441

Browse files
ShaharNavehproost
authored andcommitted
DOC/STY: Cleaned pandas/_libs/{internals,interval}.pyx (pandas-dev#30157)
1 parent f59da62 commit 0e85441

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed

pandas/_libs/internals.pyx

+1-6
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ cpdef Py_ssize_t slice_len(
243243
- if ``s.step < 0``, ``s.start`` is not ``None``
244244
245245
Otherwise, the result is unreliable.
246-
247246
"""
248247
cdef:
249248
Py_ssize_t start, stop, step, length
@@ -263,7 +262,6 @@ cdef slice_get_indices_ex(slice slc, Py_ssize_t objlen=PY_SSIZE_T_MAX):
263262
264263
If `objlen` is not specified, slice must be bounded, otherwise the result
265264
will be wrong.
266-
267265
"""
268266
cdef:
269267
Py_ssize_t start, stop, step, length
@@ -365,7 +363,6 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
365363
Returns
366364
-------
367365
iter : iterator of (int, slice or array)
368-
369366
"""
370367
# There's blkno in this function's name because it's used in block &
371368
# blockno handling.
@@ -436,18 +433,16 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
436433

437434
def get_blkno_placements(blknos, group: bool = True):
438435
"""
439-
440436
Parameters
441437
----------
442438
blknos : array of int64
443-
group : bool
439+
group : bool, default True
444440
445441
Returns
446442
-------
447443
iterator
448444
yield (BlockPlacement, blkno)
449445
"""
450-
451446
blknos = ensure_int64(blknos)
452447

453448
for blkno, indexer in get_blkno_indexers(blknos, group):

pandas/_libs/interval.pyx

+24-33
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ cdef class IntervalMixin:
4141
Returns
4242
-------
4343
bool
44-
``True`` if the Interval is closed on the left-side, else
45-
``False``.
44+
True if the Interval is closed on the left-side.
4645
"""
4746
return self.closed in ('left', 'both')
4847

@@ -56,8 +55,7 @@ cdef class IntervalMixin:
5655
Returns
5756
-------
5857
bool
59-
``True`` if the Interval is closed on the left-side, else
60-
``False``.
58+
True if the Interval is closed on the left-side.
6159
"""
6260
return self.closed in ('right', 'both')
6361

@@ -71,8 +69,7 @@ cdef class IntervalMixin:
7169
Returns
7270
-------
7371
bool
74-
``True`` if the Interval is closed on the left-side, else
75-
``False``.
72+
True if the Interval is closed on the left-side.
7673
"""
7774
return not self.closed_left
7875

@@ -86,8 +83,7 @@ cdef class IntervalMixin:
8683
Returns
8784
-------
8885
bool
89-
``True`` if the Interval is closed on the left-side, else
90-
``False``.
86+
True if the Interval is closed on the left-side.
9187
"""
9288
return not self.closed_right
9389

@@ -308,16 +304,14 @@ cdef class Interval(IntervalMixin):
308304
self._validate_endpoint(right)
309305

310306
if closed not in _VALID_CLOSED:
311-
msg = f"invalid option for 'closed': {closed}"
312-
raise ValueError(msg)
307+
raise ValueError(f"invalid option for 'closed': {closed}")
313308
if not left <= right:
314-
raise ValueError('left side of interval must be <= right side')
309+
raise ValueError("left side of interval must be <= right side")
315310
if (isinstance(left, Timestamp) and
316311
not tz_compare(left.tzinfo, right.tzinfo)):
317312
# GH 18538
318-
msg = (f"left and right must have the same time zone, got "
319-
f"{repr(left.tzinfo)}' and {repr(right.tzinfo)}")
320-
raise ValueError(msg)
313+
raise ValueError("left and right must have the same time zone, got "
314+
f"{repr(left.tzinfo)}' and {repr(right.tzinfo)}")
321315
self.left = left
322316
self.right = right
323317
self.closed = closed
@@ -326,16 +320,15 @@ cdef class Interval(IntervalMixin):
326320
# GH 23013
327321
if not (is_integer_object(endpoint) or is_float_object(endpoint) or
328322
isinstance(endpoint, (Timestamp, Timedelta))):
329-
msg = ("Only numeric, Timestamp and Timedelta endpoints "
330-
"are allowed when constructing an Interval.")
331-
raise ValueError(msg)
323+
raise ValueError("Only numeric, Timestamp and Timedelta endpoints "
324+
"are allowed when constructing an Interval.")
332325

333326
def __hash__(self):
334327
return hash((self.left, self.right, self.closed))
335328

336329
def __contains__(self, key):
337330
if _interval_like(key):
338-
raise TypeError('__contains__ not defined for two intervals')
331+
raise TypeError("__contains__ not defined for two intervals")
339332
return ((self.left < key if self.open_left else self.left <= key) and
340333
(key < self.right if self.open_right else key <= self.right))
341334

@@ -358,7 +351,7 @@ cdef class Interval(IntervalMixin):
358351
name = type(self).__name__
359352
other = type(other).__name__
360353
op_str = {Py_LT: '<', Py_LE: '<=', Py_GT: '>', Py_GE: '>='}[op]
361-
raise TypeError(f'unorderable types: {name}() {op_str} {other}()')
354+
raise TypeError(f"unorderable types: {name}() {op_str} {other}()")
362355

363356
def __reduce__(self):
364357
args = (self.left, self.right, self.closed)
@@ -437,12 +430,12 @@ cdef class Interval(IntervalMixin):
437430
Parameters
438431
----------
439432
other : Interval
440-
The interval to check against for an overlap.
433+
Interval to check against for an overlap.
441434
442435
Returns
443436
-------
444437
bool
445-
``True`` if the two intervals overlap, else ``False``.
438+
True if the two intervals overlap.
446439
447440
See Also
448441
--------
@@ -473,8 +466,8 @@ cdef class Interval(IntervalMixin):
473466
False
474467
"""
475468
if not isinstance(other, Interval):
476-
msg = f'`other` must be an Interval, got {type(other).__name__}'
477-
raise TypeError(msg)
469+
raise TypeError("`other` must be an Interval, "
470+
f"got {type(other).__name__}")
478471

479472
# equality is okay if both endpoints are closed (overlap at a point)
480473
op1 = le if (self.closed_left and other.closed_right) else lt
@@ -494,20 +487,19 @@ def intervals_to_interval_bounds(ndarray intervals,
494487
Parameters
495488
----------
496489
intervals : ndarray
497-
object array of Intervals / nulls
490+
Object array of Intervals / nulls.
498491
499-
validate_closed: boolean, default True
500-
boolean indicating if all intervals must be closed on the same side.
492+
validate_closed: bool, default True
493+
Boolean indicating if all intervals must be closed on the same side.
501494
Mismatching closed will raise if True, else return None for closed.
502495
503496
Returns
504497
-------
505-
tuples (left: ndarray object array,
506-
right: ndarray object array,
507-
closed: str)
508-
498+
tuple of tuples
499+
left : (ndarray, object, array)
500+
right : (ndarray, object, array)
501+
closed: str
509502
"""
510-
511503
cdef:
512504
object closed = None, interval
513505
int64_t n = len(intervals)
@@ -536,8 +528,7 @@ def intervals_to_interval_bounds(ndarray intervals,
536528
elif closed != interval.closed:
537529
closed = None
538530
if validate_closed:
539-
msg = 'intervals must all be closed on the same side'
540-
raise ValueError(msg)
531+
raise ValueError("intervals must all be closed on the same side")
541532

542533
return left, right, closed
543534

0 commit comments

Comments
 (0)