Skip to content

Commit e0e778d

Browse files
author
MomIsBestFriend
committed
STY: Underscores for long numbers
1 parent b9f26e2 commit e0e778d

File tree

11 files changed

+128
-101
lines changed

11 files changed

+128
-101
lines changed

pandas/_libs/testing.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ cpdef assert_almost_equal(a, b,
6666
check_less_precise=False,
6767
bint check_dtype=True,
6868
obj=None, lobj=None, robj=None):
69-
"""Check that left and right objects are almost equal.
69+
"""
70+
Check that left and right objects are almost equal.
7071
7172
Parameters
7273
----------
@@ -89,7 +90,6 @@ cpdef assert_almost_equal(a, b,
8990
Specify right object name being compared, internally used to show
9091
appropriate assertion message
9192
"""
92-
9393
cdef:
9494
int decimal
9595
double diff = 0.0
@@ -127,9 +127,9 @@ cpdef assert_almost_equal(a, b,
127127
# classes can't be the same, to raise error
128128
assert_class_equal(a, b, obj=obj)
129129

130-
assert has_length(a) and has_length(b), (
131-
f"Can't compare objects without length, one or both is invalid: "
132-
f"({a}, {b})")
130+
assert has_length(a) and has_length(b), ("Can't compare objects without "
131+
"length, one or both is invalid: "
132+
f"({a}, {b})")
133133

134134
if a_is_ndarray and b_is_ndarray:
135135
na, nb = a.size, b.size
@@ -157,7 +157,7 @@ cpdef assert_almost_equal(a, b,
157157
else:
158158
r = None
159159

160-
raise_assert_detail(obj, f'{obj} length are different', na, nb, r)
160+
raise_assert_detail(obj, f"{obj} length are different", na, nb, r)
161161

162162
for i in xrange(len(a)):
163163
try:
@@ -169,8 +169,8 @@ cpdef assert_almost_equal(a, b,
169169

170170
if is_unequal:
171171
from pandas.util.testing import raise_assert_detail
172-
msg = (f'{obj} values are different '
173-
f'({np.round(diff * 100.0 / na, 5)} %)')
172+
msg = (f"{obj} values are different "
173+
f"({np.round(diff * 100.0 / na, 5)} %)")
174174
raise_assert_detail(obj, msg, lobj, robj)
175175

176176
return True

pandas/core/algorithms.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,15 @@ def isin(comps, values) -> np.ndarray:
391391
ndarray[bool]
392392
Same length as `comps`.
393393
"""
394-
395394
if not is_list_like(comps):
396395
raise TypeError(
397-
"only list-like objects are allowed to be passed"
398-
f" to isin(), you passed a [{type(comps).__name__}]"
396+
"only list-like objects are allowed to be passed "
397+
f"to isin(), you passed a [{type(comps).__name__}]"
399398
)
400399
if not is_list_like(values):
401400
raise TypeError(
402-
"only list-like objects are allowed to be passed"
403-
f" to isin(), you passed a [{type(values).__name__}]"
401+
"only list-like objects are allowed to be passed "
402+
f"to isin(), you passed a [{type(values).__name__}]"
404403
)
405404

406405
if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
@@ -421,7 +420,7 @@ def isin(comps, values) -> np.ndarray:
421420

422421
# GH16012
423422
# Ensure np.in1d doesn't get object types or it *may* throw an exception
424-
if len(comps) > 1000000 and not is_object_dtype(comps):
423+
if len(comps) > 1_000_000 and not is_object_dtype(comps):
425424
f = np.in1d
426425
elif is_integer_dtype(comps):
427426
try:
@@ -833,8 +832,8 @@ def mode(values, dropna: bool = True) -> ABCSeries:
833832
result = f(values, dropna=dropna)
834833
try:
835834
result = np.sort(result)
836-
except TypeError as e:
837-
warn(f"Unable to sort modes: {e}")
835+
except TypeError as err:
836+
warn(f"Unable to sort modes: {err}")
838837

839838
result = _reconstruct_data(result, original.dtype, original)
840839
return Series(result)
@@ -1019,7 +1018,8 @@ def quantile(x, q, interpolation_method="fraction"):
10191018
values = np.sort(x)
10201019

10211020
def _interpolate(a, b, fraction):
1022-
"""Returns the point at the given fraction between a and b, where
1021+
"""
1022+
Returns the point at the given fraction between a and b, where
10231023
'fraction' must be between 0 and 1.
10241024
"""
10251025
return a + (b - a) * fraction
@@ -1192,7 +1192,8 @@ def compute(self, method):
11921192
)
11931193

11941194
def get_indexer(current_indexer, other_indexer):
1195-
"""Helper function to concat `current_indexer` and `other_indexer`
1195+
"""
1196+
Helper function to concat `current_indexer` and `other_indexer`
11961197
depending on `method`
11971198
"""
11981199
if method == "nsmallest":
@@ -1660,7 +1661,7 @@ def take_nd(
16601661

16611662
def take_2d_multi(arr, indexer, fill_value=np.nan):
16621663
"""
1663-
Specialized Cython take which sets NaN values in one pass
1664+
Specialized Cython take which sets NaN values in one pass.
16641665
"""
16651666
# This is only called from one place in DataFrame._reindex_multi,
16661667
# so we know indexer is well-behaved.
@@ -1988,8 +1989,8 @@ def sort_mixed(values):
19881989

19891990
if not is_list_like(codes):
19901991
raise TypeError(
1991-
"Only list-like objects or None are allowed to be"
1992-
"passed to safe_sort as codes"
1992+
"Only list-like objects or None are allowed to "
1993+
"be passed to safe_sort as codes"
19931994
)
19941995
codes = ensure_platform_int(np.asarray(codes))
19951996

pandas/core/arrays/categorical.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class Categorical(ExtensionArray, PandasObject):
299299

300300
# For comparisons, so that numpy uses our implementation if the compare
301301
# ops, which raise
302-
__array_priority__ = 1000
302+
__array_priority__ = 1_000
303303
_dtype = CategoricalDtype(ordered=False)
304304
# tolist is not actually deprecated, just suppressed in the __dir__
305305
_deprecations = PandasObject._deprecations | frozenset(["tolist", "itemsize"])
@@ -494,14 +494,13 @@ def astype(self, dtype: Dtype, copy: bool = True) -> ArrayLike:
494494
if is_extension_array_dtype(dtype):
495495
return array(self, dtype=dtype, copy=copy) # type: ignore # GH 28770
496496
if is_integer_dtype(dtype) and self.isna().any():
497-
msg = "Cannot convert float NaN to integer"
498-
raise ValueError(msg)
497+
raise ValueError("Cannot convert float NaN to integer")
499498
return np.array(self, dtype=dtype, copy=copy)
500499

501500
@cache_readonly
502501
def size(self) -> int:
503502
"""
504-
return the len of myself
503+
Return the len of myself.
505504
"""
506505
return self._codes.size
507506

pandas/core/arrays/timedeltas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class TimedeltaArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps):
157157

158158
_typ = "timedeltaarray"
159159
_scalar_type = Timedelta
160-
__array_priority__ = 1000
160+
__array_priority__ = 1_000
161161
# define my properties & methods for delegation
162162
_other_ops: List[str] = []
163163
_bool_ops: List[str] = []

pandas/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ class IndexOpsMixin:
618618
"""
619619

620620
# ndarray compatibility
621-
__array_priority__ = 1000
621+
__array_priority__ = 1_000
622622
_deprecations: FrozenSet[str] = frozenset(
623623
["tolist", "item"] # tolist is not deprecated, just suppressed in the __dir__
624624
)

pandas/core/computation/align.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def _zip_axes_from_type(typ, new_axes):
3535

3636

3737
def _any_pandas_objects(terms) -> bool:
38-
"""Check a sequence of terms for instances of PandasObject."""
38+
"""
39+
Check a sequence of terms for instances of PandasObject.
40+
"""
3941
return any(isinstance(term.value, PandasObject) for term in terms)
4042

4143

@@ -98,7 +100,7 @@ def _align_core(terms):
98100
reindexer_size = len(reindexer)
99101

100102
ordm = np.log10(max(1, abs(reindexer_size - term_axis_size)))
101-
if ordm >= 1 and reindexer_size >= 10000:
103+
if ordm >= 1 and reindexer_size >= 10_000:
102104
w = (
103105
f"Alignment difference on axis {axis} is larger "
104106
f"than an order of magnitude on term {repr(terms[i].name)}, "
@@ -116,7 +118,9 @@ def _align_core(terms):
116118

117119

118120
def align_terms(terms):
119-
"""Align a set of terms"""
121+
"""
122+
Align a set of terms.
123+
"""
120124
try:
121125
# flatten the parse tree (a nested list, really)
122126
terms = list(com.flatten(terms))

pandas/core/computation/common.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99

1010

1111
def _ensure_decoded(s):
12-
""" if we have bytes, decode them to unicode """
12+
"""
13+
If we have bytes, decode them to unicode.
14+
"""
1315
if isinstance(s, (np.bytes_, bytes)):
1416
s = s.decode(get_option("display.encoding"))
1517
return s
1618

1719

1820
def result_type_many(*arrays_and_dtypes):
19-
""" wrapper around numpy.result_type which overcomes the NPY_MAXARGS (32)
20-
argument limit """
21+
"""
22+
Wrapper around numpy.result_type which overcomes the NPY_MAXARGS (32)
23+
argument limit.
24+
"""
2125
try:
2226
return np.result_type(*arrays_and_dtypes)
2327
except ValueError:
@@ -26,8 +30,10 @@ def result_type_many(*arrays_and_dtypes):
2630

2731

2832
def _remove_spaces_column_name(name):
29-
"""Check if name contains any spaces, if it contains any spaces
30-
the spaces will be removed and an underscore suffix is added."""
33+
"""
34+
Check if name contains any spaces, if it contains any spaces
35+
the spaces will be removed and an underscore suffix is added.
36+
"""
3137
if not isinstance(name, str) or " " not in name:
3238
return name
3339

pandas/core/computation/ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ def __init__(self, lhs, rhs, **kwargs):
506506

507507
if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
508508
raise TypeError(
509-
f"unsupported operand type(s) for {self.op}:"
510-
f" '{lhs.return_type}' and '{rhs.return_type}'"
509+
f"unsupported operand type(s) for {self.op}: "
510+
f"'{lhs.return_type}' and '{rhs.return_type}'"
511511
)
512512

513513
# do not upcast float32s to float64 un-necessarily

0 commit comments

Comments
 (0)