Skip to content

Commit ed874a2

Browse files
committed
more work to satisfy ruff
1 parent c489a1f commit ed874a2

File tree

15 files changed

+42
-46
lines changed

15 files changed

+42
-46
lines changed

_plotly_utils/basevalidators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io
88
import re
99
import sys
10-
import warnings
1110
import narwhals.stable.v1 as nw
1211

1312
from _plotly_utils.optional_imports import get_module

_plotly_utils/colors/qualitative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def swatches(template=None):
151151
Plotly_r = Plotly[::-1]
152152
T10_r = T10[::-1]
153153

154-
from .colorbrewer import ( # noqa: F401
154+
from .colorbrewer import ( # noqa: E402 F401
155155
Set1,
156156
Pastel1,
157157
Dark2,
@@ -165,7 +165,7 @@ def swatches(template=None):
165165
Pastel2_r,
166166
Set3_r,
167167
)
168-
from .carto import ( # noqa: F401
168+
from .carto import ( # noqa: E402 F401
169169
Antique,
170170
Bold,
171171
Pastel,

_plotly_utils/colors/sequential.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def swatches_continuous(template=None):
124124
Turbo_r = Turbo[::-1]
125125
Viridis_r = Viridis[::-1]
126126

127-
from .plotlyjs import ( # noqa: F401
127+
from .plotlyjs import ( # noqa: E402 F401
128128
Blackbody,
129129
Bluered,
130130
Electric,
@@ -139,7 +139,7 @@ def swatches_continuous(template=None):
139139
Rainbow_r,
140140
)
141141

142-
from .colorbrewer import ( # noqa: F401
142+
from .colorbrewer import ( # noqa: E402 F401
143143
Blues,
144144
BuGn,
145145
BuPu,
@@ -180,7 +180,7 @@ def swatches_continuous(template=None):
180180
YlOrRd_r,
181181
)
182182

183-
from .cmocean import ( # noqa: F401
183+
from .cmocean import ( # noqa: E402 F401
184184
turbid,
185185
thermal,
186186
haline,
@@ -209,7 +209,7 @@ def swatches_continuous(template=None):
209209
tempo_r,
210210
)
211211

212-
from .carto import ( # noqa: F401
212+
from .carto import ( # noqa: E402 F401
213213
Burg,
214214
Burgyl,
215215
Redor,

_plotly_utils/png.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def write_array(self, outfile, pixels):
842842
"""
843843

844844
if self.interlace:
845-
if type(pixels) != array:
845+
if not isarray(pixels):
846846
# Coerce to array type
847847
fmt = "BH"[self.bitdepth > 8]
848848
pixels = array(fmt, pixels)

_plotly_utils/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,12 @@ def display_string_positions(p, i=None, offset=0, length=1, char="^", trim=True)
469469
maxaddr = 0
470470
if i is None:
471471
for p_ in p:
472-
for l in range(length):
473-
maxaddr = p_ + offset + l
472+
for temp in range(length):
473+
maxaddr = p_ + offset + temp
474474
s[maxaddr] = char
475475
else:
476-
for l in range(length):
477-
maxaddr = p[i] + offset + l
476+
for temp in range(length):
477+
maxaddr = p[i] + offset + temp
478478
s[maxaddr] = char
479479
ret = "".join(s)
480480
if trim:
@@ -501,8 +501,8 @@ def chomp_empty_strings(strings, c, reverse=False):
501501
on the right or "" if it is the last string.
502502
"""
503503

504-
def _rev(l):
505-
return [s[::-1] for s in l][::-1]
504+
def _rev(vals):
505+
return [s[::-1] for s in vals][::-1]
506506

507507
if reverse:
508508
return _rev(chomp_empty_strings(_rev(strings), c))

codegen/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ def __getattr__(import_name):
322322
graph_objects_path = opath.join(outdir, "graph_objects", "__init__.py")
323323
os.makedirs(opath.join(outdir, "graph_objects"), exist_ok=True)
324324
with open(graph_objects_path, "wt") as f:
325+
f.write("# ruff: noqa: F401\n")
325326
f.write(graph_objects_init_source)
326327

327-
# Run black code formatter on output directories
328+
# Run code formatter on output directories
328329
if noformat:
329330
print("skipping reformatting")
330331
else:

plotly/basedatatypes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ def _len_dict_item(item):
3636
convert to a string before calling len on it.
3737
"""
3838
try:
39-
l = len(item)
39+
temp = len(item)
4040
except TypeError:
4141
try:
42-
l = len("%d" % (item,))
42+
temp = len("%d" % (item,))
4343
except TypeError:
4444
raise ValueError(
4545
"Cannot find string length of an item that is not string-like nor an integer."
4646
)
47-
return l
47+
return temp
4848

4949

5050
def _str_to_dict_path_full(key_path_str):
@@ -105,7 +105,7 @@ def _split_and_chomp(s):
105105
# the list ("lift" the items out of the sublists)
106106
key_path2c = list(
107107
reduce(
108-
lambda x, y: x + y if type(y) == type(list()) else x + [y],
108+
lambda x, y: x + y if isinstance(y, list) else x + [y],
109109
map(_split_and_chomp, key_path2b),
110110
[],
111111
)
@@ -140,7 +140,7 @@ def _remake_path_from_tuple(props):
140140
return ""
141141

142142
def _add_square_brackets_to_number(n):
143-
if type(n) == type(int()):
143+
if isinstance(n, int):
144144
return "[%d]" % (n,)
145145
return n
146146

plotly/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from _plotly_utils.exceptions import *
1+
from _plotly_utils.exceptions import PlotlyError # noqa: F401

plotly/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from _plotly_utils.files import *
1+
from _plotly_utils.files import PLOTLY_DIR, ensure_writable_plotly_dir # noqa: F401

plotly/graph_objects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ruff: noqa: F401
12
import sys
23
from typing import TYPE_CHECKING
34

plotly/optional_imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from _plotly_utils.optional_imports import get_module
1+
from _plotly_utils.optional_imports import get_module # noqa: F401

plotly/tools.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,10 @@ def _replace_newline(obj):
500500
d[key] = _replace_newline(val)
501501
return d
502502
elif isinstance(obj, list):
503-
l = list()
503+
temp = list()
504504
for index, entry in enumerate(obj):
505-
l += [_replace_newline(entry)]
506-
return l
505+
temp += [_replace_newline(entry)]
506+
return temp
507507
elif isinstance(obj, str):
508508
s = obj.replace("\n", "<br>")
509509
if s != obj:
@@ -704,7 +704,7 @@ def get_config_plotly_server_url():
704704
config_dict = json.load(f)
705705
if not isinstance(config_dict, dict):
706706
config_dict = {}
707-
except:
707+
except Exception:
708708
# TODO: issue a warning and bubble it up
709709
config_dict = {}
710710

plotly/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import textwrap
22
from pprint import PrettyPrinter
33

4-
from _plotly_utils.utils import *
5-
from _plotly_utils.data_utils import *
4+
from _plotly_utils.utils import NotEncodable, PlotlyJSONEncoder, get_module # noqa: F401
5+
from _plotly_utils.data_utils import image_array_to_data_uri # noqa: F401
66

77

88
# Pretty printing

tests/test_plotly_utils/validators/test_colorscale_validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def test_acceptance_sequence(seqence_colorscale, validator):
7979
@pytest.mark.parametrize(
8080
"val",
8181
[
82-
((0, "red"),),
83-
((0.1, "rgb(255,0,0)"), (0.3, "green")),
84-
((0, "purple"), (0.2, "yellow"), (1.0, "rgba(255,0,0,100)")),
82+
[[0, "red"]],
83+
[[0.1, "rgb(255,0,0)"], [0.3, "green"]],
84+
[[0, "purple"], [0.2, "yellow"], [1.0, "rgba(255,0,0,100)"]],
8585
],
8686
)
8787
def test_acceptance_array_1(val, validator):

tests/test_plotly_utils/validators/test_enumerated_validator.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from _plotly_utils.basevalidators import EnumeratedValidator
55
from ...test_optional.test_utils.test_utils import np_inf
66

7-
87
# Fixtures
98

109
@pytest.fixture()
@@ -35,7 +34,7 @@ def validator_aok_re():
3534

3635
# Acceptance
3736
@pytest.mark.parametrize("val", ["first", "second", "third", 4])
38-
def test_acceptance_1(val, validator):
37+
def test_acceptance_no_array(val, validator):
3938
# Values should be accepted and returned unchanged
4039
assert validator.validate_coerce(val) == val
4140

@@ -45,7 +44,7 @@ def test_acceptance_1(val, validator):
4544
"val",
4645
[True, 0, 1, 23, np_inf(), set(), ["first", "second"], [True], ["third", 4], [4]],
4746
)
48-
def test_rejection_by_value_1(val, validator):
47+
def test_rejection_by_value_with_validator(val, validator):
4948
with pytest.raises(ValueError) as validation_failure:
5049
validator.validate_coerce(val)
5150

@@ -55,14 +54,14 @@ def test_rejection_by_value_1(val, validator):
5554
# Array not ok, regular expression
5655

5756
@pytest.mark.parametrize("val", ["foo", "bar0", "bar1", "bar234"])
58-
def test_acceptance_2(val, validator_re):
57+
def test_acceptance(val, validator_re):
5958
# Values should be accepted and returned unchanged
6059
assert validator_re.validate_coerce(val) == val
6160

6261

6362
# Value Rejection
6463
@pytest.mark.parametrize("val", [12, set(), "bar", "BAR0", "FOO"])
65-
def test_rejection_by_value_2(val, validator_re):
64+
def test_rejection_by_value_with_regexp(val, validator_re):
6665
with pytest.raises(ValueError) as validation_failure:
6766
validator_re.validate_coerce(val)
6867

@@ -86,13 +85,9 @@ def test_rejection_by_value_2(val, validator_re):
8685
["first", "second", "third", 4],
8786
],
8887
)
89-
def test_acceptance_aok_1(val, validator_aok):
88+
def test_acceptance_array_ok(val, validator_aok):
9089
# Values should be accepted and returned unchanged
91-
coerce_val = validator_aok.validate_coerce(val)
92-
if isinstance(val, (list, np.ndarray)):
93-
assert np.array_equal(coerce_val, np.array(val, dtype=coerce_val.dtype))
94-
else:
95-
assert coerce_val == val
90+
assert val == validator_aok.validate_coerce(val)
9691

9792

9893
# Rejection by value
@@ -108,7 +103,7 @@ def test_rejection_by_value_aok(val, validator_aok):
108103
@pytest.mark.parametrize(
109104
"val", [[True], [0], [1, 23], [np_inf(), set()], ["ffirstt", "second", "third"]]
110105
)
111-
def test_rejection_by_element_aok_1(val, validator_aok):
106+
def test_rejection_by_element_array_ok(val, validator_aok):
112107
with pytest.raises(ValueError) as validation_failure:
113108
validator_aok.validate_coerce(val)
114109

@@ -132,7 +127,7 @@ def test_rejection_by_element_aok_1(val, validator_aok):
132127
np.array(["foo", "bar012", "baz"]),
133128
],
134129
)
135-
def test_acceptance_aok_2(val, validator_aok_re):
130+
def test_acceptance_array_ok_re(val, validator_aok_re):
136131
# Values should be accepted and returned unchanged
137132
coerce_val = validator_aok_re.validate_coerce(val)
138133
if isinstance(val, (np.ndarray, pd.Series)):
@@ -145,7 +140,7 @@ def test_acceptance_aok_2(val, validator_aok_re):
145140

146141
# Reject by elements
147142
@pytest.mark.parametrize("val", [["bar", "bar0"], ["foo", 123]])
148-
def test_rejection_by_element_aok_2(val, validator_aok_re):
143+
def test_rejection_by_element_array_ok_re(val, validator_aok_re):
149144
with pytest.raises(ValueError) as validation_failure:
150145
validator_aok_re.validate_coerce(val)
151146

0 commit comments

Comments
 (0)