Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Sep 17, 2024
1 parent 4c51e6b commit d05517a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/awkward/_namedaxis.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ def __getitem__(self, where):
return where



# Define a type alias for a slice or int (can be a single axis or a sequence of axes)
AxisSlice: tp.TypeAlias = tp.Union[tuple, slice, int, tp.EllipsisType, None]
NamedAxisSlice: tp.TypeAlias = tp.Dict[AxisName, AxisSlice]
Expand Down Expand Up @@ -646,12 +645,12 @@ def _propagate_named_axis_through_slice(
"""
if where is None:
return (None,) + named_axis
elif where is (..., None):
elif where == (..., None):
return named_axis + (None,)
elif where is Ellipsis:
return named_axis
elif isinstance(where, int):
return named_axis[:where] + named_axis[where+1:]
return named_axis[:where] + named_axis[where + 1 :]
elif isinstance(where, slice):
return named_axis
elif isinstance(where, tuple):
Expand Down
8 changes: 6 additions & 2 deletions src/awkward/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,13 @@ def __getitem__(self, where):
"""
with ak._errors.SlicingErrorContext(self, where):
# normalize for potential named axis
from awkward._namedaxis import _normalize_slice, _get_named_axis, _supports_named_axis
from awkward._namedaxis import (

Check warning on line 1083 in src/awkward/highlevel.py

View workflow job for this annotation

GitHub Actions / Run PyLint

Reimport '_get_named_axis' (imported line 26)

Check warning on line 1083 in src/awkward/highlevel.py

View workflow job for this annotation

GitHub Actions / Run PyLint

Reimport '_supports_named_axis' (imported line 26)
_get_named_axis,
_normalize_slice,
_supports_named_axis,
)

out_named_axis=None
out_named_axis = None
if _supports_named_axis(self):
named_axis = _get_named_axis(self)

Expand Down
20 changes: 14 additions & 6 deletions tests/test_2596_named_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def test_named_axis_ak_to_packed():

assert ak.all(ak.to_packed(array) == ak.to_packed(named_array))

assert ak.to_packed(named_array).named_axis == named_array.named_axis
assert ak.to_packed(named_array).named_axis == named_array.named_axis


def test_named_axis_ak_to_parquet():
Expand Down Expand Up @@ -1083,9 +1083,13 @@ def test_named_axis_ak_values_astype():

named_array = ak.with_named_axis(array, ("x", "y"))

assert ak.all(ak.values_astype(array, np.float32) == ak.values_astype(named_array, np.float32))
assert ak.all(
ak.values_astype(array, np.float32) == ak.values_astype(named_array, np.float32)
)

assert ak.values_astype(named_array, np.float32).named_axis == named_array.named_axis
assert (
ak.values_astype(named_array, np.float32).named_axis == named_array.named_axis
)


def test_named_axis_ak_var():
Expand All @@ -1100,6 +1104,7 @@ def test_named_axis_ak_with_field():
# skip
assert True


def test_named_axis_ak_with_name():
array = ak.Array([[1, 2], [3], [], [4, 5, 6]])

Expand All @@ -1121,7 +1126,10 @@ def test_named_axis_ak_with_parameter():

named_array = ak.with_named_axis(array, ("x", "y"))

assert ak.with_parameter(named_array, "param", 1.0).named_axis == named_array.named_axis
assert (
ak.with_parameter(named_array, "param", 1.0).named_axis
== named_array.named_axis
)


def test_named_axis_ak_without_field():
Expand Down Expand Up @@ -1150,8 +1158,8 @@ def test_named_axis_ak_zeros_like():


def test_named_axis_ak_zip():
named_array1 = ak.with_named_axis(ak.Array([1,2,3]), ("a",))
named_array2 = ak.with_named_axis(ak.Array([[4,5,6], [], [7]]), ("x", "y"))
named_array1 = ak.with_named_axis(ak.Array([1, 2, 3]), ("a",))
named_array2 = ak.with_named_axis(ak.Array([[4, 5, 6], [], [7]]), ("x", "y"))

record = ak.zip({"x": named_array1, "y": named_array2})

Expand Down

0 comments on commit d05517a

Please sign in to comment.