Skip to content

Commit

Permalink
Make sure random_state is a list before indexed assignment (capitalon…
Browse files Browse the repository at this point in the history
…e#968)

* Make sure random_state is a list before indexed assignment

Currently, a mypy error occurs because we attempt to assign to
random_state[1] when random_state has type
Union[list[Any], tuple[Any]]. Tuples are immutable so this is a type
error.

We fix this by making random_state into a list before doing indexed
assignment on it.

* Add type guards for random_state

* Check random_state before random_state[1]

Co-authored-by: Michael Davis <[email protected]>

* Reorder conditions for consistency

Co-authored-by: Taylor Turner <[email protected]>

---------

Co-authored-by: Michael Davis <[email protected]>
Co-authored-by: Taylor Turner <[email protected]>
  • Loading branch information
3 people committed Sep 17, 2023
1 parent abb04bf commit b989d12
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dataprofiler/labelers/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,8 +1555,8 @@ def __init__(
random_state = random.Random(random_state)
elif isinstance(random_state, (list, tuple)) and len(random_state) == 3:
# tuple required for random state to be set, lists do not work
if isinstance(random_state[1], list):
random_state[1] = tuple(random_state[1]) # type: ignore
if isinstance(random_state, list) and isinstance(random_state[1], list):
random_state[1] = tuple(random_state[1])
if isinstance(random_state, list):
random_state = tuple(random_state)
temp_random_state = random.Random()
Expand Down Expand Up @@ -1894,8 +1894,8 @@ def __init__(
random_state = random.Random(random_state)
elif isinstance(random_state, (list, tuple)) and len(random_state) == 3:
# tuple required for random state to be set, lists do not work
if isinstance(random_state[1], list):
random_state[1] = tuple(random_state[1]) # type: ignore
if isinstance(random_state, list) and isinstance(random_state[1], list):
random_state[1] = tuple(random_state[1])
if isinstance(random_state, list):
random_state = tuple(random_state)
temp_random_state = random.Random()
Expand Down

0 comments on commit b989d12

Please sign in to comment.