Skip to content

Commit dc5b805

Browse files
committed
Fix some code quality and bug-risk issues
1 parent c788ee4 commit dc5b805

File tree

9 files changed

+36
-17
lines changed

9 files changed

+36
-17
lines changed

.deepsource.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version = 1
2+
3+
test_patterns = [
4+
"*/tests/**",
5+
"*/test_*.py"
6+
]
7+
8+
exclude_patterns = [
9+
"doc/**",
10+
"ci/**"
11+
]
12+
13+
[[analyzers]]
14+
name = "python"
15+
enabled = true
16+
17+
[analyzers.meta]
18+
runtime_version = "3.x.x"

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include LICENSE
2+
include *.toml
23
recursive-include licenses *
34
recursive-include doc *
45
prune doc/_build

xarray/coding/cftime_offsets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,9 @@ def cftime_range(
987987
else:
988988
raise ValueError("Closed must be either 'left', 'right' or None")
989989

990-
if not left_closed and len(dates) and start is not None and dates[0] == start:
990+
if not left_closed and dates and start is not None and dates[0] == start:
991991
dates = dates[1:]
992-
if not right_closed and len(dates) and end is not None and dates[-1] == end:
992+
if not right_closed and dates and end is not None and dates[-1] == end:
993993
dates = dates[:-1]
994994

995995
return CFTimeIndex(dates, name=name)

xarray/coding/cftimeindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _partial_date_slice(self, resolution, parsed):
309309
times = self._data
310310

311311
if self.is_monotonic:
312-
if len(times) and (
312+
if times and (
313313
(start < times[0] and end < times[0])
314314
or (start > times[-1] and end > times[-1])
315315
):

xarray/convert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ def _iris_cell_methods_to_str(cell_methods_obj):
229229
"""
230230
cell_methods = []
231231
for cell_method in cell_methods_obj:
232-
names = "".join([f"{n}: " for n in cell_method.coord_names])
232+
names = "".join(f"{n}: " for n in cell_method.coord_names)
233233
intervals = " ".join(
234-
[f"interval: {interval}" for interval in cell_method.intervals]
234+
f"interval: {interval}" for interval in cell_method.intervals
235235
)
236-
comments = " ".join([f"comment: {comment}" for comment in cell_method.comments])
236+
comments = " ".join(f"comment: {comment}" for comment in cell_method.comments)
237237
extra = " ".join([intervals, comments]).strip()
238238
if extra:
239239
extra = f" ({extra})"

xarray/core/computation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,10 @@ def dot(*arrays, dims=None, **kwargs):
11921192
# construct einsum subscripts, such as '...abc,...ab->...c'
11931193
# Note: input_core_dims are always moved to the last position
11941194
subscripts_list = [
1195-
"..." + "".join([dim_map[d] for d in ds]) for ds in input_core_dims
1195+
"..." + "".join(dim_map[d] for d in ds) for ds in input_core_dims
11961196
]
11971197
subscripts = ",".join(subscripts_list)
1198-
subscripts += "->..." + "".join([dim_map[d] for d in output_core_dims[0]])
1198+
subscripts += "->..." + "".join(dim_map[d] for d in output_core_dims[0])
11991199

12001200
join = OPTIONS["arithmetic_join"]
12011201
# using "inner" emulates `(a * b).sum()` for all joins (except "exact")

xarray/core/formatting.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,10 @@ def _summarize_coord_multiindex(coord, col_width, marker):
298298

299299
def _summarize_coord_levels(coord, col_width, marker="-"):
300300
return "\n".join(
301-
[
302-
summarize_variable(
303-
lname, coord.get_level_variable(lname), col_width, marker=marker
304-
)
305-
for lname in coord.level_names
306-
]
301+
summarize_variable(
302+
lname, coord.get_level_variable(lname), col_width, marker=marker
303+
)
304+
for lname in coord.level_names
307305
)
308306

309307

@@ -562,7 +560,7 @@ def extra_items_repr(extra_keys, mapping, ab_side):
562560

563561
for m in (a_mapping, b_mapping):
564562
attr_s = "\n".join(
565-
[summarize_attr(ak, av) for ak, av in m[k].attrs.items()]
563+
summarize_attr(ak, av) for ak, av in m[k].attrs.items()
566564
)
567565
attrs_summary.append(attr_s)
568566

xarray/core/groupby.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def __init__(
273273
grouper=None,
274274
bins=None,
275275
restore_coord_dims=None,
276-
cut_kwargs={},
276+
cut_kwargs=None,
277277
):
278278
"""Create a GroupBy object
279279
@@ -299,6 +299,8 @@ def __init__(
299299
Extra keyword arguments to pass to `pandas.cut`
300300
301301
"""
302+
if cut_kwargs is None:
303+
cut_kwargs = {}
302304
from .dataarray import DataArray
303305

304306
if grouper is not None and bins is not None:

xarray/plot/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def _infer_line_data(darray, x, y, hue):
3232
error_msg = "must be either None or one of ({:s})".format(
33-
", ".join([repr(dd) for dd in darray.dims])
33+
", ".join(repr(dd) for dd in darray.dims)
3434
)
3535
ndims = len(darray.dims)
3636

0 commit comments

Comments
 (0)