Skip to content

Fix some code quality and bug-risk issues #3999

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 1 commit into from
Apr 24, 2020
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
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"
Comment on lines +1 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary for deepsource to give useful results? I guess we can give it a try if you want to keep on making contributions using it, but I don't want to add it to CI at this time and if it doesn't get much use we'll probably eventually remove it.

Copy link
Contributor Author

@pnijhara pnijhara Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, Deepsource gives useful results. As it is used by many other projects like https://github.com/uber/ludwig and https://github.com/slackapi/python-slackclient/
I think Pydata should also give it a try.

6 changes: 3 additions & 3 deletions xarray/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 5 additions & 7 deletions xarray/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __init__(
grouper=None,
bins=None,
restore_coord_dims=None,
cut_kwargs={},
cut_kwargs=None,
):
"""Create a GroupBy object

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down