Skip to content

Commit 85a6729

Browse files
committed
Add docstrings throughout
1 parent fe4a503 commit 85a6729

File tree

7 files changed

+69
-17
lines changed

7 files changed

+69
-17
lines changed

pyproject.toml

+16-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,21 @@ profile = "black"
1414
line_length = 79
1515

1616
[tool.ruff]
17-
1817
target-version = "py38"
19-
select = ["I", "UP", "F", "E", "W"]
18+
select = ["I", "UP", "F", "E", "W", "D"]
19+
ignore = [
20+
"D100", # Missing docstring in public module
21+
"D200", # One-line docstring should fit on one line
22+
"D205", # 1 blank line required between summary line and description
23+
"D400", # First line should end with a period
24+
"D401", # First line of docstring should be in imperative mood
25+
]
2026
fix = true
27+
28+
[tool.ruff.per-file-ignores]
29+
"docs/*" = ["D"]
30+
"examples/*" = ["D"]
31+
"src/napari_matplotlib/tests/*" = ["D"]
32+
33+
[tool.ruff.pydocstyle]
34+
convention = "numpy"

src/napari_matplotlib/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
class NapariMPLWidget(QWidget):
3232
"""
33-
Base widget that can be embedded as a napari widget and contains a
34-
Matplotlib canvas.
33+
Base Matplotlib canvas. widget that can be embedded as a napari widget.
3534
3635
This creates a single FigureCanvas, which contains a single Figure.
3736
@@ -90,7 +89,9 @@ def current_z(self) -> int:
9089

9190
def setup_callbacks(self) -> None:
9291
"""
93-
Setup callbacks for:
92+
Sets up callbacks.
93+
94+
Sets up callbacks for:
9495
- Layer selection changing
9596
- z-step changing
9697
"""
@@ -135,7 +136,7 @@ def draw(self) -> None:
135136

136137
def _on_update_layers(self) -> None:
137138
"""
138-
This function is called when self.layers is updated via
139+
Function is called when self.layers is updated via
139140
``self.update_layers()``.
140141
141142
This is a no-op, and is intended for derived classes to override.

src/napari_matplotlib/histogram.py

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
2525
self.update_layers(None)
2626

2727
def clear(self) -> None:
28+
"""
29+
Clear the axes.
30+
"""
2831
self.axes.clear()
2932

3033
def draw(self) -> None:

src/napari_matplotlib/scatter.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414

1515
class ScatterBaseWidget(NapariMPLWidget):
16+
"""
17+
Base class for widgets that scatter two datasets against each other.
18+
"""
19+
1620
# opacity value for the markers
1721
_marker_alpha = 0.5
1822

@@ -90,7 +94,8 @@ class ScatterWidget(ScatterBaseWidget):
9094
input_layer_types = (napari.layers.Image,)
9195

9296
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
93-
"""Get the plot data.
97+
"""
98+
Get the plot data.
9499
95100
Returns
96101
-------
@@ -109,6 +114,10 @@ def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
109114

110115

