Skip to content

Commit 2c0ef08

Browse files
style: pre-commit fixes
1 parent 3b6d656 commit 2c0ef08

File tree

2 files changed

+62
-111
lines changed

2 files changed

+62
-111
lines changed

src/awkward/contents/listoffsetarray.py

Lines changed: 43 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ def _to_buffers(
222222
container[key] = ak._util.native_to_byteorder(
223223
self._offsets.raw(backend.nplike), byteorder
224224
)
225-
self._content._to_buffers(
226-
form.content, getkey, container, backend, byteorder)
225+
self._content._to_buffers(form.content, getkey, container, backend, byteorder)
227226

228227
def _to_typetracer(self, forget_length: bool) -> Self:
229228
offsets = self._offsets.to_nplike(TypeTracer.instance())
@@ -256,10 +255,8 @@ def _repr(self, indent, pre, post):
256255
out.append(">")
257256
out.extend(self._repr_extra(indent + " "))
258257
out.append("\n")
259-
out.append(self._offsets._repr(
260-
indent + " ", "<offsets>", "</offsets>\n"))
261-
out.append(self._content._repr(
262-
indent + " ", "<content>", "</content>\n"))
258+
out.append(self._offsets._repr(indent + " ", "<offsets>", "</offsets>\n"))
259+
out.append(self._content._repr(indent + " ", "<content>", "</content>\n"))
263260
out.append(indent + "</ListOffsetArray>")
264261
out.append(post)
265262
return "".join(out)
@@ -272,7 +269,7 @@ def to_ListOffsetArray64(self, start_at_zero: bool = False) -> ListOffsetArray:
272269
nplike=self._backend.nplike,
273270
)
274271
return ListOffsetArray(
275-
offsets, self._content[self._offsets[0]:], parameters=self._parameters
272+
offsets, self._content[self._offsets[0] :], parameters=self._parameters
276273
)
277274
else:
278275
return ListOffsetArray(
@@ -283,8 +280,7 @@ def to_RegularArray(self):
283280
start, stop = (
284281
self._offsets[0],
285282
self._offsets[
286-
self._backend.nplike.shape_item_as_index(
287-
self._offsets.length - 1)
283+
self._backend.nplike.shape_item_as_index(self._offsets.length - 1)
288284
],
289285
)
290286
content = self._content._getitem_range(start, stop)
@@ -329,8 +325,7 @@ def _is_getitem_at_virtual(self) -> bool:
329325
def _getitem_at(self, where: IndexType):
330326
# Wrap `where` by length
331327
if not is_unknown_scalar(where) and where < 0:
332-
length_index = self._backend.nplike.shape_item_as_index(
333-
self.length)
328+
length_index = self._backend.nplike.shape_item_as_index(self.length)
334329
where += length_index
335330
# Validate `where`
336331
if not (
@@ -352,7 +347,7 @@ def _getitem_range(self, start: IndexType, stop: IndexType) -> Content:
352347
if self._backend.nplike.known_data and (start == 0 and stop == self.length):
353348
return self
354349

355-
offsets = self._offsets[start: stop + 1]
350+
offsets = self._offsets[start : stop + 1]
356351
if offsets.length is not unknown_length and offsets.length == 0:
357352
offsets = Index(
358353
self._backend.nplike.zeros(1, dtype=self._offsets.dtype),
@@ -524,8 +519,7 @@ def _getitem_next(
524519
)
525520

526521
if self._starts.dtype == "int64":
527-
nextoffsets = Index64.empty(
528-
lenstarts + 1, nplike=self._backend.nplike)
522+
nextoffsets = Index64.empty(lenstarts + 1, nplike=self._backend.nplike)
529523
elif self._starts.dtype == "int32":
530524
nextoffsets = ak.index.Index32.empty(
531525
lenstarts + 1, nplike=self._backend.nplike
@@ -615,8 +609,7 @@ def _getitem_next(
615609

616610
return ak.contents.ListOffsetArray(
617611
nextoffsets,
618-
nextcontent._getitem_next(
619-
nexthead, nexttail, nextadvanced),
612+
nextcontent._getitem_next(nexthead, nexttail, nextadvanced),
620613
parameters=self._parameters,
621614
)
622615

@@ -673,12 +666,10 @@ def _getitem_next(
673666
)
674667
nextcontent = self._content._carry(nextcarry, True)
675668

676-
out = nextcontent._getitem_next(
677-
nexthead, nexttail, nextadvanced)
669+
out = nextcontent._getitem_next(nexthead, nexttail, nextadvanced)
678670
if advanced is None:
679671
return ak._slicing.getitem_next_array_wrap(
680-
out, head.metadata.get(
681-
"shape", (head.length,), self.length)
672+
out, head.metadata.get("shape", (head.length,), self.length)
682673
)
683674
else:
684675
return out
@@ -774,8 +765,7 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]
774765
tooffsets = Index64([inneroffsets[0]])
775766
return (
776767
offsets,
777-
ListOffsetArray(tooffsets, flattened,
778-
parameters=self._parameters),
768+
ListOffsetArray(tooffsets, flattened, parameters=self._parameters),
779769
)
780770

781771
else:
@@ -804,8 +794,7 @@ def _offsets_and_flattened(self, axis: int, depth: int) -> tuple[Index, Content]
804794
)
805795
return (
806796
offsets,
807-
ListOffsetArray(tooffsets, flattened,
808-
parameters=self._parameters),
797+
ListOffsetArray(tooffsets, flattened, parameters=self._parameters),
809798
)
810799

811800
def _mergeable_next(
@@ -850,8 +839,7 @@ def _mergemany(self, others: Sequence[Content]) -> Content:
850839
out = listarray._mergemany(others)
851840

852841
if all(
853-
isinstance(
854-
x, ListOffsetArray) and x._offsets.dtype == self._offsets.dtype
842+
isinstance(x, ListOffsetArray) and x._offsets.dtype == self._offsets.dtype
855843
for x in others
856844
):
857845
return out.to_ListOffsetArray64(False)
@@ -923,8 +911,7 @@ def _is_unique(self, negaxis, starts, parents, outlength):
923911
# FIXME: check validity error
924912

925913
if isinstance(self._content, ak.contents.NumpyArray):
926-
out, outoffsets = self._content._as_unique_strings(
927-
self._offsets)
914+
out, outoffsets = self._content._as_unique_strings(self._offsets)
928915
out2 = ak.contents.ListOffsetArray(
929916
outoffsets, out, parameters=self._parameters
930917
)
@@ -971,14 +958,12 @@ def _unique(self, negaxis, starts, parents, outlength):
971958
or self.parameter("__array__") == "bytestring"
972959
):
973960
if branch or (negaxis != depth):
974-
raise AxisError(
975-
"array with strings can only be sorted with axis=-1")
961+
raise AxisError("array with strings can only be sorted with axis=-1")
976962

977963
# FIXME: check validity error
978964

979965
if isinstance(self._content, ak.contents.NumpyArray):
980-
out, nextoffsets = self._content._as_unique_strings(
981-
self._offsets)
966+
out, nextoffsets = self._content._as_unique_strings(self._offsets)
982967
return ak.contents.ListOffsetArray(
983968
nextoffsets, out, parameters=self._parameters
984969
)
@@ -988,8 +973,7 @@ def _unique(self, negaxis, starts, parents, outlength):
988973
self.parameter("__array__") == "string"
989974
or self.parameter("__array__") == "bytestring"
990975
):
991-
raise AxisError(
992-
"array with strings can only be sorted with axis=-1")
976+
raise AxisError("array with strings can only be sorted with axis=-1")
993977

994978
if self._backend.nplike.known_data and parents.nplike.known_data:
995979
assert self._offsets.length - 1 == parents.length
@@ -1056,7 +1040,7 @@ def _unique(self, negaxis, starts, parents, outlength):
10561040
)
10571041
)
10581042

