Skip to content

Commit

Permalink
Let Manager subdivisions be numpy array
Browse files Browse the repository at this point in the history
numpy arrays don't (and likely won't) fulfill the Sequence
interface
numpy/numpy#2776
numpy/numpy#7315

The array gets converted down to a tuple any way, and each element
must be an integer too.

Unit test modified to allow this behavior.
  • Loading branch information
Andrew Johnson committed Mar 11, 2020
1 parent af0b5db commit ac5926b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hydep/manager.py
Expand Up @@ -155,7 +155,7 @@ def _validateSubsteps(self, divisions):
if divisions <= 0:
raise ValueError(f"Divisions must be positive integer, not {divisions}")
return FakeSequence(divisions, maxallowed)
if isinstance(divisions, Sequence):
if isinstance(divisions, (numpy.ndarray, Sequence)):
if len(divisions) != maxallowed:
raise ValueError(
"Number of divisions {} not equal to number of time "
Expand Down
9 changes: 9 additions & 0 deletions tests/test_manager.py
Expand Up @@ -130,6 +130,15 @@ def test_managerSubsteps(simpleChain):
divset = {safeargs.divisions * x for x in range(1, ntimesteps + 1)}
assert len(divset) == ntimesteps

# Test that numpy arrays are good
arraySubs = hydep.Manager(
safeargs.chain,
safeargs.timesteps,
safeargs.power,
numpy.arange(1, ntimesteps + 1),
)
assert arraySubs.substeps == tuple(range(1, ntimesteps + 1))

with pytest.raises(TypeError):
hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power, divset)

Expand Down

0 comments on commit ac5926b

Please sign in to comment.