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

Raise on inplace=True #3260

Merged
merged 9 commits into from
Aug 26, 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
5 changes: 4 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ This release increases the minimum required Python version from 3.5.0 to 3.5.3
Breaking changes
~~~~~~~~~~~~~~~~

The ``isel_points`` and ``sel_points`` methods are removed, having been deprecated
- The ``isel_points`` and ``sel_points`` methods are removed, having been deprecated
since v0.10.0. These are redundant with the ``isel`` / ``sel`` methods.
See :ref:`vectorized_indexing` for the details
By `Maximilian Roos <https://github.com/max-sixty>`_
- The ``inplace`` kwarg for public methods now raises an error, having been deprecated
since v0.11.0.
By `Maximilian Roos <https://github.com/max-sixty>`_

New functions/methods
~~~~~~~~~~~~~~~~~~~~~
Expand Down
59 changes: 12 additions & 47 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,30 +700,17 @@ def reset_coords(
drop : bool, optional
If True, remove coordinates instead of converting them into
variables.
inplace : bool, optional
If True, modify this object in place. Otherwise, create a new
object.

Returns
-------
Dataset, or DataArray if ``drop == True``, or None if
``inplace == True``
Dataset, or DataArray if ``drop == True``
"""
inplace = _check_inplace(inplace)
if inplace and not drop:
raise ValueError(
"cannot reset coordinates in-place on a "
"DataArray without ``drop == True``"
)
_check_inplace(inplace)
if names is None:
names = set(self.coords) - set(self.dims)
dataset = self.coords.to_dataset().reset_coords(names, drop)
if drop:
if inplace:
self._coords = dataset._variables
return None
else:
return self._replace(coords=dataset._variables)
return self._replace(coords=dataset._variables)
else:
if self.name is None:
raise ValueError(
Expand Down Expand Up @@ -1485,9 +1472,6 @@ def set_index(
append : bool, optional
If True, append the supplied index(es) to the existing index(es).
Otherwise replace the existing index(es) (default).
inplace : bool, optional
If True, set new index(es) in-place. Otherwise, return a new
DataArray object.
**indexes_kwargs: optional
The keyword arguments form of ``indexes``.
One of indexes or indexes_kwargs must be provided.
Expand All @@ -1496,7 +1480,6 @@ def set_index(
-------
obj : DataArray
Another DataArray, with this data but replaced coordinates.
Return None if inplace=True.

Example
-------
Expand Down Expand Up @@ -1526,14 +1509,10 @@ def set_index(
--------
DataArray.reset_index
"""
inplace = _check_inplace(inplace)
_check_inplace(inplace)
indexes = either_dict_or_kwargs(indexes, indexes_kwargs, "set_index")
coords, _ = merge_indexes(indexes, self._coords, set(), append=append)
if inplace:
self._coords = coords
return None
else:
return self._replace(coords=coords)
return self._replace(coords=coords)

def reset_index(
self,
Expand All @@ -1551,36 +1530,29 @@ def reset_index(
drop : bool, optional
If True, remove the specified indexes and/or multi-index levels
instead of extracting them as new coordinates (default: False).
inplace : bool, optional
If True, modify the dataarray in-place. Otherwise, return a new
DataArray object.

Returns
-------
obj : DataArray
Another dataarray, with this dataarray's data but replaced
coordinates. If ``inplace == True``, return None.
coordinates.

See Also
--------
DataArray.set_index
"""
inplace = _check_inplace(inplace)
_check_inplace(inplace)
coords, _ = split_indexes(
dims_or_levels, self._coords, set(), self._level_coords, drop=drop
)
if inplace:
self._coords = coords
return None
else:
return self._replace(coords=coords)
return self._replace(coords=coords)

def reorder_levels(
self,
dim_order: Mapping[Hashable, Sequence[int]] = None,
inplace: bool = None,
**dim_order_kwargs: Sequence[int]
) -> Optional["DataArray"]:
) -> "DataArray":
"""Rearrange index levels using input order.

Parameters
Expand All @@ -1589,9 +1561,6 @@ def reorder_levels(
Mapping from names matching dimensions and values given
by lists representing new level orders. Every given dimension
must have a multi-index.
inplace : bool, optional
If True, modify the dataarray in-place. Otherwise, return a new
DataArray object.
**dim_order_kwargs: optional
The keyword arguments form of ``dim_order``.
One of dim_order or dim_order_kwargs must be provided.
Expand All @@ -1600,9 +1569,9 @@ def reorder_levels(
-------
obj : DataArray
Another dataarray, with this dataarray's data but replaced
coordinates. If ``inplace == True``, return None.
coordinates.
"""
inplace = _check_inplace(inplace)
_check_inplace(inplace)
dim_order = either_dict_or_kwargs(dim_order, dim_order_kwargs, "reorder_levels")
replace_coords = {}
for dim, order in dim_order.items():
Expand All @@ -1613,11 +1582,7 @@ def reorder_levels(
replace_coords[dim] = IndexVariable(coord.dims, index.reorder_levels(order))
coords = self._coords.copy()
coords.update(replace_coords)
if inplace:
self._coords = coords
return None
else:
return self._replace(coords=coords)
return self._replace(coords=coords)

def stack(
self,
Expand Down
Loading