diff --git a/src/awkward/operations/ak_full_like.py b/src/awkward/operations/ak_full_like.py index 66ce515f0a..8411f8ca98 100644 --- a/src/awkward/operations/ak_full_like.py +++ b/src/awkward/operations/ak_full_like.py @@ -7,7 +7,8 @@ from awkward._dispatch import high_level_function from awkward._layout import HighLevelContext, ensure_same_backend from awkward._nplikes.numpy_like import NumpyMetadata -from awkward._nplikes.typetracer import ensure_known_scalar +from awkward._nplikes.typetracer import is_unknown_scalar +from awkward._regularize import is_integer_like from awkward.operations.ak_zeros_like import _ZEROS __all__ = ("full_like",) @@ -125,12 +126,20 @@ def action(layout, backend, **kwargs): if layout.is_numpy: original = nplike.asarray(layout.data) - if fill_value is _ZEROS or ensure_known_scalar(fill_value == 0, False): + if fill_value is _ZEROS or ( + is_integer_like(fill_value) + and not is_unknown_scalar(fill_value) + and fill_value == 0 + ): return ak.contents.NumpyArray( nplike.zeros_like(original, dtype=dtype), parameters=layout.parameters, ) - elif ensure_known_scalar(fill_value == 1, False): + elif ( + is_integer_like(fill_value) + and not is_unknown_scalar(fill_value) + and fill_value == 1 + ): return ak.contents.NumpyArray( nplike.ones_like(original, dtype=dtype), parameters=layout.parameters, diff --git a/tests/test_2857_full_like_scalar.py b/tests/test_2857_full_like_scalar.py new file mode 100644 index 0000000000..f34ab6d4b6 --- /dev/null +++ b/tests/test_2857_full_like_scalar.py @@ -0,0 +1,36 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE + +from __future__ import annotations + +import numpy as np +import pytest # noqa: F401 + +import awkward as ak + + +def test(): + arr = ak.Array([{"x": 1}, {"x": 2}]) + # Fill with + result = ak.full_like(arr, np.datetime64(20, "s"), dtype="