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

Modified named_arrays.AbstractFunctionArray.__getitem__() to support any instance of named_arrays.AbstractArray. #105

Merged
merged 2 commits into from
Jan 15, 2025
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
14 changes: 8 additions & 6 deletions named_arrays/_functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@
shape_inputs = inputs.shape
shape_outputs = outputs.shape

if isinstance(item, na.AbstractFunctionArray):
if np.any(item.inputs != self.inputs):
raise ValueError("boolean advanced index does not have the same inputs as the array")

item_inputs = item.outputs
item_outputs = item.outputs
if isinstance(item, na.AbstractArray):
if isinstance(item, na.AbstractFunctionArray):
if np.any(item.inputs != self.inputs):
raise ValueError("boolean advanced index does not have the same inputs as the array")
item_inputs = item.outputs
item_outputs = item.outputs

Check warning on line 182 in named_arrays/_functions/functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/functions.py#L177-L182

Added lines #L177 - L182 were not covered by tests
else:
item_inputs = item_outputs = item

Check warning on line 184 in named_arrays/_functions/functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/functions.py#L184

Added line #L184 was not covered by tests

shape_item_inputs = item_inputs.shape
shape_item_outputs = item_outputs.shape
Expand Down
21 changes: 14 additions & 7 deletions named_arrays/_functions/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,15 @@
outputs=na.ScalarArrayRange(0, 2, axis='y'),
)
),
na.ScalarLinearSpace(0, 1, axis='y', num=_num_y) > 0.5,
na.FunctionArray(
inputs=na.ScalarLinearSpace(0, 1, axis='y', num=_num_y),
outputs=na.ScalarLinearSpace(0, 1, axis='y', num=_num_y) > 0.5,
),
na.FunctionArray(
inputs=na.ScalarLinearSpace(0, 2, axis='y', num=_num_y),
outputs=na.ScalarLinearSpace(0, 1, axis='y', num=_num_y) > 0.5,
),
na.FunctionArray(
inputs=na.ScalarLinearSpace(0, 1, axis='y', num=_num_y),
outputs=na.UniformUncertainScalarArray(
Expand All @@ -157,13 +162,15 @@
array[item]
return

if isinstance(item, na.AbstractFunctionArray):
if np.any(item.inputs != array.inputs):
with pytest.raises(ValueError):
array[item]
return

item_outputs = item_inputs = item.outputs
if isinstance(item, na.AbstractArray):
if isinstance(item, na.AbstractFunctionArray):
if np.any(item.inputs != array.inputs):
with pytest.raises(ValueError):
array[item]
return
item_outputs = item_inputs = item.outputs

Check warning on line 171 in named_arrays/_functions/tests/test_functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/tests/test_functions.py#L165-L171

Added lines #L165 - L171 were not covered by tests
else:
item_outputs = item_inputs = item

Check warning on line 173 in named_arrays/_functions/tests/test_functions.py

View check run for this annotation

Codecov / codecov/patch

named_arrays/_functions/tests/test_functions.py#L173

Added line #L173 was not covered by tests

elif isinstance(item, dict):
item_inputs = {
Expand Down
Loading