Skip to content

More annotations in Dataset #3112

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

Merged
merged 14 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ New functions/methods
(:issue:`3026`).
By `Julia Kent <https://github.com/jukent>`_.

- The xarray package is now discoverably by mypy (although typing hints
coverage is not complete yet). mypy users can now remove from their setup.cfg
the lines::

[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


Enhancements
~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@
tests_require=TESTS_REQUIRE,
url=URL,
packages=find_packages(),
package_data={'xarray': ['tests/data/*']})
package_data={'xarray': ['py.typed', 'tests/data/*']})
33 changes: 25 additions & 8 deletions xarray/core/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
import warnings
from collections import OrderedDict, defaultdict
from contextlib import suppress
from typing import Any, Mapping, Optional, Tuple
from typing import (
Any,
Dict,
Hashable,
Mapping,
Optional,
Tuple,
Union,
TYPE_CHECKING,
)

import numpy as np
import pandas as pd
Expand All @@ -13,6 +22,10 @@
from .utils import is_dict_like, is_full_slice
from .variable import IndexVariable, Variable

if TYPE_CHECKING:
from .dataarray import DataArray
from .dataset import Dataset


def _get_joiner(join):
if join == 'outer':
Expand Down Expand Up @@ -169,8 +182,8 @@ def deep_align(objects, join='inner', copy=True, indexes=None,

This function is not public API.
"""
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


if indexes is None:
indexes = {}
Expand Down Expand Up @@ -222,7 +235,10 @@ def is_alignable(obj):
return out


def reindex_like_indexers(target, other):
def reindex_like_indexers(
target: Union['DataArray', 'Dataset'],
other: Union['DataArray', 'Dataset'],
) -> Dict[Hashable, pd.Index]:
"""Extract indexers to align target with other.

Not public API.
Expand All @@ -236,7 +252,8 @@ def reindex_like_indexers(target, other):

Returns
-------
Dict[Any, pandas.Index] providing indexes for reindex keyword arguments.
Dict[Hashable, pandas.Index] providing indexes for reindex keyword
arguments.

Raises
------
Expand Down Expand Up @@ -310,7 +327,7 @@ def reindex_variables(
new_indexes : OrderedDict
Dict of indexes associated with the reindexed variables.
"""
from .dataarray import DataArray
from .dataarray import DataArray # noqa: F811

# create variables for the new dataset
reindexed = OrderedDict() # type: OrderedDict[Any, Variable]
Expand Down Expand Up @@ -463,8 +480,8 @@ def broadcast(*args, exclude=None):
a (x, y) int64 1 1 2 2 3 3
b (x, y) int64 5 6 5 6 5 6
"""
from .dataarray import DataArray
from .dataset import Dataset
from .dataarray import DataArray # noqa: F811
from .dataset import Dataset # noqa: F811

if exclude is None:
exclude = set()
Expand Down
9 changes: 7 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,13 @@ def reindex_like(self, other: Union['DataArray', Dataset],
align
"""
indexers = reindex_like_indexers(self, other)
return self.reindex(method=method, tolerance=tolerance, copy=copy,
fill_value=fill_value, **indexers)
return self.reindex(
indexers=indexers,
method=method,
tolerance=tolerance,
copy=copy,
fill_value=fill_value,
)

def reindex(self, indexers: Optional[Mapping[Hashable, Any]] = None,
method: Optional[str] = None, tolerance=None,
Expand Down
Loading