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

More annotations in Dataset #3112

Merged
merged 14 commits into from Jul 31, 2019
Merged

More annotations in Dataset #3112

merged 14 commits into from Jul 31, 2019

Conversation

crusaderky
Copy link
Contributor

@crusaderky crusaderky commented Jul 13, 2019

No description provided.

from .dataarray import DataArray
from .dataset import Dataset
from .dataarray import DataArray # noqa: F811
from .dataset import Dataset # noqa: F811
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a workaround to a flake8 limitation https://gitlab.com/pycqa/flake8/issues/553

elif isinstance(dim, Mapping):
# We're later going to modify dim in place; don't tamper with
# the input
dim = OrderedDict(dim)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed bug where dim was modified in place, tainting the input variable. Also, fixed crash if the input dim is a read-only mapping.

@codecov
Copy link

codecov bot commented Jul 13, 2019

Codecov Report

Merging #3112 into master will decrease coverage by 0.04%.
The diff coverage is 88.57%.

@@            Coverage Diff             @@
##           master    #3112      +/-   ##
==========================================
- Coverage   95.98%   95.94%   -0.05%     
==========================================
  Files          63       63              
  Lines       12802    12816      +14     
==========================================
+ Hits        12288    12296       +8     
- Misses        514      520       +6

append: bool = False,
inplace: bool = None,
**indexes_kwargs: Union[Hashable, Sequence[Hashable]]
) -> 'Dataset':
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worth noting the behaviour is inconsistent with DataArray and pandas, which return None when inplace=True. Changing it however would benefit nobody and would break stuff.

@crusaderky
Copy link
Contributor Author

@shoyer @max-sixty ready for review and merge

Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

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

This looks great!

indexes: Mapping[Hashable, Union[Hashable, Sequence[Hashable]]] = None,
append: bool = False,
inplace: bool = None,
**indexes_kwargs: Union[Hashable, Sequence[Hashable]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing this is fine because mypy passes - my original thought was whether this should be Optional[Mapping] given it was either None or a dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of mypy 0.701, x: MyType = None and x: Optional[MyType] = None are the same.

from typing import Optional


def f1(x: int = None) -> None:
    pass

def f2(x: Optional[int] = None) -> None:
    pass

def f3(x: int = 1) -> None:
    pass

def f4(x: Optional[int] = 1) -> None:
    pass


f1()
f2()
f3()
f4()
f1(1)
f2(1)
f3(1)
f4(1)
f1(None)
f2(None)
f3(None)
f4(None)

mypy output:

test_mypy.py:27: error: Argument 1 to "f3" has incompatible type "None"; expected "int"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@max-sixty I did a generalised cleanup of all already existing cases; I find it's much more readable now

self,
dims_or_levels: Union[Hashable, Sequence[Hashable]],
drop: bool = False,
inplace: bool = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

inplace should go away soon so shouldn't matter... but should this be Optional[bool] given the default is None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above

Variable,
Tuple[Hashable, Any],
Tuple[Sequence[Hashable], Any],
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙌

@pep8speaks
Copy link

pep8speaks commented Jul 15, 2019

Hello @crusaderky! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-07-24 22:54:48 UTC

@max-sixty
Copy link
Collaborator

Great! Agree re Optional, thanks for clearing up.
Good to go from my end

@crusaderky crusaderky closed this Jul 19, 2019
@crusaderky crusaderky reopened this Jul 19, 2019
@crusaderky crusaderky closed this Jul 20, 2019
@crusaderky crusaderky reopened this Jul 20, 2019
@crusaderky
Copy link
Contributor Author

@shoyer this is ready for merge unless there are comments

[mypy-xarray]
ignore_missing_imports = True

By `Guido Imperiale <https://github.com/crusaderky>`_
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move this up to 0.12.4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@max-sixty
Copy link
Collaborator

Thanks @crusaderky ! I think fine to merge given we've both reviewed

@shoyer
Copy link
Member

shoyer commented Jul 24, 2019 via email

@crusaderky
Copy link
Contributor Author

@max-sixty @shoyer can we merge please?

@max-sixty
Copy link
Collaborator

Sorry @crusaderky - we were all waiting on each other! My mistake

@max-sixty max-sixty merged commit 1757dff into pydata:master Jul 31, 2019
@max-sixty
Copy link
Collaborator

Thanks again for the PR

@crusaderky crusaderky deleted the annotations branch August 1, 2019 10:41
dcherian added a commit to dcherian/xarray that referenced this pull request Aug 1, 2019
* master:
  More annotations in Dataset (pydata#3112)
  Hotfix for case of combining identical non-monotonic coords (pydata#3151)
  changed url for rasterio network test (pydata#3162)
dcherian added a commit to yohai/xarray that referenced this pull request Aug 3, 2019
* master: (68 commits)
  enable sphinx.ext.napoleon (pydata#3180)
  remove type annotations from autodoc method signatures (pydata#3179)
  Fix regression: IndexVariable.copy(deep=True) casts dtype=U to object (pydata#3095)
  Fix distributed.Client.compute applied to DataArray (pydata#3173)
  More annotations in Dataset (pydata#3112)
  Hotfix for case of combining identical non-monotonic coords (pydata#3151)
  changed url for rasterio network test (pydata#3162)
  to_zarr(append_dim='dim0') doesn't need mode='a' (pydata#3123)
  BUG: fix+test groupby on empty DataArray raises StopIteration (pydata#3156)
  Temporarily remove pynio from py36 CI build (pydata#3157)
  missing 'about' field (pydata#3146)
  Fix h5py version printing (pydata#3145)
  Remove the matplotlib=3.0 constraint from py36.yml (pydata#3143)
  disable codecov comments (pydata#3140)
  Merge broadcast_like docstrings, analyze implementation problem (pydata#3130)
  Update whats-new for pydata#3125 and pydata#2334 (pydata#3135)
  Fix tests on big-endian systems (pydata#3125)
  XFAIL tests failing on ARM (pydata#2334)
  Add broadcast_like. (pydata#3086)
  Better docs and errors about expand_dims() view (pydata#3114)
  ...
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.

None yet

4 participants