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

replace duplicate method _from_vars_and_coord_names #3565

Merged
merged 3 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Internal Changes
~~~~~~~~~~~~~~~~


- Removed internal method ``Dataset._from_vars_and_coord_names``,
which was dominated by ``Dataset._construct_direct``. (:pull:`3565`)
By `Maximilian Roos <https://github.com/max-sixty>`_


v0.14.1 (19 Nov 2019)
---------------------
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _fast_dataset(

variables.update(coord_variables)
coord_names = set(coord_variables)
return Dataset._from_vars_and_coord_names(variables, coord_names)
return Dataset._construct_direct(variables, coord_names)


def apply_dataset_vfunc(
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def to_dataset(self) -> "Dataset":
from .dataset import Dataset

coords = {k: v.copy(deep=False) for k, v in self._data._coords.items()}
return Dataset._from_vars_and_coord_names(coords, set(coords))
return Dataset._construct_direct(coords, set(coords))

def __delitem__(self, key: Hashable) -> None:
del self._data._coords[key]
Expand Down
6 changes: 2 additions & 4 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def subset(dim, label):
variables.update({k: v for k, v in self._coords.items() if k != dim})
indexes = propagate_indexes(self._indexes, exclude=dim)
coord_names = set(self._coords) - set([dim])
dataset = Dataset._from_vars_and_coord_names(
dataset = Dataset._construct_direct(
variables, coord_names, indexes=indexes, attrs=self.attrs
)
return dataset
Expand Down Expand Up @@ -496,9 +496,7 @@ def _to_dataset_whole(
indexes = self._indexes

coord_names = set(self._coords)
dataset = Dataset._from_vars_and_coord_names(
variables, coord_names, indexes=indexes
)
dataset = Dataset._construct_direct(variables, coord_names, indexes=indexes)
return dataset

def to_dataset(self, dim: Hashable = None, *, name: Hashable = None) -> Dataset:
Expand Down
8 changes: 0 additions & 8 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,14 +877,6 @@ def _construct_direct(
obj._encoding = encoding
return obj

@classmethod
def _from_vars_and_coord_names(
cls, variables, coord_names, indexes=None, attrs=None
):
return cls._construct_direct(
variables, coord_names, indexes=indexes, attrs=attrs
)

def _replace(
self,
variables: Dict[Hashable, Variable] = None,
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ def test_selection_multiindex_from_level(self):
data = xr.concat([da, db], dim="x").set_index(xy=["x", "y"])
assert data.dims == ("xy",)
actual = data.sel(y="a")
expected = data.isel(xy=[0, 1]).unstack("xy").squeeze("y").drop("y")
expected = data.isel(xy=[0, 1]).unstack("xy").squeeze("y").drop_vars("y")
assert_equal(actual, expected)

def test_virtual_default_coords(self):
Expand Down