1059-
trimmed = self._content[self._offsets[0]: self._offsets[-1]]
1043+
trimmed = self._content[self._offsets[0] : self._offsets[-1]]
10601044
outcontent = trimmed._unique(
10611045
negaxis,
10621046
self._offsets[:-1],
@@ -1089,8 +1073,7 @@ def _argsort_next(
10891073
or self.parameter("__array__") == "bytestring"
10901074
):
10911075
if branch or (negaxis != depth):
1092-
raise AxisError(
1093-
"array with strings can only be sorted with axis=-1")
1076+
raise AxisError("array with strings can only be sorted with axis=-1")
10941077

10951078
# FIXME: check validity error
10961079

@@ -1136,8 +1119,7 @@ def _argsort_next(
11361119
self.parameter("__array__") == "string"
11371120
or self.parameter("__array__") == "bytestring"
11381121
):
1139-
raise AxisError(
1140-
"array with strings can only be sorted with axis=-1")
1122+
raise AxisError("array with strings can only be sorted with axis=-1")
11411123

11421124
if self._backend.nplike.known_data and parents.nplike.known_data:
11431125
assert self._offsets.length - 1 == parents.length
@@ -1243,7 +1225,7 @@ def _argsort_next(
12431225
)
12441226
)
12451227

1246-
trimmed = self._content[self._offsets[0]: self._offsets[-1]]
1228+
trimmed = self._content[self._offsets[0] : self._offsets[-1]]
12471229
outcontent = trimmed._argsort_next(
12481230
negaxis,
12491231
self._offsets[:-1],
@@ -1268,8 +1250,7 @@ def _sort_next(self, negaxis, starts, parents, outlength, ascending, stable):
12681250
or self.parameter("__array__") == "bytestring"
12691251
):
12701252
if branch or (negaxis != depth):
1271-
raise AxisError(
1272-
"array with strings can only be sorted with axis=-1")
1253+
raise AxisError("array with strings can only be sorted with axis=-1")
12731254

