From 9dcb061b8c26dc03f9bf996ec0b4b415dacc47a4 Mon Sep 17 00:00:00 2001 From: jpivarski Date: Wed, 10 Jan 2024 14:54:06 -0600 Subject: [PATCH] Finalize deprecations whose time is up and adjust code and tests. --- src/awkward/_connect/pyarrow.py | 5 +- src/awkward/_nplikes/typetracer.py | 2 +- src/awkward/contents/indexedoptionarray.py | 6 +- src/awkward/forms/emptyform.py | 32 +-- src/awkward/forms/form.py | 24 +- src/awkward/forms/numpyform.py | 27 +- src/awkward/forms/unionform.py | 4 +- src/awkward/operations/ak_concatenate.py | 19 +- src/awkward/operations/ak_enforce_type.py | 22 +- src/awkward/operations/str/__init__.py | 6 +- src/awkward/typetracer.py | 2 +- tests/test_0914_types_and_forms.py | 265 ++++++++---------- tests/test_2085_empty_if_typetracer.py | 2 +- tests/test_2503_deprecate_to_numpyform.py | 13 - .../test_2518_datetime_units_as_parameter.py | 23 +- tests/test_2656_unflatten_axis_typetracer.py | 2 +- 16 files changed, 165 insertions(+), 289 deletions(-) diff --git a/src/awkward/_connect/pyarrow.py b/src/awkward/_connect/pyarrow.py index d76e81cb65..8125efa9cd 100644 --- a/src/awkward/_connect/pyarrow.py +++ b/src/awkward/_connect/pyarrow.py @@ -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: diff --git a/src/awkward/_nplikes/typetracer.py b/src/awkward/_nplikes/typetracer.py index b78bc3018a..cdf7b307a8 100644 --- a/src/awkward/_nplikes/typetracer.py +++ b/src/awkward/_nplikes/typetracer.py @@ -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 diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index bacc5f26d7..53374609ab 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -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) diff --git a/src/awkward/forms/emptyform.py b/src/awkward/forms/emptyform.py index 2371de4fb8..09f183742d 100644 --- a/src/awkward/forms/emptyform.py +++ b/src/awkward/forms/emptyform.py @@ -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 @@ -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)) diff --git a/src/awkward/forms/form.py b/src/awkward/forms/form.py index 18f16a0198..098b3373dc 100644 --- a/src/awkward/forms/form.py +++ b/src/awkward/forms/form.py @@ -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 @@ -492,14 +491,14 @@ 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, @@ -507,18 +506,19 @@ def length_zero_array( 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 @@ -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, diff --git a/src/awkward/forms/numpyform.py b/src/awkward/forms/numpyform.py index 3af48d5e19..f68f3b9cdf 100644 --- a/src/awkward/forms/numpyform.py +++ b/src/awkward/forms/numpyform.py @@ -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",) @@ -25,7 +24,7 @@ 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 = () @@ -33,29 +32,11 @@ def from_dtype( 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, diff --git a/src/awkward/forms/unionform.py b/src/awkward/forms/unionform.py index fd6d439acc..368d52b2f9 100644 --- a/src/awkward/forms/unionform.py +++ b/src/awkward/forms/unionform.py @@ -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 ) diff --git a/src/awkward/operations/ak_concatenate.py b/src/awkward/operations/ak_concatenate.py index cc035e5c27..42df7bc4f4 100644 --- a/src/awkward/operations/ak_concatenate.py +++ b/src/awkward/operations/ak_concatenate.py @@ -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) @@ -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 @@ -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( @@ -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)): diff --git a/src/awkward/operations/ak_enforce_type.py b/src/awkward/operations/ak_enforce_type.py index 2bd5996a01..902ed8a369 100644 --- a/src/awkward/operations/ak_enforce_type.py +++ b/src/awkward/operations/ak_enforce_type.py @@ -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): @@ -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: @@ -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( @@ -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 ] ) @@ -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 ] @@ -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 ), ) ) @@ -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 ), ) ) diff --git a/src/awkward/operations/str/__init__.py b/src/awkward/operations/str/__init__.py index 3a6d776904..73e6855e0c 100644 --- a/src/awkward/operations/str/__init__.py +++ b/src/awkward/operations/str/__init__.py @@ -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, @@ -256,7 +256,7 @@ def action(layout, **_): parameters={"__array__": "string"}, ), ) - .length_zero_array(highlevel=False) + .length_zero_array() .to_typetracer(forget_length=True) ) @@ -270,7 +270,7 @@ def action(layout, **_): parameters={"__array__": "bytestring"}, ), ) - .length_zero_array(highlevel=False) + .length_zero_array() .to_typetracer(forget_length=True) ) else: diff --git a/src/awkward/typetracer.py b/src/awkward/typetracer.py index abaf542ceb..bd82422e4c 100644 --- a/src/awkward/typetracer.py +++ b/src/awkward/typetracer.py @@ -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) diff --git a/tests/test_0914_types_and_forms.py b/tests/test_0914_types_and_forms.py index 1249d40d55..8541756d9c 100644 --- a/tests/test_0914_types_and_forms.py +++ b/tests/test_0914_types_and_forms.py @@ -1369,149 +1369,124 @@ def test_NumpyForm(): "parameters": {"__unit__": "s", "x": 123}, } - with pytest.warns(DeprecationWarning): - assert ak.forms.numpyform.from_dtype(np.dtype("bool")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "bool", - } - assert ak.forms.numpyform.from_dtype(np.dtype("int8")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "int8", - } - assert ak.forms.numpyform.from_dtype(np.dtype("uint8")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "uint8", - } - assert ak.forms.numpyform.from_dtype(np.dtype("int16")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "int16", - } - assert ak.forms.numpyform.from_dtype(np.dtype("uint16")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "uint16", - } - assert ak.forms.numpyform.from_dtype(np.dtype("int32")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "int32", - } - assert ak.forms.numpyform.from_dtype(np.dtype("uint32")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "uint32", - } - assert ak.forms.numpyform.from_dtype(np.dtype("int64")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "int64", - } - assert ak.forms.numpyform.from_dtype(np.dtype("uint64")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "uint64", - } - if hasattr(np, "float16"): - assert ak.forms.numpyform.from_dtype(np.dtype("float16")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "float16", - } - assert ak.forms.numpyform.from_dtype(np.dtype("float32")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "float32", - } - assert ak.forms.numpyform.from_dtype(np.dtype("float64")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "float64", - } - if hasattr(np, "float128"): - assert ak.forms.numpyform.from_dtype(np.dtype("float128")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "float128", - } - assert ak.forms.numpyform.from_dtype(np.dtype("complex64")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "complex64", - } - assert ak.forms.numpyform.from_dtype(np.dtype("complex128")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "complex128", - } - if hasattr(np, "complex256"): - assert ak.forms.numpyform.from_dtype(np.dtype("complex256")).to_dict( - verbose=False - ) == { - "class": "NumpyArray", - "primitive": "complex256", - } - assert ak.forms.numpyform.from_dtype(np.dtype("M8")).to_dict(verbose=False) == { - "class": "NumpyArray", - "primitive": "datetime64", - } - assert ak.forms.numpyform.from_dtype(np.dtype("M8[s]")).to_dict( + assert ak.forms.numpyform.from_dtype(np.dtype("bool")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "bool", + } + assert ak.forms.numpyform.from_dtype(np.dtype("int8")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "int8", + } + assert ak.forms.numpyform.from_dtype(np.dtype("uint8")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "uint8", + } + assert ak.forms.numpyform.from_dtype(np.dtype("int16")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "int16", + } + assert ak.forms.numpyform.from_dtype(np.dtype("uint16")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "uint16", + } + assert ak.forms.numpyform.from_dtype(np.dtype("int32")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "int32", + } + assert ak.forms.numpyform.from_dtype(np.dtype("uint32")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "uint32", + } + assert ak.forms.numpyform.from_dtype(np.dtype("int64")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "int64", + } + assert ak.forms.numpyform.from_dtype(np.dtype("uint64")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "uint64", + } + if hasattr(np, "float16"): + assert ak.forms.numpyform.from_dtype(np.dtype("float16")).to_dict( verbose=False ) == { "class": "NumpyArray", - "primitive": "datetime64", - "parameters": {"__unit__": "s"}, - } - assert ak.forms.numpyform.from_dtype( - np.dtype("M8[s]"), parameters={"x": 123} - ).to_dict(verbose=False) == { - "class": "NumpyArray", - "primitive": "datetime64", - "parameters": {"__unit__": "s", "x": 123}, - } - assert ak.forms.numpyform.from_dtype(np.dtype("m8")).to_dict(verbose=False) == { - "class": "NumpyArray", - "primitive": "timedelta64", + "primitive": "float16", } - assert ak.forms.numpyform.from_dtype(np.dtype("m8[s]")).to_dict( + assert ak.forms.numpyform.from_dtype(np.dtype("float32")).to_dict( + verbose=False + ) == { + "class": "NumpyArray", + "primitive": "float32", + } + assert ak.forms.numpyform.from_dtype(np.dtype("float64")).to_dict( + verbose=False + ) == { + "class": "NumpyArray", + "primitive": "float64", + } + if hasattr(np, "float128"): + assert ak.forms.numpyform.from_dtype(np.dtype("float128")).to_dict( verbose=False ) == { "class": "NumpyArray", - "primitive": "timedelta64", - "parameters": {"__unit__": "s"}, - } - assert ak.forms.numpyform.from_dtype( - np.dtype("m8[s]"), parameters={"x": 123} - ).to_dict(verbose=False) == { - "class": "NumpyArray", - "primitive": "timedelta64", - "parameters": {"__unit__": "s", "x": 123}, + "primitive": "float128", } - assert ak.forms.numpyform.from_dtype(np.dtype(("bool", (1, 2, 3)))).to_dict( + assert ak.forms.numpyform.from_dtype(np.dtype("complex64")).to_dict( + verbose=False + ) == { + "class": "NumpyArray", + "primitive": "complex64", + } + assert ak.forms.numpyform.from_dtype(np.dtype("complex128")).to_dict( + verbose=False + ) == { + "class": "NumpyArray", + "primitive": "complex128", + } + if hasattr(np, "complex256"): + assert ak.forms.numpyform.from_dtype(np.dtype("complex256")).to_dict( verbose=False ) == { "class": "NumpyArray", - "primitive": "bool", - "inner_shape": [1, 2, 3], + "primitive": "complex256", } + assert ak.forms.numpyform.from_dtype(np.dtype("M8")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "datetime64", + } + assert ak.forms.numpyform.from_dtype(np.dtype("M8[s]")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "datetime64[s]", + } + assert ak.forms.numpyform.from_dtype( + np.dtype("M8[s]"), parameters={"x": 123} + ).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "datetime64[s]", + "parameters": {"x": 123}, + } + assert ak.forms.numpyform.from_dtype(np.dtype("m8")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "timedelta64", + } + assert ak.forms.numpyform.from_dtype(np.dtype("m8[s]")).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "timedelta64[s]", + } + assert ak.forms.numpyform.from_dtype( + np.dtype("m8[s]"), parameters={"x": 123} + ).to_dict(verbose=False) == { + "class": "NumpyArray", + "primitive": "timedelta64[s]", + "parameters": {"x": 123}, + } + assert ak.forms.numpyform.from_dtype(np.dtype(("bool", (1, 2, 3)))).to_dict( + verbose=False + ) == { + "class": "NumpyArray", + "primitive": "bool", + "inner_shape": [1, 2, 3], + } assert ak.forms.numpyform.from_dtype( np.dtype("M8"), time_units_as_parameter=False @@ -1634,24 +1609,22 @@ def test_NumpyForm(): assert ak.forms.from_dict( { "class": "NumpyArray", - "primitive": "datetime64", - "parameters": {"__unit__": "s"}, + "primitive": "datetime64[s]", } ).to_dict(verbose=False) == { "class": "NumpyArray", - "primitive": "datetime64", - "parameters": {"__unit__": "s"}, + "primitive": "datetime64[s]", } assert ak.forms.from_dict( { "class": "NumpyArray", - "primitive": "datetime64", - "parameters": {"__unit__": "s", "x": 123}, + "primitive": "datetime64[s]", + "parameters": {"x": 123}, } ).to_dict(verbose=False) == { "class": "NumpyArray", - "primitive": "datetime64", - "parameters": {"__unit__": "s", "x": 123}, + "primitive": "datetime64[s]", + "parameters": {"x": 123}, } assert ak.forms.from_dict("timedelta64").to_dict(verbose=False) == { "class": "NumpyArray", @@ -1660,24 +1633,22 @@ def test_NumpyForm(): assert ak.forms.from_dict( { "class": "NumpyArray", - "primitive": "timedelta64", - "parameters": {"__unit__": "s"}, + "primitive": "timedelta64[s]", } ).to_dict(verbose=False) == { "class": "NumpyArray", - "primitive": "timedelta64", - "parameters": {"__unit__": "s"}, + "primitive": "timedelta64[s]", } assert ak.forms.from_dict( { "class": "NumpyArray", - "primitive": "timedelta64", - "parameters": {"__unit__": "s", "x": 123}, + "primitive": "timedelta64[s]", + "parameters": {"x": 123}, } ).to_dict(verbose=False) == { "class": "NumpyArray", - "primitive": "timedelta64", - "parameters": {"__unit__": "s", "x": 123}, + "primitive": "timedelta64[s]", + "parameters": {"x": 123}, } assert ak.forms.from_dict({"class": "NumpyArray", "primitive": "bool"}).to_dict( diff --git a/tests/test_2085_empty_if_typetracer.py b/tests/test_2085_empty_if_typetracer.py index f31ba16f8d..1364480e1f 100644 --- a/tests/test_2085_empty_if_typetracer.py +++ b/tests/test_2085_empty_if_typetracer.py @@ -56,6 +56,6 @@ def test_multiplier(regulararray): b = ak.from_numpy(a, regulararray=regulararray) assert str(b.type) == "2 * 3 * 5 * int64" - c = ak.Array(b.layout.form.length_one_array(highlevel=False)) + c = ak.Array(b.layout.form.length_one_array()) assert str(c.type) == "1 * 3 * 5 * int64" assert c.tolist() == [[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]] diff --git a/tests/test_2503_deprecate_to_numpyform.py b/tests/test_2503_deprecate_to_numpyform.py index 7c03ff6542..c65d00ebf5 100644 --- a/tests/test_2503_deprecate_to_numpyform.py +++ b/tests/test_2503_deprecate_to_numpyform.py @@ -2,22 +2,9 @@ from __future__ import annotations -import numpy as np -import pytest - import awkward as ak -def test_dtype_deprecated(): - form = ak.forms.EmptyForm() - with pytest.warns( - DeprecationWarning, - match=r"the `dtype` parameter in EmptyForm\.to_NumpyForm is deprecated", - ): - next_form = form.to_NumpyForm(dtype=np.dtype(np.int64)) - assert next_form.primitive == "int64" - - def test_primitive(): form = ak.forms.EmptyForm() next_form = form.to_NumpyForm(primitive="int64") diff --git a/tests/test_2518_datetime_units_as_parameter.py b/tests/test_2518_datetime_units_as_parameter.py index 351b80bc02..9456d03aa9 100644 --- a/tests/test_2518_datetime_units_as_parameter.py +++ b/tests/test_2518_datetime_units_as_parameter.py @@ -3,32 +3,11 @@ from __future__ import annotations import numpy as np -import pytest import awkward as ak -def test_no_parameter(): - dtype = np.dtype("datetime64[15us]") - with pytest.warns( - DeprecationWarning, match=r"from_dtype conversion of temporal units" - ): - form = ak.forms.numpyform.from_dtype(dtype) - assert form.primitive == "datetime64" - assert form.parameters == {"__unit__": "15us"} - - -def test_true_parameter(): - dtype = np.dtype("datetime64[15us]") - with pytest.warns( - DeprecationWarning, match=r"from_dtype conversion of temporal units" - ): - form = ak.forms.numpyform.from_dtype(dtype, time_units_as_parameter=True) - assert form.primitive == "datetime64" - assert form.parameters == {"__unit__": "15us"} - - def test_false_parameter(): dtype = np.dtype("datetime64[15us]") - form = ak.forms.numpyform.from_dtype(dtype, time_units_as_parameter=False) + form = ak.forms.numpyform.from_dtype(dtype) assert form.primitive == "datetime64[15us]" diff --git a/tests/test_2656_unflatten_axis_typetracer.py b/tests/test_2656_unflatten_axis_typetracer.py index a7c4047e6d..d8b8d65d36 100644 --- a/tests/test_2656_unflatten_axis_typetracer.py +++ b/tests/test_2656_unflatten_axis_typetracer.py @@ -83,7 +83,7 @@ def test(): form = ak.forms.from_dict(fromjson) - ttlayout = form.length_zero_array(highlevel=False).to_typetracer(forget_length=True) + ttlayout = form.length_zero_array().to_typetracer(forget_length=True) ttarray = ak.Array(ttlayout, behavior=ak.behavior) backend = ttlayout.backend