Skip to content

Commit 353d955

Browse files
authored
STYLE double-quote cython strings #21 (#50013)
double quote cython strings
1 parent 36dcf51 commit 353d955

31 files changed

+623
-622
lines changed

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ repos:
2727
rev: v0.9.1
2828
hooks:
2929
- id: cython-lint
30+
- id: double-quote-cython-strings
3031
- repo: https://github.com./pre-commit/pre-commit-hooks
3132
rev: v4.4.0
3233
hooks:

pandas/_libs/algos.pyx

+10-10
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def is_lexsorted(list_of_arrays: list) -> bint:
180180
cdef int64_t **vecs = <int64_t**>malloc(nlevels * sizeof(int64_t*))
181181
for i in range(nlevels):
182182
arr = list_of_arrays[i]
183-
assert arr.dtype.name == 'int64'
183+
assert arr.dtype.name == "int64"
184184
vecs[i] = <int64_t*>cnp.PyArray_DATA(arr)
185185

186186
# Assume uniqueness??
@@ -514,9 +514,9 @@ def validate_limit(nobs: int | None, limit=None) -> int:
514514
lim = nobs
515515
else:
516516
if not util.is_integer_object(limit):
517-
raise ValueError('Limit must be an integer')
517+
raise ValueError("Limit must be an integer")
518518
if limit < 1:
519-
raise ValueError('Limit must be greater than 0')
519+
raise ValueError("Limit must be greater than 0")
520520
lim = limit
521521

