Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some code quality and bug-risk issues
Browse files Browse the repository at this point in the history
pnijhara committed Apr 23, 2020
1 parent c788ee4 commit dc5b805
Showing 9 changed files with 36 additions and 17 deletions.
18 changes: 18 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version = 1

test_patterns = [
"*/tests/**",
"*/test_*.py"
]

exclude_patterns = [
"doc/**",
"ci/**"
]

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include LICENSE
include *.toml
recursive-include licenses *
recursive-include doc *
prune doc/_build
4 changes: 2 additions & 2 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
@@ -987,9 +987,9 @@ def cftime_range(
else:
raise ValueError("Closed must be either 'left', 'right' or None")

if not left_closed and len(dates) and start is not None and dates[0] == start:
if not left_closed and dates and start is not None and dates[0] == start:
dates = dates[1:]
if not right_closed and len(dates) and end is not None and dates[-1] == end:
if not right_closed and dates and end is not None and dates[-1] == end:
dates = dates[:-1]

return CFTimeIndex(dates, name=name)
2 changes: 1 addition & 1 deletion xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ def _partial_date_slice(self, resolution, parsed):
times = self._data

if self.is_monotonic:
if len(times) and (
if times and (
(start < times[0] and end < times[0])
or (start > times[-1] and end > times[-1])
):
6 changes: 3 additions & 3 deletions xarray/convert.py
Original file line number Diff line number Diff line change
@@ -229,11 +229,11 @@ def _iris_cell_methods_to_str(cell_methods_obj):
"""
cell_methods = []
for cell_method in cell_methods_obj:
names = "".join([f"{n}: " for n in cell_method.coord_names])
names = "".join(f"{n}: " for n in cell_method.coord_names)
intervals = " ".join(
[f"interval: {interval}" for interval in cell_method.intervals]
f"interval: {interval}" for interval in cell_method.intervals
)
comments = " ".join([f"comment: {comment}" for comment in cell_method.comments])
comments = " ".join(f"comment: {comment}" for comment in cell_method.comments)
extra = " ".join([intervals, comments]).strip()
if extra:
extra = f" ({extra})"
4 changes: 2 additions & 2 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
@@ -1192,10 +1192,10 @@ def dot(*arrays, dims=None, **kwargs):
# construct einsum subscripts, such as '...abc,...ab->...c'
# Note: input_core_dims are always moved to the last position
subscripts_list = [
"..." + "".join([dim_map[d] for d in ds]) for ds in input_core_dims
"..." + "".join(dim_map[d] for d in ds) for ds in input_core_dims
]
subscripts = ",".join(subscripts_list)
subscripts += "->..." + "".join([dim_map[d] for d in output_core_dims[0]])
subscripts += "->..." + "".join(dim_map[d] for d in output_core_dims[0])

join = OPTIONS["arithmetic_join"]
# using "inner" emulates `(a * b).sum()` for all joins (except "exact")
12 changes: 5 additions & 7 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
@@ -298,12 +298,10 @@ def _summarize_coord_multiindex(coord, col_width, marker):

def _summarize_coord_levels(coord, col_width, marker="-"):
return "\n".join(
[
summarize_variable(
lname, coord.get_level_variable(lname), col_width, marker=marker
)
for lname in coord.level_names
]
summarize_variable(
lname, coord.get_level_variable(lname), col_width, marker=marker
)
for lname in coord.level_names
)


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

for m in (a_mapping, b_mapping):
attr_s = "\n".join(
[summarize_attr(ak, av) for ak, av in m[k].attrs.items()]
summarize_attr(ak, av) for ak, av in m[k].attrs.items()
)
attrs_summary.append(attr_s)

4 changes: 3 additions & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ def __init__(
grouper=None,
bins=None,
restore_coord_dims=None,
cut_kwargs={},
cut_kwargs=None,
):
"""Create a GroupBy object
@@ -299,6 +299,8 @@ def __init__(
Extra keyword arguments to pass to `pandas.cut`
"""
if cut_kwargs is None:
cut_kwargs = {}
from .dataarray import DataArray

if grouper is not None and bins is not None:
2 changes: 1 addition & 1 deletion xarray/plot/plot.py
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@

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

0 comments on commit dc5b805

Please sign in to comment.