Skip to content

Commit

Permalink
chore: fix ruff warnings (#3010)
Browse files Browse the repository at this point in the history
* fix: specify dtype for `full`

* fix: drop use of sctype

* fix: don't use quadratic loop
  • Loading branch information
agoose77 authored Feb 7, 2024
1 parent a0350e7 commit 9096a7c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/awkward/_nplikes/typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _scalar_type_of(obj) -> DType:
if is_unknown_scalar(obj):
return obj.dtype
else:
return numpy.obj2sctype(obj)
return numpy.array(obj).dtype


def try_touch_data(array: Any):
Expand Down
16 changes: 12 additions & 4 deletions src/awkward/operations/ak_enforce_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ def _recurse_option_any(
# Converting to an unknown inside an option!
if isinstance(type_.content, ak.types.UnknownType):
return ak.contents.IndexedOptionArray(
ak.index.Index64(layout.backend.index_nplike.full(layout.length, -1)),
ak.index.Index64(
layout.backend.index_nplike.full(layout.length, -1, dtype=np.int64)
),
ak.forms.from_type(type_.content).length_zero_array(
backend=layout.backend
),
Expand Down Expand Up @@ -696,7 +698,9 @@ def _recurse_any_option(
# Converting to an unknown inside an option!
if isinstance(type_.content, ak.types.UnknownType):
return ak.contents.IndexedOptionArray(
ak.index.Index64(layout.backend.index_nplike.full(layout.length, -1)),
ak.index.Index64(
layout.backend.index_nplike.full(layout.length, -1, dtype=np.int64)
),
ak.forms.from_type(type_.content).length_zero_array(backend=layout.backend),
)
else:
Expand Down Expand Up @@ -1125,7 +1129,9 @@ def _recurse_record_any(
next_contents.append(
ak.contents.IndexedOptionArray(
ak.index.Index64(
layout.backend.index_nplike.full(layout.length, -1)
layout.backend.index_nplike.full(
layout.length, -1, dtype=np.int64
)
),
ak.forms.from_type(next_type.content).length_zero_array(
backend=layout.backend
Expand Down Expand Up @@ -1170,7 +1176,9 @@ def _recurse_record_any(
next_contents.append(
ak.contents.IndexedOptionArray(
ak.index.Index64(
layout.backend.index_nplike.full(layout.length, -1)
layout.backend.index_nplike.full(
layout.length, -1, dtype=np.int64
)
),
ak.forms.from_type(field_type.content).length_zero_array(
backend=layout.backend
Expand Down
9 changes: 7 additions & 2 deletions src/awkward/operations/ak_to_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from __future__ import annotations

from functools import reduce
from operator import iconcat

import awkward as ak
from awkward._dispatch import high_level_function
from awkward._nplikes.numpy import Numpy
Expand Down Expand Up @@ -193,7 +196,8 @@ def recurse(layout, row_arrays, col_names):
if layout.is_union:
return [(ak.operations.to_numpy(layout), row_arrays, col_names)]
else:
return sum(
return reduce(
iconcat,
(
recurse(layout._getitem_field(n), row_arrays, (*col_names, n))
for n in layout.fields
Expand All @@ -202,7 +206,8 @@ def recurse(layout, row_arrays, col_names):
)

elif isinstance(layout, ak.contents.RecordArray):
return sum(
return reduce(
iconcat,
(
recurse(layout._getitem_field(n), row_arrays, (*col_names, n))
for n in layout.fields
Expand Down

0 comments on commit 9096a7c

Please sign in to comment.