522522
return lim
@@ -958,7 +958,7 @@ def rank_1d(
958958
if not ascending:
959959
tiebreak = TIEBREAK_FIRST_DESCENDING
960960

961-
keep_na = na_option == 'keep'
961+
keep_na = na_option == "keep"
962962

963963
N = len(values)
964964
if labels is not None:
@@ -984,7 +984,7 @@ def rank_1d(
984984
# with mask, without obfuscating location of missing data
985985
# in values array
986986
if numeric_object_t is object and values.dtype != np.object_:
987-
masked_vals = values.astype('O')
987+
masked_vals = values.astype("O")
988988
else:
989989
masked_vals = values.copy()
990990

@@ -1005,7 +1005,7 @@ def rank_1d(
10051005
# If descending, fill with highest value since descending
10061006
# will flip the ordering to still end up with lowest rank.
10071007
# Symmetric logic applies to `na_option == 'bottom'`
1008-
nans_rank_highest = ascending ^ (na_option == 'top')
1008+
nans_rank_highest = ascending ^ (na_option == "top")
10091009
nan_fill_val = get_rank_nan_fill_val(nans_rank_highest, <numeric_object_t>0)
10101010
if nans_rank_highest:
10111011
order = [masked_vals, mask]
@@ -1345,7 +1345,7 @@ def rank_2d(
13451345
if not ascending:
13461346
tiebreak = TIEBREAK_FIRST_DESCENDING
13471347

1348-
keep_na = na_option == 'keep'
1348+
keep_na = na_option == "keep"
13491349

13501350
# For cases where a mask is not possible, we can avoid mask checks
13511351
check_mask = (
@@ -1362,9 +1362,9 @@ def rank_2d(
13621362

13631363
if numeric_object_t is object:
13641364
if values.dtype != np.object_:
1365-
values = values.astype('O')
1365+
values = values.astype("O")
13661366

1367-
nans_rank_highest = ascending ^ (na_option == 'top')
1367+
nans_rank_highest = ascending ^ (na_option == "top")
13681368
if check_mask:
13691369
nan_fill_val = get_rank_nan_fill_val(nans_rank_highest, <numeric_object_t>0)
13701370

@@ -1385,7 +1385,7 @@ def rank_2d(
13851385
order = (values, ~np.asarray(mask))
13861386

13871387
n, k = (<object>values).shape
1388-
out = np.empty((n, k), dtype='f8', order='F')
1388+
out = np.empty((n, k), dtype="f8", order="F")
13891389
grp_sizes = np.ones(n, dtype=np.int64)
13901390

13911391
# lexsort is slower, so only use if we need to worry about the mask

pandas/_libs/groupby.pyx

+8-8
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,12 @@ def group_any_all(
604604
intp_t lab
605605
int8_t flag_val, val
606606

607-
if val_test == 'all':
607+
if val_test == "all":
608608
# Because the 'all' value of an empty iterable in Python is True we can
609609
# start with an array full of ones and set to zero when a False value
610610
# is encountered
611611
flag_val = 0
612-
elif val_test == 'any':
612+
elif val_test == "any":
613613
# Because the 'any' value of an empty iterable in Python is False we
614614
# can start with an array full of zeros and set to one only if any
615615
# value encountered is True
@@ -1061,7 +1061,7 @@ def group_ohlc(
10611061
N, K = (<object>values).shape
10621062

10631063
if out.shape[1] != 4:
1064-
raise ValueError('Output array must have 4 columns')
1064+
raise ValueError("Output array must have 4 columns")
10651065

10661066
if K > 1:
10671067
raise NotImplementedError("Argument 'values' must have only one dimension")
@@ -1157,11 +1157,11 @@ def group_quantile(
11571157
)
11581158

11591159
inter_methods = {
1160-
'linear': INTERPOLATION_LINEAR,
1161-
'lower': INTERPOLATION_LOWER,
1162-
'higher': INTERPOLATION_HIGHER,
1163-
'nearest': INTERPOLATION_NEAREST,
1164-
'midpoint': INTERPOLATION_MIDPOINT,
1160+
"linear": INTERPOLATION_LINEAR,
1161+
"lower": INTERPOLATION_LOWER,
1162+
"higher": INTERPOLATION_HIGHER,
1163+
"nearest": INTERPOLATION_NEAREST,
1164+
"midpoint": INTERPOLATION_MIDPOINT,
11651165
}
11661166
interp = inter_methods[interpolation]
11671167

pandas/_libs/index.pyx

+14-14
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ cdef class IndexEngine:
184184
if self.is_monotonic_increasing:
185185
values = self.values
186186
try:
187-
left = values.searchsorted(val, side='left')
188-
right = values.searchsorted(val, side='right')
187+
left = values.searchsorted(val, side="left")
188+
right = values.searchsorted(val, side="right")
189189
except TypeError:
190190
# e.g. GH#29189 get_loc(None) with a Float64Index
191191
# 2021-09-29 Now only reached for object-dtype
@@ -353,8 +353,8 @@ cdef class IndexEngine:
353353
remaining_stargets = set()
354354
for starget in stargets:
355355
try:
356-
start = values.searchsorted(starget, side='left')
357-
end = values.searchsorted(starget, side='right')
356+
start = values.searchsorted(starget, side="left")
357+
end = values.searchsorted(starget, side="right")
358358
except TypeError: # e.g. if we tried to search for string in int array
359359
remaining_stargets.add(starget)
360360
else:
@@ -551,7 +551,7 @@ cdef class DatetimeEngine(Int64Engine):
551551
return self._get_loc_duplicates(conv)
552552
values = self.values
553553

554-
loc = values.searchsorted(conv, side='left')
554+
loc = values.searchsorted(conv, side="left")
555555

556556
if loc == len(values) or values[loc] != conv:
557557
raise KeyError(val)
@@ -655,8 +655,8 @@ cdef class BaseMultiIndexCodesEngine:
655655
# with positive integers (-1 for NaN becomes 1). This enables us to
656656
# differentiate between values that are missing in other and matching
657657
# NaNs. We will set values that are not found to 0 later:
658-
labels_arr = np.array(labels, dtype='int64').T + multiindex_nulls_shift
659-
codes = labels_arr.astype('uint64', copy=False)
658+
labels_arr = np.array(labels, dtype="int64").T + multiindex_nulls_shift
659+
codes = labels_arr.astype("uint64", copy=False)
660660
self.level_has_nans = [-1 in lab for lab in labels]
661661

662662
# Map each codes combination in the index to an integer unambiguously
@@ -693,7 +693,7 @@ cdef class BaseMultiIndexCodesEngine:
693693
if self.level_has_nans[i] and codes.hasnans:
694694
result[codes.isna()] += 1
695695
level_codes.append(result)
696-
return self._codes_to_ints(np.array(level_codes, dtype='uint64').T)
696+
return self._codes_to_ints(np.array(level_codes, dtype="uint64").T)
697697

698698
def get_indexer(self, target: np.ndarray) -> np.ndarray:
699699
"""
@@ -754,12 +754,12 @@ cdef class BaseMultiIndexCodesEngine:
754754
ndarray[int64_t, ndim=1] new_codes, new_target_codes
755755
ndarray[intp_t, ndim=1] sorted_indexer
756756

757-
target_order = np.argsort(target).astype('int64')
757+
target_order = np.argsort(target).astype("int64")
758758
target_values = target[target_order]
759759
num_values, num_target_values = len(values), len(target_values)
760760
new_codes, new_target_codes = (
761-
np.empty((num_values,)).astype('int64'),
762-
np.empty((num_target_values,)).astype('int64'),
761+
np.empty((num_values,)).astype("int64"),
762+
np.empty((num_target_values,)).astype("int64"),
763763
)
764764

765765
# `values` and `target_values` are both sorted, so we walk through them
@@ -809,7 +809,7 @@ cdef class BaseMultiIndexCodesEngine:
809809
raise KeyError(key)
810810

811811
# Transform indices into single integer:
812-
lab_int = self._codes_to_ints(np.array(indices, dtype='uint64'))
812+
lab_int = self._codes_to_ints(np.array(indices, dtype="uint64"))
813813

814814
return self._base.get_loc(self, lab_int)
815815

@@ -940,8 +940,8 @@ cdef class SharedEngine:
940940
if self.is_monotonic_increasing:
941941
values = self.values
942942
try:
943-
left = values.searchsorted(val, side='left')
944-
right = values.searchsorted(val, side='right')
943+
left = values.searchsorted(val, side="left")
944+
right = values.searchsorted(val, side="right")
945945
except TypeError:
946946
# e.g. GH#29189 get_loc(None) with a Float64Index
947947
raise KeyError(val)

pandas/_libs/internals.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cdef class BlockPlacement:
6969
or not cnp.PyArray_ISWRITEABLE(val)
7070
or (<ndarray>val).descr.type_num != cnp.NPY_INTP
7171
):
72-
arr = np.require(val, dtype=np.intp, requirements='W')
72+
arr = np.require(val, dtype=np.intp, requirements="W")
7373
else:
7474
arr = val
7575
# Caller is responsible for ensuring arr.ndim == 1

pandas/_libs/interval.pyx

+15-15
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ from pandas._libs.tslibs.util cimport (
4242
is_timedelta64_object,
4343
)
4444

45-
VALID_CLOSED = frozenset(['left', 'right', 'both', 'neither'])
45+
VALID_CLOSED = frozenset(["left", "right", "both", "neither"])
4646

4747

4848
cdef class IntervalMixin:
@@ -59,7 +59,7 @@ cdef class IntervalMixin:
5959
bool
6060
True if the Interval is closed on the left-side.
6161
"""
62-
return self.closed in ('left', 'both')
62+
return self.closed in ("left", "both")
6363

6464
@property
6565
def closed_right(self):
@@ -73,7 +73,7 @@ cdef class IntervalMixin:
7373
bool
7474
True if the Interval is closed on the left-side.
7575
"""
76-
return self.closed in ('right', 'both')
76+
return self.closed in ("right", "both")
7777

7878
@property
7979
def open_left(self):
@@ -172,9 +172,9 @@ cdef class IntervalMixin:
172172
>>> pd.IntervalIndex(ivs).is_empty
173173
array([ True, False])
174174
"""
175-
return (self.right == self.left) & (self.closed != 'both')
175+
return (self.right == self.left) & (self.closed != "both")
176176

177-
def _check_closed_matches(self, other, name='other'):
177+
def _check_closed_matches(self, other, name="other"):
178178
"""
179179
Check if the closed attribute of `other` matches.
180180
@@ -197,9 +197,9 @@ cdef class IntervalMixin:
197197

198198

199199
cdef bint _interval_like(other):
200-
return (hasattr(other, 'left')
201-
and hasattr(other, 'right')
202-
and hasattr(other, 'closed'))
200+
return (hasattr(other, "left")
201+
and hasattr(other, "right")
202+
and hasattr(other, "closed"))
203203

204204

205205
cdef class Interval(IntervalMixin):
@@ -311,7 +311,7 @@ cdef class Interval(IntervalMixin):
311311
Either ``left``, ``right``, ``both`` or ``neither``.
312312
"""
313313

314-
def __init__(self, left, right, str closed='right'):
314+
def __init__(self, left, right, str closed="right"):
315315
# note: it is faster to just do these checks than to use a special
316316
# constructor (__cinit__/__new__) to avoid them
317317

@@ -343,8 +343,8 @@ cdef class Interval(IntervalMixin):
343343

344344
def __contains__(self, key) -> bool:
345345
if _interval_like(key):
346-
key_closed_left = key.closed in ('left', 'both')
347-
key_closed_right = key.closed in ('right', 'both')
346+
key_closed_left = key.closed in ("left", "both")
347+
key_closed_right = key.closed in ("right", "both")
348348
if self.open_left and key_closed_left:
349349
left_contained = self.left < key.left
350350
else:
@@ -389,15 +389,15 @@ cdef class Interval(IntervalMixin):
389389

390390
left, right = self._repr_base()
391391
name = type(self).__name__
392-
repr_str = f'{name}({repr(left)}, {repr(right)}, closed={repr(self.closed)})'
392+
repr_str = f"{name}({repr(left)}, {repr(right)}, closed={repr(self.closed)})"
393393
return repr_str
394394

395395
def __str__(self) -> str:
396396

397397
left, right = self._repr_base()
398-
start_symbol = '[' if self.closed_left else '('
399-
end_symbol = ']' if self.closed_right else ')'
400-
return f'{start_symbol}{left}, {right}{end_symbol}'
398+
start_symbol = "[" if self.closed_left else "("
399+
end_symbol = "]" if self.closed_right else ")"
400+
return f"{start_symbol}{left}, {right}{end_symbol}"
401401

402402
def __add__(self, y):
403403
if (

0 commit comments

Comments
 (0)