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

typing fixes #235

Merged
merged 104 commits into from
Jul 3, 2023
Merged

typing fixes #235

merged 104 commits into from
Jul 3, 2023

Conversation

Illviljan
Copy link
Contributor

@Illviljan Illviljan commented Apr 21, 2023

Newer version of mypy has found new issues with the typing.

@Illviljan
Copy link
Contributor Author

Found 15 errors in 2 files (checked 11 source files)
flox/core.py:219: error: Argument 1 to "tuple" has incompatible type "Union[ExtensionDtype, str, dtype[generic], Type[object]]"; expected "Iterable[str]"  [arg-type]
flox/core.py:508: error: Incompatible types in assignment (expression has type "Tuple[None, ...]", variable has type "Optional[Tuple[Index, ...]]")  [assignment]
flox/core.py:512: error: Argument 2 to "zip" has incompatible type "Optional[Tuple[Index, ...]]"; expected "Iterable[Index]"  [arg-type]
flox/core.py:545: error: Argument 1 to "append" of "list" has incompatible type "IntervalIndex[Any]"; expected "ndarray[Any, dtype[Any]]"  [arg-type]
flox/core.py:559: error: Incompatible types in assignment (expression has type "ndarray[Any, Any]", variable has type "Union[Index, str, bytes, date, timedelta, datetime64, timedelta64, int, float, integer[Any], floating[Any], complex]")  [assignment]
flox/core.py:559: error: Argument 1 to "factorize" has incompatible type "Union[ndarray[Any, Any], Any]"; expected "Sequence[Any]"  [arg-type]
flox/core.py:750: error: Argument "expected_groups" to "factorize_" has incompatible type "Tuple[Optional[Index]]"; expected "Optional[Tuple[Index, ...]]"  [arg-type]
flox/core.py:1581: error: Argument 1 to "append" of "list" has incompatible type "Union[Sequence[Any], ndarray[Any, Any], Index, None]"; expected "Optional[Index]"  [arg-type]
flox/core.py:1584: error: Argument 1 to "from_breaks" of "IntervalIndex" has incompatible type "Union[Sequence[Any], ndarray[Any, Any], Index]"; expected "Union[Sequence[int], ndarray[Any, dtype[signedinteger[_64Bit]]], ndarray[Any, dtype[signedinteger[_32Bit]]], ndarray[Any, dtype[signedinteger[Any]]], Series[int], _IntIndexType]"  [arg-type]
flox/core.py:1643: error: Argument "expected_groups" to "factorize_" has incompatible type "Tuple[Optional[Index], ...]"; expected "Optional[Tuple[Index, ...]]"  [arg-type]
flox/xarray.py:333: error: Incompatible types in assignment (expression has type "Union[Sequence[Any], ndarray[Any, Any], Index]", variable has type "Index")  [assignment]
flox/xarray.py:449: error: Item "Sequence[Any]" of "Union[Sequence[Any], ndarray[Any, Any], Index, None]" has no attribute "values"  [union-attr]
flox/xarray.py:449: error: Item "ndarray[Any, Any]" of "Union[Sequence[Any], ndarray[Any, Any], Index, None]" has no attribute "values"  [union-attr]
flox/xarray.py:449: error: Item "None" of "Union[Sequence[Any], ndarray[Any, Any], Index, None]" has no attribute "values"  [union-attr]
Error: Process completed with exit code 1.

@Illviljan
Copy link
Contributor Author

@dcherian , finally all green! :)

Copy link
Collaborator

@dcherian dcherian left a comment

Choose a reason for hiding this comment

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

Looking good. Just some minor comments

flox/core.py Show resolved Hide resolved
flox/core.py Outdated Show resolved Hide resolved
flox/core.py Outdated Show resolved Hide resolved
Comment on lines +331 to +342

expect1: T_ExpectOpt
if expect is None:
if isbin_:
raise ValueError(
f"Please provided bin edges for group variable {idx} "
f"named {group_name} in expected_groups."
)
expect_ = _get_expected_groups(b_.data, sort=sort)
expect1 = _get_expected_groups(b_.data, sort=sort)
else:
expect_ = expect
expect_index = _convert_expected_groups_to_index((expect_,), (isbin_,), sort=sort)[0]
expect1 = expect
expect_index = _convert_expected_groups_to_index((expect1,), (isbin_,), sort=sort)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer expect_ to expect1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found using numbers were much easier to read when you had multiple expect with varying types:
expect1 similar readabilty to expect_
expect2 much easier to read than expect__.

@dcherian dcherian enabled auto-merge (squash) July 3, 2023 15:47
@dcherian dcherian merged commit 66f152b into xarray-contrib:main Jul 3, 2023
15 of 16 checks passed
@Illviljan Illviljan deleted the typing_fixes branch July 7, 2023 17:18
dcherian added a commit that referenced this pull request Sep 28, 2023
* main: (68 commits)
  convert datetime: micro-optimizations (#261)
  compatibility with `numpy>=2.0` (#257)
  replace the deprecated `provision-with-micromamba` with `setup-micromamba` (#258)
  Fix some typing errors in asv_bench and tests (#253)
  [pre-commit.ci] pre-commit autoupdate (#250)
  typing fixes (#235)
  Fix test failure on i386 (#248)
  Delete resample_reduce (#246)
  Bump codecov/codecov-action from 3.1.3 to 3.1.4 (#243)
  Enable nanargmax, nanargmin (#171)
  Support nanfirst, nanlast with simple combine algo (#240)
  Check method only for dask reductions. (#241)
  Optimize broadcasting (#230)
  Handle min_count=0 (#238)
  Try and fix dtypes on 3.8,3.10 windows
  Preserve input dtypes now that pandas can do it.
  Add pytest-pretty to envs
  factorize early as much as possible
  Bump codecov/codecov-action from 3.1.1 to 3.1.3 (#239)
  [pre-commit.ci] pre-commit autoupdate (#229)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants