Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: only run test for specific Numba version #2921

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/awkward/_connect/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,8 @@ def handle_arrow(obj, generate_bitmasks=False, pass_empty_field=False):
if len(batches) == 0:
# create an empty array following the input schema
return form_handle_arrow(
obj.schema,
pass_empty_field=pass_empty_field,
).length_zero_array(highlevel=False)
obj.schema, pass_empty_field=pass_empty_field
).length_zero_array()
elif len(batches) == 1:
return handle_arrow(batches[0], generate_bitmasks, pass_empty_field)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/_nplikes/typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ def _attach_report(
def typetracer_with_report(
form: ak.forms.Form, getkey: Callable[[Form, str], str]
) -> tuple[ak.contents.Content, TypeTracerReport]:
layout = form.length_zero_array(highlevel=False).to_typetracer(forget_length=True)
layout = form.length_zero_array().to_typetracer(forget_length=True)
report = TypeTracerReport()
_attach_report(layout, form, report, getkey)
return layout, report
6 changes: 3 additions & 3 deletions src/awkward/contents/indexedoptionarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ def to_ByteMaskedArray(self, valid_when):
carry = ak.index.Index(carry)

if self._content.length is not unknown_length and self._content.length == 0:
content = self._content.form.length_one_array(
backend=self._backend, highlevel=False
)._carry(carry, False)
content = self._content.form.length_one_array(backend=self._backend)._carry(
carry, False
)
else:
content = self._content._carry(carry, False)

Expand Down
32 changes: 2 additions & 30 deletions src/awkward/forms/emptyform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from __future__ import annotations

from collections.abc import Callable
from inspect import signature

import awkward as ak
from awkward._errors import deprecate
from awkward._meta.emptymeta import EmptyMeta
from awkward._nplikes.numpy_like import NumpyMetadata
from awkward._nplikes.shape import ShapeItem
Expand Down Expand Up @@ -59,34 +57,8 @@ def _to_dict_part(self, verbose, toplevel):
def type(self):
return ak.types.UnknownType()

def to_NumpyForm(self, *args, **kwargs):
def legacy_impl(dtype):
deprecate(
f"the `dtype` parameter in {type(self).__name__}.to_NumpyForm is deprecated, "
f"in favour of a new `primitive` argument. Pass `primitive` by keyword to opt-in to the new behavior.",
version="2.4.0",
)
return ak.forms.numpyform.from_dtype(dtype)

def new_impl(*, primitive):
return ak.forms.numpyform.NumpyForm(primitive)

dispatch_table = [
new_impl,
legacy_impl,
]
for func in dispatch_table:
sig = signature(func)
try:
bound_arguments = sig.bind(*args, **kwargs)
except TypeError:
continue
else:
return func(*bound_arguments.args, **bound_arguments.kwargs)
raise AssertionError(
f"{type(self).__name__}.to_NumpyForm accepts either the new `primitive` argument as a keyword-only "
f"argument, or the legacy `dtype` argument as positional or keyword"
)
def to_NumpyForm(self, primitive):
return ak.forms.numpyform.NumpyForm(primitive)

def _columns(self, path, output, list_indicator):
output.append(".".join(path))
Expand Down
24 changes: 12 additions & 12 deletions src/awkward/forms/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import awkward as ak
from awkward._backends.numpy import NumpyBackend
from awkward._errors import deprecate
from awkward._meta.meta import Meta
from awkward._nplikes.numpy_like import NumpyMetadata
from awkward._nplikes.shape import ShapeItem, unknown_length
Expand Down Expand Up @@ -492,33 +491,34 @@ def _to_dict_part(self, verbose, toplevel):
raise NotImplementedError

def length_zero_array(
self, *, backend=numpy_backend, highlevel=True, behavior=None
self, *, backend=numpy_backend, highlevel=False, behavior=None
):
if highlevel:
deprecate(
"The `highlevel=True` variant of `Form.length_zero_array` is now deprecated. "
raise ValueError(
"The `highlevel=True` variant of `Form.length_zero_array` has been removed. "
"Please use `ak.Array(form.length_zero_array(...), behavior=...)` if an `ak.Array` is required.",
version="2.3.0",
)

return ak.operations.ak_from_buffers._impl(
form=self,
length=0,
container={"": b"\x00\x00\x00\x00\x00\x00\x00\x00"},
buffer_key="",
backend=backend,
byteorder=ak._util.native_byteorder,
highlevel=highlevel,
highlevel=False,
behavior=behavior,
attrs=None,
simplify=False,
)

def length_one_array(self, *, backend=numpy_backend, highlevel=True, behavior=None):
def length_one_array(
self, *, backend=numpy_backend, highlevel=False, behavior=None
):
if highlevel:
deprecate(
"The `highlevel=True` variant of `Form.length_zero_array` is now deprecated. "
"Please use `ak.Array(form.length_zero_array(...), behavior=...)` if an `ak.Array` is required.",
version="2.3.0",
raise ValueError(
"The `highlevel=True` variant of `Form.length_one_array` has been removed. "
"Please use `ak.Array(form.length_one_array(...), behavior=...)` if an `ak.Array` is required.",
)

# The naive implementation of a length-1 array requires that we have a sufficiently
Expand Down Expand Up @@ -616,7 +616,7 @@ def prepare(form, multiplier):
buffer_key="{form_key}",
backend=backend,
byteorder=ak._util.native_byteorder,
highlevel=highlevel,
highlevel=False,
behavior=behavior,
attrs=None,
simplify=False,
Expand Down
27 changes: 4 additions & 23 deletions src/awkward/forms/numpyform.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from collections.abc import Callable, Iterable, Iterator

import awkward as ak
from awkward._errors import deprecate
from awkward._meta.numpymeta import NumpyMeta
from awkward._nplikes.numpy_like import NumpyMetadata
from awkward._nplikes.shape import unknown_length
from awkward._typing import TYPE_CHECKING, Any, DType, JSONMapping, Self, final
from awkward._util import UNSET, Sentinel
from awkward._util import UNSET
from awkward.forms.form import Form, _SpecifierMatcher

__all__ = ("NumpyForm",)
Expand All @@ -25,37 +24,19 @@ def from_dtype(
dtype,
parameters: JSONMapping | None = None,
*,
time_units_as_parameter: bool | Sentinel = UNSET,
time_units_as_parameter: bool = False,
):
if dtype.subdtype is None:
inner_shape = ()
else:
inner_shape = dtype.shape
dtype = dtype.subdtype[0]

if time_units_as_parameter is UNSET:
time_units_as_parameter = True

if time_units_as_parameter:
deprecate(
"from_dtype conversion of temporal units to generic `datetime64` and `timedelta64` types is deprecated, "
"pass `time_units_as_parameter=False` to disable this warning.",
version="2.4.0",
raise ValueError(
"`time_units_as_parameter=True` is no longer supported; NumPy's time units are no longer converted into Awkward parameters"
)

if time_units_as_parameter and issubclass(
dtype.type, (np.datetime64, np.timedelta64)
):
unit, step = np.datetime_data(dtype)
if unit != "generic":
unitstr = ("" if step == 1 else str(step)) + unit
if parameters is None:
parameters = {}
else:
parameters = parameters.copy()
parameters["__unit__"] = unitstr
dtype = np.dtype(dtype.type)

return NumpyForm(
primitive=ak.types.numpytype.dtype_to_primitive(dtype),
parameters=parameters,
Expand Down
4 changes: 2 additions & 2 deletions src/awkward/forms/unionform.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def simplified(
return ak.contents.UnionArray.simplified(
ak.index._form_to_zero_length(tags),
ak.index._form_to_zero_length(index),
[x.length_zero_array(highlevel=False) for x in contents],
[x.length_zero_array() for x in contents],
parameters=parameters,
).form

def _union_of_optionarrays(self, index, parameters):
return (
self.length_zero_array(highlevel=False)
self.length_zero_array()
._union_of_optionarrays(ak.index._form_to_zero_length(index), parameters)
.form
)
Expand Down
19 changes: 7 additions & 12 deletions src/awkward/operations/ak_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def enforce_concatenated_form(layout, form):
)
# Unknowns become canonical forms
elif layout.is_unknown and not form.is_unknown:
return form.length_zero_array(highlevel=False).to_backend(layout.backend)
return form.length_zero_array().to_backend(layout.backend)

############## Unions #####################################################
# Merge invariant (drop union)
Expand Down Expand Up @@ -467,9 +467,7 @@ def enforce_concatenated_form(layout, form):
union_has_exact_type = True
else:
contents.append(
content_form.length_zero_array(highlevel=False).to_backend(
layout.backend
)
content_form.length_zero_array().to_backend(layout.backend)
)

# Otherwise, find anything we can merge with
Expand All @@ -478,18 +476,16 @@ def enforce_concatenated_form(layout, form):

for content_form in form.contents:
# TODO check forms mergeable
content_layout = content_form.length_zero_array(
highlevel=False
).to_backend(layout.backend)
content_layout = content_form.length_zero_array().to_backend(
layout.backend
)
if mergeable(content_layout, layout_to_merge):
contents.insert(
0, enforce_concatenated_form(layout_to_merge, content_form)
)
else:
contents.append(
content_form.length_zero_array(highlevel=False).to_backend(
layout.backend
)
content_form.length_zero_array().to_backend(layout.backend)
)

return ak.contents.UnionArray(
Expand All @@ -512,8 +508,7 @@ def enforce_concatenated_form(layout, form):
"merge result should only grow or preserve a union's cardinality"
)
form_contents = [
f.length_zero_array(highlevel=False).to_backend(layout.backend)
for f in form.contents
f.length_zero_array().to_backend(layout.backend) for f in form.contents
]
form_indices = range(len(form_contents))
for form_projection_indices in permutations(form_indices, len(layout.contents)):
Expand Down
22 changes: 7 additions & 15 deletions src/awkward/operations/ak_enforce_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,7 @@ def _recurse_unknown_any(
layout: ak.contents.EmptyArray, type_: ak.types.Type
) -> ak.contents.Content:
type_form = ak.forms.from_type(type_)
return type_form.length_zero_array(highlevel=False).copy(
parameters=type_._parameters
)
return type_form.length_zero_array().copy(parameters=type_._parameters)


def _recurse_any_unknown(layout: ak.contents.Content, type_: ak.types.UnknownType):
Expand All @@ -634,7 +632,7 @@ def _recurse_option_any(
return ak.contents.IndexedOptionArray(
ak.index.Index64(layout.backend.index_nplike.full(layout.length, -1)),
ak.forms.from_type(type_.content).length_zero_array(
backend=layout.backend, highlevel=False
backend=layout.backend
),
)
else:
Expand Down Expand Up @@ -699,9 +697,7 @@ def _recurse_any_option(
if isinstance(type_.content, ak.types.UnknownType):
return ak.contents.IndexedOptionArray(
ak.index.Index64(layout.backend.index_nplike.full(layout.length, -1)),
ak.forms.from_type(type_.content).length_zero_array(
backend=layout.backend, highlevel=False
),
ak.forms.from_type(type_.content).length_zero_array(backend=layout.backend),
)
else:
return ak.contents.UnmaskedArray(
Expand Down Expand Up @@ -765,9 +761,7 @@ def _recurse_union_union(
]
contents.extend(
[
ak.forms.from_type(t).length_zero_array(
highlevel=False, backend=layout.backend
)
ak.forms.from_type(t).length_zero_array(backend=layout.backend)
for t in missing_types
]
)
Expand Down Expand Up @@ -990,9 +984,7 @@ def _recurse_any_union(
index = index_nplike.arange(layout.length, dtype=np.int64)

other_contents = [
ak.forms.from_type(t).length_zero_array(
backend=layout.backend, highlevel=False
)
ak.forms.from_type(t).length_zero_array(backend=layout.backend)
for j, t in enumerate(type_.contents)
if j != i
]
Expand Down Expand Up @@ -1136,7 +1128,7 @@ def _recurse_record_any(
layout.backend.index_nplike.full(layout.length, -1)
),
ak.forms.from_type(next_type.content).length_zero_array(
backend=layout.backend, highlevel=False
backend=layout.backend
),
)
)
Expand Down Expand Up @@ -1181,7 +1173,7 @@ def _recurse_record_any(
layout.backend.index_nplike.full(layout.length, -1)
),
ak.forms.from_type(field_type.content).length_zero_array(
backend=layout.backend, highlevel=False
backend=layout.backend
),
)
)
Expand Down
6 changes: 3 additions & 3 deletions src/awkward/operations/str/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _apply_through_arrow(
if backend is typetracer:
converted_args = [
to_arrow(
x.form.length_zero_array(highlevel=False),
x.form.length_zero_array(),
extensionarray=False,
string_to32=string_to32,
bytestring_to32=bytestring_to32,
Expand Down Expand Up @@ -256,7 +256,7 @@ def action(layout, **_):
parameters={"__array__": "string"},
),
)
.length_zero_array(highlevel=False)
.length_zero_array()
.to_typetracer(forget_length=True)
)

Expand All @@ -270,7 +270,7 @@ def action(layout, **_):
parameters={"__array__": "bytestring"},
),
)
.length_zero_array(highlevel=False)
.length_zero_array()
.to_typetracer(forget_length=True)
)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/awkward/typetracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def typetracer_from_form(
"'form' argument must be a Form or its Python dict/JSON string representation"
)

layout = form.length_zero_array(highlevel=False).to_typetracer(forget_length=True)
layout = form.length_zero_array().to_typetracer(forget_length=True)

return wrap_layout(layout, behavior=behavior, highlevel=highlevel, attrs=attrs)

Expand Down
Loading
Loading