111116
class FeaturesScatterWidget(ScatterBaseWidget):
117+
"""
118+
Widget to scatter data stored in two layer feature attributes.
119+
"""
120+
112121
n_layers_input = Interval(1, 1)
113122
# All layers that have a .features attributes
114123
input_layer_types = (
@@ -132,7 +141,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
132141

133142
@property
134143
def x_axis_key(self) -> Optional[str]:
135-
"""Key to access x axis data from the FeaturesTable"""
144+
"""
145+
Key to access x axis data from the FeaturesTable.
146+
"""
136147
return self._x_axis_key
137148

138149
@x_axis_key.setter
@@ -142,16 +153,23 @@ def x_axis_key(self, key: Optional[str]) -> None:
142153

143154
@property
144155
def y_axis_key(self) -> Optional[str]:
145-
"""Key to access y axis data from the FeaturesTable"""
156+
"""
157+
Key to access y axis data from the FeaturesTable.
158+
"""
146159
return self._y_axis_key
147160

148161
@y_axis_key.setter
149162
def y_axis_key(self, key: Optional[str]) -> None:
163+
"""
164+
Set the y-axis key.
165+
"""
150166
self._y_axis_key = key
151167
self._draw()
152168

153169
def _set_axis_keys(self, x_axis_key: str, y_axis_key: str) -> None:
154-
"""Set both axis keys and then redraw the plot"""
170+
"""
171+
Set both axis keys and then redraw the plot.
172+
"""
155173
self._x_axis_key = x_axis_key
156174
self._y_axis_key = y_axis_key
157175
self._draw()
@@ -174,7 +192,8 @@ def _get_valid_axis_keys(
174192
return self.layers[0].features.keys()
175193

176194
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
177-
"""Get the plot data.
195+
"""
196+
Get the plot data.
178197
179198
Returns
180199
-------
@@ -213,8 +232,7 @@ def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
213232

214233
def _on_update_layers(self) -> None:
215234
"""
216-
This is called when the layer selection changes by
217-
``self.update_layers()``.
235+
Called when the layer selection changes by ``self.update_layers()``.
218236
"""
219237
if hasattr(self, "_key_selection_widget"):
220238
self._key_selection_widget.reset_choices()

src/napari_matplotlib/slice.py

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
5050

5151
@property
5252
def layer(self):
53+
"""
54+
Layer being plotted.
55+
"""
5356
return self.layers[0]
5457

5558
@property
@@ -70,6 +73,9 @@ def current_dim_index(self) -> int:
7073

7174
@property
7275
def selector_values(self) -> Dict[str, int]:
76+
"""
77+
Values of the slice selectors.
78+
"""
7379
return {d: self.slice_selectors[d].value() for d in _dims_sel}
7480

7581
def update_slice_selectors(self) -> None:
@@ -107,6 +113,9 @@ def get_xy(self) -> Tuple[np.ndarray, np.ndarray]:
107113
return x, y
108114

109115
def clear(self) -> None:
116+
"""
117+
Clear the axes.
118+
"""
110119
self.axes.cla()
111120

112121
def draw(self) -> None:

src/napari_matplotlib/tests/test_scatter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def make_labels_layer_with_features():
3434

3535

3636
def test_features_scatter_get_data(make_napari_viewer):
37-
"""test the get data method"""
37+
"""Test the get data method"""
3838
# make the label image
3939
label_image, feature_table = make_labels_layer_with_features()
4040

@@ -59,7 +59,7 @@ def test_features_scatter_get_data(make_napari_viewer):
5959

6060

6161
def test_get_valid_axis_keys(make_napari_viewer):
62-
"""test the values returned from
62+
"""Test the values returned from
6363
FeaturesScatterWidget._get_valid_keys() when there
6464
are valid keys.
6565
"""
@@ -76,7 +76,7 @@ def test_get_valid_axis_keys(make_napari_viewer):
7676

7777

7878
def test_get_valid_axis_keys_no_valid_keys(make_napari_viewer):
79-
"""test the values returned from
79+
"""Test the values returned from
8080
FeaturesScatterWidget._get_valid_keys() when there
8181
are not valid keys.
8282
"""

src/napari_matplotlib/util.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
class Interval:
5+
"""
6+
An integer interval.
7+
"""
8+
59
def __init__(self, lower_bound: Optional[int], upper_bound: Optional[int]):
610
"""
711
Parameters
@@ -19,7 +23,10 @@ def __init__(self, lower_bound: Optional[int], upper_bound: Optional[int]):
1923
self.lower = lower_bound
2024
self.upper = upper_bound
2125

22-
def __contains__(self, val):
26+
def __contains__(self, val: int) -> bool:
27+
"""
28+
Return True if val is in the current interval.
29+
"""
2330
if not isinstance(val, int):
2431
raise ValueError("variable must be an integer")
2532
if self.lower is not None and val < self.lower:

0 commit comments

Comments
 (0)