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

Make sure random_state is a list before indexed assignment #968

Merged

Conversation

junholee6a
Copy link
Contributor

@junholee6a junholee6a commented Jul 25, 2023

Issue: #722

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. This tells mypy that random_state is definitely a list and cannot be a tuple.

@taylorfturner
Copy link
Contributor

update branch

@junholee6a junholee6a force-pushed the make-list-before-indexed-assignment branch from 8749eb0 to d6b0aa3 Compare July 25, 2023 16:35
tyfarnan
tyfarnan previously approved these changes Jul 27, 2023
@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a case for cast as opposed to a computation. I'm surprised isinstance(random_state, (list, tuple)) isn't alleviating this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah just trick mypy with the cast rather than at execution time actually changing the type to list

Copy link
Contributor Author

@junholee6a junholee6a Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a case for cast as opposed to a computation. I'm surprised isinstance(random_state, (list, tuple)) isn't alleviating this.

It's because random_state could be a tuple, in which case indexed assignment isn't possible.

Is there any possibility that random_state is a tuple while random_state[1] is a list? If this will never happen we can safely cast here, or change the line 1558 conditional to if isinstance(random_state[1], list) and isinstance(random_state, list):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any possibility that random_state is a tuple while random_state[1] is a list?

Though, if this ever did happen in the past it would've thrown a runtime error.

Copy link
Contributor

@ksneab7 ksneab7 Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorfturner @junholee6a Did this get resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or change the line 1558 conditional to if isinstance(random_state[1], list) and isinstance(random_state, list):

I just committed this solution since it avoids casting

ksneab7
ksneab7 previously approved these changes Aug 7, 2023
Copy link
Contributor

@taylorfturner taylorfturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking for 0.10.3 release. will unblock post-deployment

@taylorfturner taylorfturner dismissed their stale review August 8, 2023 14:01

dismissing block post 0.10.3

@taylorfturner
Copy link
Contributor

will review today. Update branch with dev needed @junholee6a

@junholee6a junholee6a force-pushed the make-list-before-indexed-assignment branch from d6b0aa3 to 32c414b Compare August 8, 2023 15:17
auto-merge was automatically disabled August 8, 2023 15:17

Head branch was pushed to by a user without write access

@taylorfturner
Copy link
Contributor

@junholee6a sorry something else merged to dev before this.... can you update branch once more 🙂

@taylorfturner taylorfturner changed the base branch from old-dev to dev August 9, 2023 15:37
@taylorfturner taylorfturner dismissed stale reviews from ksneab7 and tyfarnan August 9, 2023 15:37

The base branch was changed.

@taylorfturner
Copy link
Contributor

You might need to rebase... looking at the commits in this PR: some of them aren't probably related to the work you did on this PR itself

@junholee6a
Copy link
Contributor Author

I can't rebase automatically on github, let me see if I can do so manually

@junholee6a junholee6a force-pushed the make-list-before-indexed-assignment branch from 0f361ec to ae2e834 Compare August 9, 2023 16:23
@junholee6a
Copy link
Contributor Author

Rebased

@taylorfturner
Copy link
Contributor

Rebased

still showing as out of date with dev 🤔

@junholee6a junholee6a force-pushed the make-list-before-indexed-assignment branch from ae2e834 to 9c02d41 Compare August 10, 2023 16:02
@taylorfturner taylorfturner enabled auto-merge (squash) August 10, 2023 16:43
@taylorfturner
Copy link
Contributor

@junholee6a update branch here lol -- @ksneab7 let's review this PR first

auto-merge was automatically disabled September 1, 2023 21:41

Head branch was pushed to by a user without write access

@junholee6a junholee6a force-pushed the make-list-before-indexed-assignment branch from 2a63511 to 555b0a7 Compare September 1, 2023 21:41
@taylorfturner taylorfturner enabled auto-merge (squash) September 5, 2023 16:04
taylorfturner
taylorfturner previously approved these changes Sep 6, 2023
auto-merge was automatically disabled September 8, 2023 15:17

Head branch was pushed to by a user without write access

junholee6a and others added 3 commits September 8, 2023 11:40
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.
Co-authored-by: Michael Davis <36012613+micdavis@users.noreply.github.com>
@junholee6a junholee6a force-pushed the make-list-before-indexed-assignment branch from 91b12ab to ec031d9 Compare September 8, 2023 15:40
@taylorfturner taylorfturner enabled auto-merge (squash) September 11, 2023 19:41
Co-authored-by: Taylor Turner <taylorfturner@gmail.com>
auto-merge was automatically disabled September 12, 2023 14:16

Head branch was pushed to by a user without write access

@taylorfturner taylorfturner enabled auto-merge (squash) September 12, 2023 14:25
@taylorfturner taylorfturner merged commit ff14ab3 into capitalone:dev Sep 13, 2023
junholee6a added a commit to junholee6a/DataProfiler that referenced this pull request Sep 17, 2023
…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 <36012613+micdavis@users.noreply.github.com>

* Reorder conditions for consistency

Co-authored-by: Taylor Turner <taylorfturner@gmail.com>

---------

Co-authored-by: Michael Davis <36012613+micdavis@users.noreply.github.com>
Co-authored-by: Taylor Turner <taylorfturner@gmail.com>
taylorfturner added a commit that referenced this pull request Sep 21, 2023
* modified the assignees for issue creation (#1016)

* Minor: Profiler Path Fix in Example Notebook (#1021)

* Bump actions/checkout from 3 to 4 (#1024)

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Taylor Turner <taylorfturner@gmail.com>

* Make sure random_state is a list before indexed assignment (#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 <36012613+micdavis@users.noreply.github.com>

* Reorder conditions for consistency

Co-authored-by: Taylor Turner <taylorfturner@gmail.com>

---------

Co-authored-by: Michael Davis <36012613+micdavis@users.noreply.github.com>
Co-authored-by: Taylor Turner <taylorfturner@gmail.com>

* added psi calculation to categorical columns (#1027)

* added psi calculation to categorical columns

* Changed test value to non-calculated assignment

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Navid Nafiuzzaman <mxn4459@rit.edu>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Taylor Turner <taylorfturner@gmail.com>
Co-authored-by: Junho Lee <53921230+junholee6a@users.noreply.github.com>
Co-authored-by: Michael Davis <36012613+micdavis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
static_typing mypy static typing issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants