Skip to content

More Pylint issues #10463

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
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: 0 additions & 4 deletions properties/test_index_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,13 @@ def assert_invariants(self):

@pytest.mark.skip(reason="failure detected by hypothesis")
def test_unstack_object():
import xarray as xr

ds = xr.Dataset()
ds["0"] = np.array(["", "\x000"], dtype=object)
ds.stack({"1": ["0"]}).unstack()


@pytest.mark.skip(reason="failure detected by hypothesis")
def test_unstack_timedelta_index():
import xarray as xr

ds = xr.Dataset()
ds["0"] = np.array([0, 1, 2, 3], dtype="timedelta64[ns]")
ds.stack({"1": ["0"]}).unstack()
2 changes: 0 additions & 2 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,6 @@ def date_range(
cftime_range
date_range_like
"""
from xarray.coding.times import _is_standard_calendar

if tz is not None:
use_cftime = False

Expand Down
2 changes: 0 additions & 2 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,6 @@ def asi8(self):
@property
def calendar(self):
"""The calendar used by the datetimes in the index."""
from xarray.coding.times import infer_calendar_name

if not self._data.size:
return None

Expand Down
1 change: 0 additions & 1 deletion xarray/computation/apply_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ def apply_groupby_func(func, *args):
DataArray, Variable and/or ndarray objects.
"""
from xarray.core.groupby import GroupBy, peek_at
from xarray.core.variable import Variable

groupbys = [arg for arg in args if isinstance(arg, GroupBy)]
assert groupbys, "must have at least one groupby to iterate over"
Expand Down
1 change: 0 additions & 1 deletion xarray/computation/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ def dot(
array(235)
"""
from xarray.core.dataarray import DataArray
from xarray.core.variable import Variable

if any(not isinstance(arr, Variable | DataArray) for arr in arrays):
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion xarray/computation/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def _wrapper(Y, *args, **kwargs):
mask = np.all([np.any(~np.isnan(x), axis=0), ~np.isnan(y)], axis=0)
x = x[:, mask]
y = y[mask]
if not len(y):
if y.size == 0:
popt = np.full([n_params], np.nan)
pcov = np.full([n_params, n_params], np.nan)
return popt, pcov
Expand Down
2 changes: 0 additions & 2 deletions xarray/computation/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ def nansum(a, axis=None, dtype=None, out=None, min_count=None):

def _nanmean_ddof_object(ddof, value, axis=None, dtype=None, **kwargs):
"""In house nanmean. ddof argument will be used in _nanvar method"""
from xarray.core.duck_array_ops import count, fillna, where_method

valid_count = count(value, axis=axis)
value = fillna(value, 0)
# As dtype inference is impossible for object dtype, we assume float
Expand Down
4 changes: 0 additions & 4 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,6 @@ def _setitem_check(self, key, value):
to avoid leaving the dataset in a partially updated state when an error occurs.
"""
from xarray.core.dataarray import DataArray
from xarray.structure.alignment import align

if isinstance(value, Dataset):
missing_vars = [
Expand Down Expand Up @@ -2551,7 +2550,6 @@ def _validate_indexers(
+ string indexers are cast to the appropriate date type if the
associated index is a DatetimeIndex or CFTimeIndex
"""
from xarray.coding.cftimeindex import CFTimeIndex
from xarray.core.dataarray import DataArray

indexers = drop_dims_from_indexers(indexers, self.dims, missing_dims)
Expand Down Expand Up @@ -8268,8 +8266,6 @@ def differentiate(
--------
numpy.gradient: corresponding numpy function
"""
from xarray.core.variable import Variable

if coord not in self.variables and coord not in self.dims:
variables_and_dims = tuple(set(self.variables.keys()).union(self.dims))
raise ValueError(
Expand Down
1 change: 0 additions & 1 deletion xarray/core/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,6 @@ def _unary_op(self, f, *args, **kwargs) -> DataTree:
return self.map_over_datasets(functools.partial(f, **kwargs), *args) # type: ignore[return-value]

def _binary_op(self, other, f, reflexive=False, join=None) -> DataTree:
from xarray.core.dataset import Dataset
from xarray.core.groupby import GroupBy

if isinstance(other, GroupBy):
Expand Down
6 changes: 1 addition & 5 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@


def einsum(*args, **kwargs):
from xarray.core.options import OPTIONS

if OPTIONS["use_opt_einsum"] and module_available("opt_einsum"):
import opt_einsum

Expand Down Expand Up @@ -250,7 +248,7 @@

if xp == np:
# numpy currently doesn't have a astype:
return data.astype(dtype, **kwargs)

Check warning on line 251 in xarray/core/duck_array_ops.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

invalid value encountered in cast

Check warning on line 251 in xarray/core/duck_array_ops.py

View workflow job for this annotation

GitHub Actions / macos-latest py3.10

invalid value encountered in cast

Check warning on line 251 in xarray/core/duck_array_ops.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

invalid value encountered in cast

Check warning on line 251 in xarray/core/duck_array_ops.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest py3.10

invalid value encountered in cast
return xp.astype(data, dtype, **kwargs)


Expand Down Expand Up @@ -681,9 +679,7 @@
The output data type.

"""
import datetime as dt

if isinstance(value, dt.timedelta):
if isinstance(value, datetime.timedelta):
out = py_timedelta_to_float(value, datetime_unit)
elif isinstance(value, np.timedelta64):
out = np_timedelta64_to_float(value, datetime_unit)
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def factorize(self) -> EncodedGroups:
_flatcodes = where(mask.data, -1, _flatcodes)

full_index = pd.MultiIndex.from_product(
list(grouper.full_index.values for grouper in groupers),
[grouper.full_index.values for grouper in groupers],
names=tuple(grouper.name for grouper in groupers),
)
if not full_index.is_unique:
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/treenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,12 @@ def _path_to_ancestor(self, ancestor: NamedNode) -> NodePath:
raise NotFoundInTreeError(
"Cannot find relative path to ancestor because nodes do not lie within the same tree"
)
if ancestor.path not in list(a.path for a in (self, *self.parents)):
if ancestor.path not in [a.path for a in (self, *self.parents)]:
raise NotFoundInTreeError(
"Cannot find relative path to ancestor because given node is not an ancestor of this node"
)

parents_paths = list(parent.path for parent in (self, *self.parents))
parents_paths = [parent.path for parent in (self, *self.parents)]
generation_gap = list(parents_paths).index(ancestor.path)
path_upwards = "../" * generation_gap if generation_gap > 0 else "."
return NodePath(path_upwards)
Expand Down
4 changes: 0 additions & 4 deletions xarray/groupers.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ def reset(self) -> Self:
)

def _init_properties(self, group: T_Group) -> None:
from xarray import CFTimeIndex

group_as_index = safe_cast_to_index(group)
offset = self.offset

Expand All @@ -494,8 +492,6 @@ def _init_properties(self, group: T_Group) -> None:
raise ValueError("Index must be monotonic for resampling")

if isinstance(group_as_index, CFTimeIndex):
from xarray.core.resample_cftime import CFTimeGrouper

self.index_grouper = CFTimeGrouper(
freq=self.freq,
closed=self.closed,
Expand Down
4 changes: 0 additions & 4 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,6 @@ def get_axis(
ax: Axes | None = None,
**subplot_kws: Any,
) -> Axes:
from xarray.core.utils import attempt_import

if TYPE_CHECKING:
import matplotlib as mpl
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -1048,8 +1046,6 @@ def legend_elements(
labels : list of str
The string labels for elements of the legend.
"""
import warnings

import matplotlib as mpl

mlines = mpl.lines
Expand Down
2 changes: 1 addition & 1 deletion xarray/structure/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def process_subset_opt(opt, subset):
elif opt == "all":
concat_over.update(
set().union(
*list(set(getattr(d, subset)) - set(d.dims) for d in datasets)
*[set(getattr(d, subset)) - set(d.dims) for d in datasets]
)
)
elif opt == "minimal":
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def test_nones(self) -> None:

def test_full(self, simple_datatree) -> None:
dt = simple_datatree
paths = list(node.path for node in dt.subtree)
paths = [node.path for node in dt.subtree]
assert paths == [
"/",
"/set1",
Expand Down
2 changes: 0 additions & 2 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3256,8 +3256,6 @@ def test_shuffle_simple() -> None:
def test_shuffle_by(chunks, expected_chunks):
import dask.array

from xarray.groupers import UniqueGrouper

da = xr.DataArray(
dims="x",
data=dask.array.arange(10, chunks=chunks),
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ def test_searchsorted(self, func, unit, error, dtype):
data_array = xr.DataArray(data=array)

scalar_types = (int, float)
args = list(value * unit for value in func.args)
args = [value * unit for value in func.args]
kwargs = {
key: (value * unit if isinstance(value, scalar_types) else value)
for key, value in func.kwargs.items()
Expand Down Expand Up @@ -2708,7 +2708,7 @@ def test_numpy_methods_with_args(self, func, unit, error, dtype):
data_array = xr.DataArray(data=array)

scalar_types = (int, float)
args = list(value * unit for value in func.args)
args = [value * unit for value in func.args]
kwargs = {
key: (value * unit if isinstance(value, scalar_types) else value)
for key, value in func.kwargs.items()
Expand Down
Loading