Skip to content

Commit 9096a7c

Browse files
authored
chore: fix ruff warnings (#3010)
* fix: specify dtype for `full` * fix: drop use of sctype * fix: don't use quadratic loop
1 parent a0350e7 commit 9096a7c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/awkward/_nplikes/typetracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def _scalar_type_of(obj) -> DType:
505505
if is_unknown_scalar(obj):
506506
return obj.dtype
507507
else:
508-
return numpy.obj2sctype(obj)
508+
return numpy.array(obj).dtype
509509

510510

511511
def try_touch_data(array: Any):

src/awkward/operations/ak_enforce_type.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ def _recurse_option_any(
630630
# Converting to an unknown inside an option!
631631
if isinstance(type_.content, ak.types.UnknownType):
632632
return ak.contents.IndexedOptionArray(
633-
ak.index.Index64(layout.backend.index_nplike.full(layout.length, -1)),
633+
ak.index.Index64(
634+
layout.backend.index_nplike.full(layout.length, -1, dtype=np.int64)
635+
),
634636
ak.forms.from_type(type_.content).length_zero_array(
635637
backend=layout.backend
636638
),
@@ -696,7 +698,9 @@ def _recurse_any_option(
696698
# Converting to an unknown inside an option!
697699
if isinstance(type_.content, ak.types.UnknownType):
698700
return ak.contents.IndexedOptionArray(
699-
ak.index.Index64(layout.backend.index_nplike.full(layout.length, -1)),
701+
ak.index.Index64(
702+
layout.backend.index_nplike.full(layout.length, -1, dtype=np.int64)
703+
),
700704
ak.forms.from_type(type_.content).length_zero_array(backend=layout.backend),
701705
)
702706
else:
@@ -1125,7 +1129,9 @@ def _recurse_record_any(
11251129
next_contents.append(
11261130
ak.contents.IndexedOptionArray(
11271131
ak.index.Index64(
1128-
layout.backend.index_nplike.full(layout.length, -1)
1132+
layout.backend.index_nplike.full(
1133+
layout.length, -1, dtype=np.int64
1134+
)
11291135
),
11301136
ak.forms.from_type(next_type.content).length_zero_array(
11311137
backend=layout.backend
@@ -1170,7 +1176,9 @@ def _recurse_record_any(
11701176
next_contents.append(
11711177
ak.contents.IndexedOptionArray(
11721178
ak.index.Index64(
1173-
layout.backend.index_nplike.full(layout.length, -1)
1179+
layout.backend.index_nplike.full(
1180+
layout.length, -1, dtype=np.int64
1181+
)
11741182
),
11751183
ak.forms.from_type(field_type.content).length_zero_array(
11761184
backend=layout.backend

src/awkward/operations/ak_to_dataframe.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from __future__ import annotations
44

5+
from functools import reduce
6+
from operator import iconcat
7+
58
import awkward as ak
69
from awkward._dispatch import high_level_function
710
from awkward._nplikes.numpy import Numpy
@@ -193,7 +196,8 @@ def recurse(layout, row_arrays, col_names):
193196
if layout.is_union:
194197
return [(ak.operations.to_numpy(layout), row_arrays, col_names)]
195198
else:
196-
return sum(
199+
return reduce(
200+
iconcat,
197201
(
198202
recurse(layout._getitem_field(n), row_arrays, (*col_names, n))
199203
for n in layout.fields
@@ -202,7 +206,8 @@ def recurse(layout, row_arrays, col_names):
202206
)
203207

204208
elif isinstance(layout, ak.contents.RecordArray):
205-
return sum(
209+
return reduce(
210+
iconcat,
206211
(
207212
recurse(layout._getitem_field(n), row_arrays, (*col_names, n))
208213
for n in layout.fields

0 commit comments

Comments
 (0)