Skip to content

Commit

Permalink
replace duplicate method _from_vars_and_coord_names (#3565)
Browse files Browse the repository at this point in the history
* replace duplicate method _from_vars_and_coord_names

* drop_vars

* whatsnew
  • Loading branch information
max-sixty authored and dcherian committed Nov 23, 2019
1 parent 8aabaf0 commit 06b8ee4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
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

0 comments on commit 06b8ee4

Please sign in to comment.