-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from chris-greening/refactor-create-range
Refactor create range
- Loading branch information
Showing
6 changed files
with
50 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import itertools | ||
import collections | ||
from typing import Tuple, List, Union | ||
from numbers import Number | ||
|
||
def _get_products_of_inputs(*args) -> Tuple[Number]: | ||
"""Return a list of tuples that contains all of the input arguments""" | ||
list_of_lists = [_set_int_to_list(el) for el in args] | ||
product = list(itertools.product(*list_of_lists)) | ||
return product | ||
|
||
def _validate_only_one_iterable(*args) -> bool: | ||
"""Return validation check that only one argument passed to create_range is an iterable""" | ||
inputs = collections.Counter([isinstance(el, collections.abc.Iterable) for el in args]) | ||
if inputs[True] > 1: | ||
raise ValueError("More than one input variable was varied. Please only pass one list of varying inputs and try again.") | ||
|
||
def _set_int_to_list(input_val: Union[Number, List[Number]]) -> List[Number]: | ||
"""Return list of numbers from given input parameter""" | ||
if isinstance(input_val, Number): | ||
input_val = [input_val] | ||
return input_val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from spyrograph._misc import _set_int_to_list | ||
|
||
def test_set_int_to_list(): | ||
"""Test that setting int to list""" | ||
num_test = _set_int_to_list(1) | ||
list_test = _set_int_to_list([2]) | ||
assert isinstance(num_test, list) | ||
assert isinstance(list_test, list) | ||
assert num_test[0] == 1 | ||
assert list_test[0] == 2 |