Skip to content

Commit

Permalink
Fix: code quality issues (#167)
Browse files Browse the repository at this point in the history
- Removed unnecessary comprehension

- Used literal syntax instead of function calls to create data structure

- Used literal syntax to create data structure

- added .deepsource.toml file
  • Loading branch information
withshubh authored Feb 7, 2021
1 parent d7f0c15 commit 19b5d20
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = 1

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

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

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

[analyzers.meta]
runtime_version = "3.x.x"
8 changes: 4 additions & 4 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _apply_single_mapper(mapper):
else:
results = flat

nresults = any([bool(v) for v in [results]])
nresults = any(bool(v) for v in [results])
if not nresults:
if error:
raise KeyError(
Expand Down Expand Up @@ -497,7 +497,7 @@ def _getattr(
if not attribute:
return dict(attribute)

newmap = dict()
newmap = {}
inverted = invert_mappings(
accessor.axes,
accessor.coordinates,
Expand Down Expand Up @@ -1165,7 +1165,7 @@ def cell_measures(self) -> Dict[str, List[str]]:
da.attrs.get("cell_measures", "") for da in obj.data_vars.values()
]

measures: Dict[str, List[str]] = dict()
measures: Dict[str, List[str]] = {}
for attr in all_attrs:
for key, value in parse_cell_methods_attr(attr).items():
measures[key] = measures.setdefault(key, []) + [value]
Expand Down Expand Up @@ -1201,7 +1201,7 @@ def standard_names(self) -> Dict[str, List[str]]:
elif isinstance(self._obj, DataArray):
variables = self._obj.coords

vardict: Dict[str, List[str]] = dict()
vardict: Dict[str, List[str]] = {}
for k, v in variables.items():
if "standard_name" in v.attrs:
std_name = v.attrs["standard_name"]
Expand Down
4 changes: 2 additions & 2 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def test_dataarray_plot():
plt.close()

rv = obj.isel(lat=[0, 1], lon=1).cf.plot.line(x="T", hue="Y")
assert all([isinstance(line, mpl.lines.Line2D) for line in rv])
assert all(isinstance(line, mpl.lines.Line2D) for line in rv)
plt.close()

# set y automatically
Expand Down Expand Up @@ -517,7 +517,7 @@ def test_plot_xincrease_yincrease():
@pytest.mark.parametrize("dims", ["lat", "time", ["lat", "lon"]])
@pytest.mark.parametrize("obj", [airds])
def test_add_bounds(obj, dims):
expected = dict()
expected = {}
expected["lat"] = xr.concat(
[
obj.lat.copy(data=np.arange(76.25, 16.0, -2.5)),
Expand Down
2 changes: 1 addition & 1 deletion cf_xarray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def invert_mappings(*mappings):
for mapping in mappings:
for k, v in mapping.items():
for name in v:
merged[name] |= set([k])
merged[name] |= {k}
return merged

0 comments on commit 19b5d20

Please sign in to comment.