Skip to content

Commit 2e70f58

Browse files
authored
Merge pull request #32 from ksunden/black
Rewrap (with black) to 88 chars instead of 115
2 parents 1e2ad42 + 333db3a commit 2e70f58

15 files changed

+150
-42
lines changed

Diff for: .pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ default_language_version:
22
python: python3
33
repos:
44
- repo: https://github.com/ambv/black
5-
rev: stable
5+
rev: 23.3.0
66
hooks:
77
- id: black
88
- repo: https://github.com/pre-commit/pre-commit-hooks
99
rev: v2.0.0
1010
hooks:
1111
- id: flake8
1212
- repo: https://github.com/kynan/nbstripout
13-
rev: 0.3.9
13+
rev: 0.6.1
1414
hooks:
1515
- id: nbstripout

Diff for: data_prototype/containers.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def query(
117117
coord_transform: _MatplotlibTransform,
118118
size: Tuple[int, int],
119119
) -> Tuple[Dict[str, Any], Union[str, int]]:
120-
return {k: np.random.randn(*d.shape) for k, d in self._desc.items()}, str(uuid.uuid4())
120+
return {k: np.random.randn(*d.shape) for k, d in self._desc.items()}, str(
121+
uuid.uuid4()
122+
)
121123

122124
def describe(self) -> Dict[str, Desc]:
123125
return dict(self._desc)
@@ -127,9 +129,15 @@ class FuncContainer:
127129
def __init__(
128130
self,
129131
# TODO: is this really the best spelling?!
130-
xfuncs: Optional[Dict[str, Tuple[Tuple[Union[str, int], ...], Callable[[Any], Any]]]] = None,
131-
yfuncs: Optional[Dict[str, Tuple[Tuple[Union[str, int], ...], Callable[[Any], Any]]]] = None,
132-
xyfuncs: Optional[Dict[str, Tuple[Tuple[Union[str, int], ...], Callable[[Any, Any], Any]]]] = None,
132+
xfuncs: Optional[
133+
Dict[str, Tuple[Tuple[Union[str, int], ...], Callable[[Any], Any]]]
134+
] = None,
135+
yfuncs: Optional[
136+
Dict[str, Tuple[Tuple[Union[str, int], ...], Callable[[Any], Any]]]
137+
] = None,
138+
xyfuncs: Optional[
139+
Dict[str, Tuple[Tuple[Union[str, int], ...], Callable[[Any, Any], Any]]]
140+
] = None,
133141
):
134142
"""
135143
A container that wraps several functions. They are split into 3 categories:
@@ -274,7 +282,10 @@ def query(
274282
coord_transform: _MatplotlibTransform,
275283
size: Tuple[int, int],
276284
) -> Tuple[Dict[str, Any], Union[str, int]]:
277-
return {self._index_name: self._data.index.values, self._col_name: self._data.values}, self._hash_key
285+
return {
286+
self._index_name: self._data.index.values,
287+
self._col_name: self._data.values,
288+
}, self._hash_key
278289

279290
def describe(self) -> Dict[str, Desc]:
280291
return dict(self._desc)

Diff for: data_prototype/conversion_node.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def from_nodes(cls, *nodes: ConversionNode, trim_keys=False):
5050
return cls(required, tuple(output), trim_keys, nodes)
5151

5252
def evaluate(self, input: dict[str, Any]) -> dict[str, Any]:
53-
return super().evaluate({k: v for n in self.nodes for k, v in n.evaluate(input).items()})
53+
return super().evaluate(
54+
{k: v for n in self.nodes for k, v in n.evaluate(input).items()}
55+
)
5456

5557

5658
@dataclass
@@ -66,7 +68,9 @@ def from_mapping(cls, mapping: dict[str, str], trim_keys=False):
6668
return cls(required, tuple(output), trim_keys, mapping)
6769

6870
def evaluate(self, input: dict[str, Any]) -> dict[str, Any]:
69-
return super().evaluate({**input, **{out: input[inp] for (inp, out) in self.mapping.items()}})
71+
return super().evaluate(
72+
{**input, **{out: input[inp] for (inp, out) in self.mapping.items()}}
73+
)
7074

7175

7276
@dataclass
@@ -91,7 +95,10 @@ def evaluate(self, input: dict[str, Any]) -> dict[str, Any]:
9195
return super().evaluate(
9296
{
9397
**input,
94-
**{k: func(**{p: input[p] for p in sig.parameters}) for (k, (func, sig)) in self._sigs.items()},
98+
**{
99+
k: func(**{p: input[p] for p in sig.parameters})
100+
for (k, (func, sig)) in self._sigs.items()
101+
},
95102
}
96103
)
97104

Diff for: data_prototype/patches.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def __init__(self, data: DataContainer, converters=None, /, **kwargs):
5050

5151
@_stale_wrapper
5252
def draw(self, renderer):
53-
self._update_wrapped(self._query_and_transform(renderer, xunits=self._xunits, yunits=self._yunits))
53+
self._update_wrapped(
54+
self._query_and_transform(
55+
renderer, xunits=self._xunits, yunits=self._yunits
56+
)
57+
)
5458
return self._wrapped_instance.draw(renderer)
5559

5660
def _update_wrapped(self, data):
@@ -75,7 +79,14 @@ class RectangleWrapper(PatchWrapper):
7579
)
7680
_xunits = ("x", "width")
7781
_yunits = ("y", "height")
78-
required_keys = PatchWrapper.required_keys | {"x", "y", "width", "height", "angle", "rotation_point"}
82+
required_keys = PatchWrapper.required_keys | {
83+
"x",
84+
"y",
85+
"width",
86+
"height",
87+
"angle",
88+
"rotation_point",
89+
}
7990

8091
def _update_wrapped(self, data):
8192
for k, v in data.items():

Diff for: data_prototype/tests/test_containers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
@pytest.fixture
1212
def ac():
13-
return containers.ArrayContainer(a=np.arange(5), b=np.arange(42, dtype=float).reshape(6, 7))
13+
return containers.ArrayContainer(
14+
a=np.arange(5), b=np.arange(42, dtype=float).reshape(6, 7)
15+
)
1416

1517

1618
def _verify_describe(container):

Diff for: data_prototype/wrappers.py

+55-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
from matplotlib.patches import StepPatch as _StepPatch
1313
from matplotlib.text import Text as _Text
1414
import matplotlib.transforms as mtransforms
15-
from matplotlib.collections import LineCollection as _LineCollection, PathCollection as _PathCollection
15+
from matplotlib.collections import (
16+
LineCollection as _LineCollection,
17+
PathCollection as _PathCollection,
18+
)
1619
from matplotlib.artist import Artist as _Artist
1720

1821
from data_prototype.containers import DataContainer, _MatplotlibTransform
@@ -60,7 +63,9 @@ def identity(**kwargs):
6063
(_,) = kwargs.values()
6164
return _
6265

63-
identity.__signature__ = inspect.Signature([inspect.Parameter(k, inspect.Parameter.POSITIONAL_OR_KEYWORD)])
66+
identity.__signature__ = inspect.Signature(
67+
[inspect.Parameter(k, inspect.Parameter.POSITIONAL_OR_KEYWORD)]
68+
)
6469
return identity
6570

6671

@@ -116,7 +121,9 @@ def draw(self, renderer):
116121
def _update_wrapped(self, data):
117122
raise NotImplementedError
118123

119-
def _query_and_transform(self, renderer, *, xunits: List[str], yunits: List[str]) -> Dict[str, Any]:
124+
def _query_and_transform(
125+
self, renderer, *, xunits: List[str], yunits: List[str]
126+
) -> Dict[str, Any]:
120127
"""
121128
Helper to centralize the data querying and python-side transforms
122129
@@ -152,7 +159,9 @@ def _query_and_transform(self, renderer, *, xunits: List[str], yunits: List[str]
152159
self._cache[cache_key] = transformed_data
153160
return transformed_data
154161

155-
def __init__(self, data, converters: ConversionNode | list[ConversionNode] | None, **kwargs):
162+
def __init__(
163+
self, data, converters: ConversionNode | list[ConversionNode] | None, **kwargs
164+
):
156165
super().__init__(**kwargs)
157166
self.data = data
158167
self._cache = LFUCache(64)
@@ -180,23 +189,43 @@ def __getattr__(self, key):
180189
return getattr(self._wrapped_instance, key)
181190

182191
def __setattr__(self, key, value):
183-
if key in ("_wrapped_instance", "data", "_cache", "_converters", "stale", "_sigs"):
192+
if key in (
193+
"_wrapped_instance",
194+
"data",
195+
"_cache",
196+
"_converters",
197+
"stale",
198+
"_sigs",
199+
):
184200
super().__setattr__(key, value)
185-
elif hasattr(self, "_wrapped_instance") and hasattr(self._wrapped_instance, key):
201+
elif hasattr(self, "_wrapped_instance") and hasattr(
202+
self._wrapped_instance, key
203+
):
186204
setattr(self._wrapped_instance, key, value)
187205
else:
188206
super().__setattr__(key, value)
189207

190208

191209
class LineWrapper(ProxyWrapper):
192210
_wrapped_class = _Line2D
193-
_privtized_methods = ("set_xdata", "set_ydata", "set_data", "get_xdata", "get_ydata", "get_data")
211+
_privtized_methods = (
212+
"set_xdata",
213+
"set_ydata",
214+
"set_data",
215+
"get_xdata",
216+
"get_ydata",
217+
"get_data",
218+
)
194219
required_keys = {"x", "y"}
195220

196221
def __init__(self, data: DataContainer, converters=None, /, **kwargs):
197222
super().__init__(data, converters)
198-
self._wrapped_instance = self._wrapped_class(np.array([]), np.array([]), **kwargs)
199-
self._converters.insert(-1, RenameConversionNode.from_mapping({"x": "xdata", "y": "ydata"}))
223+
self._wrapped_instance = self._wrapped_class(
224+
np.array([]), np.array([]), **kwargs
225+
)
226+
self._converters.insert(
227+
-1, RenameConversionNode.from_mapping({"x": "xdata", "y": "ydata"})
228+
)
200229
setters = [f[4:] for f in dir(self._wrapped_class) if f.startswith("set_")]
201230
self._converters[-1] = LimitKeysConversionNode.from_keys(setters)
202231

@@ -252,7 +281,9 @@ class ImageWrapper(ProxyWrapper):
252281
_wrapped_class = _AxesImage
253282
required_keys = {"xextent", "yextent", "image"}
254283

255-
def __init__(self, data: DataContainer, converters=None, /, cmap=None, norm=None, **kwargs):
284+
def __init__(
285+
self, data: DataContainer, converters=None, /, cmap=None, norm=None, **kwargs
286+
):
256287
converters = converters or []
257288
if cmap is not None or norm is not None:
258289
if converters is not None and "image" in converters:
@@ -261,7 +292,11 @@ def __init__(self, data: DataContainer, converters=None, /, cmap=None, norm=None
261292
cmap = mpl.colormaps["viridis"]
262293
if norm is None:
263294
raise ValueError("not sure how to do autoscaling yet")
264-
converters.append(FunctionConversionNode.from_funcs({"image": lambda image: cmap(norm(image))}))
295+
converters.append(
296+
FunctionConversionNode.from_funcs(
297+
{"image": lambda image: cmap(norm(image))}
298+
)
299+
)
265300
super().__init__(data, converters)
266301
kwargs.setdefault("origin", "lower")
267302
self._wrapped_instance = self._wrapped_class(None, **kwargs)
@@ -341,7 +376,9 @@ def __setattr__(self, key, value):
341376
super().__setattr__(key, value)
342377
if hasattr(self, "_wrapped_instances"):
343378
# We can end up with out wrapped instance as part of init
344-
children_have_attrs = [hasattr(c, key) for c in self._wrapped_instances.values()]
379+
children_have_attrs = [
380+
hasattr(c, key) for c in self._wrapped_instances.values()
381+
]
345382
if any(children_have_attrs):
346383
if not all(children_have_attrs):
347384
raise Exception("mixed attributes 😱")
@@ -356,7 +393,9 @@ def get_children(self):
356393

357394
class ErrorbarWrapper(MultiProxyWrapper):
358395
required_keys = {"x", "y"}
359-
expected_keys = {f"{axis}{dirc}" for axis in ["x", "y"] for dirc in ["upper", "lower"]}
396+
expected_keys = {
397+
f"{axis}{dirc}" for axis in ["x", "y"] for dirc in ["upper", "lower"]
398+
}
360399

361400
def __init__(self, data: DataContainer, converters=None, /, **kwargs):
362401
super().__init__(data, converters)
@@ -387,7 +426,9 @@ def __init__(self, data: DataContainer, converters=None, /, **kwargs):
387426
def draw(self, renderer):
388427
self._update_wrapped(
389428
self._query_and_transform(
390-
renderer, xunits=["x", "xupper", "xlower"], yunits=["y", "yupper", "ylower"]
429+
renderer,
430+
xunits=["x", "xupper", "xlower"],
431+
yunits=["y", "yupper", "ylower"],
391432
),
392433
)
393434
for k, v in self._wrapped_instances.items():

Diff for: docs/source/conf.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
166166
#
167167
html_logo = "_static/logo2.svg"
168168
html_theme_options = {
169-
"logo": {"link": "index", "image_light": "images/logo2.svg", "image_dark": "images/logo_dark.svg"},
169+
"logo": {
170+
"link": "index",
171+
"image_light": "images/logo2.svg",
172+
"image_dark": "images/logo_dark.svg",
173+
},
170174
}
171175

172176
# Add any paths that contain custom static files (such as style sheets) here,
@@ -214,15 +218,23 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, **kwargs):
214218
# (source start file, target name, title,
215219
# author, documentclass [howto, manual, or own class]).
216220
latex_documents = [
217-
(master_doc, "data_prototype.tex", "data_prototype Documentation", "Contributors", "manual"),
221+
(
222+
master_doc,
223+
"data_prototype.tex",
224+
"data_prototype Documentation",
225+
"Contributors",
226+
"manual",
227+
),
218228
]
219229

220230

221231
# -- Options for manual page output ---------------------------------------
222232

223233
# One entry per manual page. List of tuples
224234
# (source start file, name, description, authors, manual section).
225-
man_pages = [(master_doc, "data_prototype", "data_prototype Documentation", [author], 1)]
235+
man_pages = [
236+
(master_doc, "data_prototype", "data_prototype Documentation", [author], 1)
237+
]
226238

227239

228240
# -- Options for Texinfo output -------------------------------------------

Diff for: examples/2Dfunc.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
xyfuncs={
2222
"xextent": ((2,), lambda x, y: [x[0], x[-1]]),
2323
"yextent": ((2,), lambda x, y: [y[0], y[-1]]),
24-
"image": (("N", "M"), lambda x, y: np.sin(x).reshape(1, -1) * np.cos(y).reshape(-1, 1)),
24+
"image": (
25+
("N", "M"),
26+
lambda x, y: np.sin(x).reshape(1, -1) * np.cos(y).reshape(-1, 1),
27+
),
2528
},
2629
)
2730
norm = Normalize(vmin=-1, vmax=1)

