Skip to content

Commit

Permalink
Make sure random_state is a list before indexed assignment
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
junholee6a committed Sep 1, 2023
1 parent bb65a13 commit a279efd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dataprofiler/labelers/data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,8 @@ def __init__(
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
random_state = list(random_state)
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 @@ -1895,7 +1896,8 @@ def __init__(
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
random_state = list(random_state)
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 a279efd

Please sign in to comment.