Skip to content

Commit 156babb

Browse files
odimkacopybara-github
authored andcommitted
Fix kd.index docstring an argument check.
PiperOrigin-RevId: 713682449 Change-Id: If5b3d709dc883faf3c1e49a98e84948465263912
1 parent 865045e commit 156babb

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

py/koladata/operators/slices.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,8 @@ def index(x, dim=-1):
811811
812812
Args:
813813
x: A DataSlice.
814-
dim: The dimension to compute indices over. Requires abs(dim) < get_ndim(x).
814+
dim: The dimension to compute indices over.
815+
Requires -get_ndim(x) <= dim < get_ndim(x).
815816
If dim < 0 then dim = get_ndim(x) + dim.
816817
"""
817818
x = assertion.with_assertion(
@@ -825,7 +826,7 @@ def index(x, dim=-1):
825826
ndim = assertion.with_assertion(
826827
ndim,
827828
(ndim < get_ndim(x)) & (ndim >= 0),
828-
'kde.slices.index: expected 0 <= dim < rank',
829+
'kde.slices.index: expected -get_ndim(x) <= dim < get_ndim(x)',
829830
)
830831

831832
aggregated = masking.agg_has(x, ndim)

py/koladata/operators/tests/slices_index_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ def test_out_of_bounds_ndim_error(self, ndim):
133133
with self.assertRaisesRegex(
134134
# TODO: b/375621456 - Raise KodaError.
135135
ValueError,
136-
'kde.slices.index: expected 0 <= dim < rank',
136+
re.escape(
137+
'kde.slices.index: expected -get_ndim(x) <= dim < get_ndim(x)'
138+
),
137139
):
138140
expr_eval.eval(kde.slices.index(x, ndim))
139141

0 commit comments

Comments
 (0)