Diff for: examples/data_frame.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
th = np.linspace(0, 4 * np.pi, 256)
1818

19-
dc1 = DataFrameContainer(pd.DataFrame({"x": th, "y": np.cos(th)}), index_name=None, col_names=lambda n: n)
19+
dc1 = DataFrameContainer(
20+
pd.DataFrame({"x": th, "y": np.cos(th)}), index_name=None, col_names=lambda n: n
21+
)
2022

2123
df = pd.DataFrame(
2224
{

Diff for: examples/errorbar.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
xupper = x + 0.5
2222
xlower = x - 0.5
2323

24-
ac = ArrayContainer(x=x, y=y, yupper=yupper, ylower=ylower, xlower=xlower, xupper=xupper)
24+
ac = ArrayContainer(
25+
x=x, y=y, yupper=yupper, ylower=ylower, xlower=xlower, xupper=xupper
26+
)
2527

2628

2729
fig, ax = plt.subplots()

Diff for: examples/hist.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from data_prototype.wrappers import StepWrapper
1414
from data_prototype.containers import HistContainer
1515

16-
hc = HistContainer(np.concatenate([np.random.randn(5000), 0.1 * np.random.randn(500) + 5]), 25)
16+
hc = HistContainer(
17+
np.concatenate([np.random.randn(5000), 0.1 * np.random.randn(500) + 5]), 25
18+
)
1719

1820

1921
fig, (ax1, ax2) = plt.subplots(1, 2, layout="constrained")

Diff for: examples/lissajous.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ def query(
4646
) -> Tuple[Dict[str, Any], Union[str, int]]:
4747
def next_time():
4848
cur_time = time.time()
49-
cur_time = np.array([cur_time, cur_time - 0.1, cur_time - 0.2, cur_time - 0.3])
49+
cur_time = np.array(
50+
[cur_time, cur_time - 0.1, cur_time - 0.2, cur_time - 0.3]
51+
)
5052

5153
phase = 15 * np.pi * (self.scale * cur_time % 60) / 150
5254
marker_obj = mmarkers.MarkerStyle("o")
5355
return {
5456
"x": np.cos(5 * phase),
5557
"y": np.sin(3 * phase),
5658
"sizes": np.array([256]),
57-
"paths": [marker_obj.get_path().transformed(marker_obj.get_transform())],
59+
"paths": [
60+
marker_obj.get_path().transformed(marker_obj.get_transform())
61+
],
5862
"edgecolors": "k",
5963
"facecolors": ["#4682b4ff", "#82b446aa", "#46b48288", "#8246b433"],
6064
"time": cur_time[0],

0 commit comments

Comments
 (0)