12741255
# FIXME: check validity error
12751256

@@ -1311,8 +1292,7 @@ def _sort_next(self, negaxis, starts, parents, outlength, ascending, stable):
13111292
self.parameter("__array__") == "string"
13121293
or self.parameter("__array__") == "bytestring"
13131294
):
1314-
raise AxisError(
1315-
"array with strings can only be sorted with axis=-1")
1295+
raise AxisError("array with strings can only be sorted with axis=-1")
13161296

13171297
if self._backend.nplike.known_data and parents.nplike.known_data:
13181298
assert self._offsets.length - 1 == parents.length
@@ -1356,8 +1336,7 @@ def _sort_next(self, negaxis, starts, parents, outlength, ascending, stable):
13561336
parameters=self._parameters,
13571337
)
13581338
else:
1359-
nextlen = nplike.index_as_shape_item(
1360-
self._offsets[-1] - self._offsets[0])
1339+
nextlen = nplike.index_as_shape_item(self._offsets[-1] - self._offsets[0])
13611340
nextparents = Index64.empty(nextlen, nplike)
13621341
lenstarts = self._offsets.length - 1
13631342

@@ -1374,7 +1353,7 @@ def _sort_next(self, negaxis, starts, parents, outlength, ascending, stable):
13741353
)
13751354
)
13761355

1377-
trimmed = self._content[self._offsets[0]: self._offsets[-1]]
1356+
trimmed = self._content[self._offsets[0] : self._offsets[-1]]
13781357
outcontent = trimmed._sort_next(
13791358
negaxis,
13801359
self._offsets[:-1],
@@ -1625,14 +1604,12 @@ def _reduce_next(
16251604
)
16261605

16271606
if keepdims:
1628-
out = ak.contents.RegularArray(
1629-
out, 1, self.length, parameters=None)
1607+
out = ak.contents.RegularArray(out, 1, self.length, parameters=None)
16301608

16311609
return out
16321610

16331611
else:
1634-
nextlen = nplike.index_as_shape_item(
1635-
self._offsets[-1] - self._offsets[0])
1612+
nextlen = nplike.index_as_shape_item(self._offsets[-1] - self._offsets[0])
16361613
nextparents = Index64.empty(nextlen, nplike)
16371614

16381615
# n.b. awkward_ListOffsetArray_reduce_local_nextparents_64 always returns parents that are
@@ -1650,7 +1627,7 @@ def _reduce_next(
16501627
)
16511628
)
16521629

1653-
trimmed = self._content[self.offsets[0]: self.offsets[-1]]
1630+
trimmed = self._content[self.offsets[0] : self.offsets[-1]]
16541631
nextstarts = self.offsets[:-1]
16551632

