diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 051a41a57e5..1993e543322 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -129,6 +129,10 @@ Internal Changes - Use ``async`` / ``await`` for the asynchronous distributed tests. (:issue:`3987`, :pull:`3989`) By `Justus Magin `_. +- Remove unnecessary comprehensions becuase the built-in functions like + ``all``, ``any``, ``enumerate``, ``sum``, ``tuple`` etc. can work directly with a + generator expression. (:pull:`4026`) + By `Prajjwal Nijhara `_. .. _whats-new.0.15.1: diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 148e16863d1..85dd735c2fe 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -29,7 +29,7 @@ def check_reduce_dims(reduce_dims, dimensions): if reduce_dims is not ...: if is_scalar(reduce_dims): reduce_dims = [reduce_dims] - if any([dim not in dimensions for dim in reduce_dims]): + if any(dim not in dimensions for dim in reduce_dims): raise ValueError( "cannot reduce over dimensions %r. expected either '...' to reduce over all dimensions or one or more of %r." % (reduce_dims, dimensions) diff --git a/xarray/core/pdcompat.py b/xarray/core/pdcompat.py index f2e4518e0dc..f2e22329fc8 100644 --- a/xarray/core/pdcompat.py +++ b/xarray/core/pdcompat.py @@ -55,4 +55,4 @@ def count_not_none(*args) -> int: Copied from pandas.core.common.count_not_none (not part of the public API) """ - return sum([arg is not None for arg in args]) + return sum(arg is not None for arg in args) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 68e823ca426..e19132b1b06 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -2412,7 +2412,7 @@ def assert_unique_multiindex_level_names(variables): duplicate_names = [v for v in level_names.values() if len(v) > 1] if duplicate_names: - conflict_str = "\n".join([", ".join(v) for v in duplicate_names]) + conflict_str = "\n".join(", ".join(v) for v in duplicate_names) raise ValueError("conflicting MultiIndex level name(s):\n%s" % conflict_str) # Check confliction between level names and dimensions GH:2299 for k, v in variables.items():