16561633
outcontent = trimmed._reduce_next(
@@ -1698,8 +1675,7 @@ def _reduce_next(
16981675

16991676
def _rearrange_prepare_next(self, outlength, parents):
17001677
nplike = self._backend.nplike
1701-
nextlen = nplike.index_as_shape_item(
1702-
self._offsets[-1] - self._offsets[0])
1678+
nextlen = nplike.index_as_shape_item(self._offsets[-1] - self._offsets[0])
17031679
lenstarts = self._offsets.length - 1
17041680
_maxcount = Index64.empty(1, nplike)
17051681
offsetscopy = Index64.empty(self.offsets.length, nplike)
@@ -1939,7 +1915,7 @@ def _to_arrow(
19391915
else:
19401916
downsize = options["list_to32"]
19411917
(npoffsets,) = maybe_materialize(self._offsets.raw(numpy))
1942-
akcontent = self._content[npoffsets[0]: npoffsets[length]]
1918+
akcontent = self._content[npoffsets[0] : npoffsets[length]]
19431919
if len(npoffsets) > length + 1:
19441920
npoffsets = npoffsets[: length + 1]
19451921
if npoffsets[0] != 0:
@@ -2001,8 +1977,7 @@ def _to_arrow(
20011977
[
20021978
ak._connect.pyarrow.to_validbits(validbytes),
20031979
pyarrow.py_buffer(npoffsets),
2004-
pyarrow.py_buffer(
2005-
*maybe_materialize(akcontent._raw(numpy))),
1980+
pyarrow.py_buffer(*maybe_materialize(akcontent._raw(numpy))),
20061981
],
20071982
)
20081983

@@ -2064,7 +2039,6 @@ def _to_cudf(self, cudf: Any, mask: Content | None, length: int):
20642039
m = None
20652040
if self.parameters.get("__array__") == "string":
20662041
from cudf.core.column.string import StringColumn
2067-
from cudf.utils.dtypes import CUDF_STRING_DTYPE
20682042

20692043
data = cudf.core.buffer.as_buffer(cupy.asarray(self._content.data))
20702044
StrCol = StringColumn
@@ -2104,8 +2078,7 @@ def _to_backend_array(self, allow_missing, backend):
21042078
self._offsets.length,
21052079
_max_code_points,
21062080
)
2107-
max_code_points = backend.nplike.index_as_shape_item(
2108-
_max_code_points[0])
2081+
max_code_points = backend.nplike.index_as_shape_item(_max_code_points[0])
21092082
# Ensure that we have at-least length-1 bytestrings
21102083
if max_code_points is not unknown_length:
21112084
max_code_points = max(1, max_code_points)
@@ -2141,8 +2114,7 @@ def _to_backend_array(self, allow_missing, backend):
21412114
if max_count is not unknown_length:
21422115
max_count = max(1, max_count)
21432116

2144-
buffer = backend.nplike.empty(
2145-
max_count * self.length, dtype=np.uint8)
2117+
buffer = backend.nplike.empty(max_count * self.length, dtype=np.uint8)
21462118

21472119
self.backend[
21482120
"awkward_NumpyArray_pad_zero_to_length",
@@ -2169,7 +2141,7 @@ def _remove_structure(
21692141
):
21702142
return [self]
21712143
else:
2172-
content = self._content[self._offsets[0]: self._offsets[-1]]
2144+
content = self._content[self._offsets[0] : self._offsets[-1]]
21732145
contents = content._remove_structure(backend, options)
21742146
if options["keepdims"]:
21752147
if options["list_to_regular"]:
@@ -2189,8 +2161,7 @@ def _remove_structure(
21892161
backend.nplike.asarray(
21902162
[
21912163
0,
2192-
backend.nplike.shape_item_as_index(
2193-
c.length),
2164+
backend.nplike.shape_item_as_index(c.length),
21942165
]
21952166
)
21962167
),
@@ -2248,7 +2219,7 @@ def _recursively_apply(
22482219
offsets = ak.index.Index(
22492220
self._offsets.data - offsetsmin, nplike=self._backend.nplike
22502221
)
2251-
content = self._content[offsetsmin: self._offsets[-1]]
2222+
content = self._content[offsetsmin : self._offsets[-1]]
22522223
else:
22532224
self._touch_data(recursive=False)
22542225
offsets, content = self._offsets, self._content
@@ -2333,20 +2304,19 @@ def _to_list(self, behavior, json_conversions):
23332304
out = [None] * starts.length
23342305
if convert_bytes is None:
23352306
for i in range(starts.length):
2336-
out[i] = ak._util.tobytes(
2337-
data[starts_data[i]: stops_data[i]])
2307+
out[i] = ak._util.tobytes(data[starts_data[i] : stops_data[i]])
23382308
else:
23392309
for i in range(starts.length):
23402310
out[i] = convert_bytes(
2341-
ak._util.tobytes(data[starts_data[i]: stops_data[i]])
2311+
ak._util.tobytes(data[starts_data[i] : stops_data[i]])
23422312
)
23432313
return out
23442314

23452315
elif self.parameter("__array__") == "string":
23462316
data = nextcontent.data
23472317
out = [None] * starts.length
23482318
for i in range(starts.length):
2349-
out[i] = ak._util.tobytes(data[starts_data[i]: stops_data[i]]).decode(
2319+
out[i] = ak._util.tobytes(data[starts_data[i] : stops_data[i]]).decode(
23502320
errors="surrogateescape"
23512321
)
23522322
return out
@@ -2360,7 +2330,7 @@ def _to_list(self, behavior, json_conversions):
23602330
out = [None] * starts.length
23612331

23622332
for i in range(starts.length):
2363-
out[i] = content[starts_data[i]: stops_data[i]]
2333+
out[i] = content[starts_data[i] : stops_data[i]]
23642334
return out
23652335

23662336
def _to_backend(self, backend: Backend) -> Self:
@@ -2402,11 +2372,9 @@ def _awkward_strings_to_nonfinite(self, nonfinit_dict):
24022372
union_tags = ak.index.Index8.zeros(
24032373
content.length, nplike=self._backend.nplike
24042374
)
2405-
content.backend.nplike.isnan(
2406-
content._data, union_tags._data)
2375+
content.backend.nplike.isnan(content._data, union_tags._data)
24072376
union_index = Index64(
2408-
self._backend.nplike.arange(
2409-
content.length, dtype=np.int64),
2377+
self._backend.nplike.arange(content.length, dtype=np.int64),
24102378
nplike=self._backend.nplike,
24112379
)
24122380

0 commit comments

Comments
 (0)