Skip to content

Commit e962890

Browse files
Merge pull request #3749 from plotly/non-string-flaglist-extras
allow non-string extras in flaglist attributes
2 parents 59f0039 + f8ec53a commit e962890

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
56
## UNRELEASED
67

78
### Added
89

910
- `pattern_shape` options now available in `px.timeline()`
1011

12+
### Updated
13+
14+
- Allow non-string extras in `flaglist` attributes, to support upcoming changes to `ax.automargin` in plotly.js [plotly.js#6193](https://github.com/plotly/plotly.js/pull/6193), [#3749](https://github.com/plotly/plotly.py/pull/3749)
15+
1116
## [5.8.2] - 2022-06-10
1217

1318
### Fixed
@@ -18,7 +23,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1823

1924
(no changes, due to a mixup with the build process!)
2025

21-
2226
## [5.8.0] - 2022-05-09
2327

2428
### Fixed

packages/python/plotly/_plotly_utils/basevalidators.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1795,8 +1795,6 @@ def __init__(
17951795
self.extras = extras if extras is not None else []
17961796
self.array_ok = array_ok
17971797

1798-
self.all_flags = self.flags + self.extras
1799-
18001798
def description(self):
18011799

18021800
desc = (
@@ -1835,24 +1833,21 @@ def description(self):
18351833
return desc
18361834

18371835
def vc_scalar(self, v):
1836+
if isinstance(v, str):
1837+
v = v.strip()
1838+
1839+
if v in self.extras:
1840+
return v
1841+
18381842
if not isinstance(v, str):
18391843
return None
18401844

18411845
# To be generous we accept flags separated on plus ('+'),
1842-
# or comma (',')
1846+
# or comma (',') and we accept whitespace around the flags
18431847
split_vals = [e.strip() for e in re.split("[,+]", v)]
18441848

18451849
# Are all flags valid names?
1846-
all_flags_valid = all([f in self.all_flags for f in split_vals])
1847-
1848-
# Are any 'extras' flags present?
1849-
has_extras = any([f in self.extras for f in split_vals])
1850-
1851-
# For flaglist to be valid all flags must be valid, and if we have
1852-
# any extras present, there must be only one flag (the single extras
1853-
# flag)
1854-
is_valid = all_flags_valid and (not has_extras or len(split_vals) == 1)
1855-
if is_valid:
1850+
if all(f in self.flags for f in split_vals):
18561851
return "+".join(split_vals)
18571852
else:
18581853
return None

packages/python/plotly/_plotly_utils/tests/validators/test_flaglist_validator.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,45 @@
44
import numpy as np
55

66

7+
EXTRAS = ["none", "all", True, False, 3]
8+
FLAGS = ["lines", "markers", "text"]
9+
710
# Fixtures
811
# --------
9-
@pytest.fixture(params=[None, ["none", "all"]])
12+
@pytest.fixture(params=[None, EXTRAS])
1013
def validator(request):
1114
# Validator with or without extras
12-
return FlaglistValidator(
13-
"prop", "parent", flags=["lines", "markers", "text"], extras=request.param
14-
)
15+
return FlaglistValidator("prop", "parent", flags=FLAGS, extras=request.param)
1516

1617

1718
@pytest.fixture()
1819
def validator_extra():
19-
return FlaglistValidator(
20-
"prop", "parent", flags=["lines", "markers", "text"], extras=["none", "all"]
21-
)
20+
return FlaglistValidator("prop", "parent", flags=FLAGS, extras=EXTRAS)
2221

2322

2423
@pytest.fixture()
2524
def validator_extra_aok():
2625
return FlaglistValidator(
2726
"prop",
2827
"parent",
29-
flags=["lines", "markers", "text"],
30-
extras=["none", "all"],
28+
flags=FLAGS,
29+
extras=EXTRAS,
3130
array_ok=True,
3231
)
3332

3433

3534
@pytest.fixture(
3635
params=[
3736
"+".join(p)
38-
for i in range(1, 4)
39-
for p in itertools.permutations(["lines", "markers", "text"], i)
37+
for i in range(1, len(FLAGS) + 1)
38+
for p in itertools.permutations(FLAGS, i)
4039
]
4140
)
4241
def flaglist(request):
4342
return request.param
4443

4544

46-
@pytest.fixture(params=["none", "all"])
45+
@pytest.fixture(params=EXTRAS)
4746
def extra(request):
4847
return request.param
4948

@@ -69,7 +68,7 @@ def test_coercion(in_val, coerce_val, validator):
6968

7069

7170
# ### Rejection by type ###
72-
@pytest.mark.parametrize("val", [21, (), ["lines"], set(), {}])
71+
@pytest.mark.parametrize("val", [(), ["lines"], set(), {}])
7372
def test_rejection_type(val, validator):
7473
with pytest.raises(ValueError) as validation_failure:
7574
validator.validate_coerce(val)
@@ -79,7 +78,7 @@ def test_rejection_type(val, validator):
7978

8079
# ### Rejection by value ###
8180
@pytest.mark.parametrize(
82-
"val", ["", "line", "markers+line", "lin es", "lin es+markers"]
81+
"val", ["", "line", "markers+line", "lin es", "lin es+markers", 21]
8382
)
8483
def test_rejection_val(val, validator):
8584
with pytest.raises(ValueError) as validation_failure:
@@ -144,7 +143,7 @@ def test_acceptance_aok_scalarlist_flaglist(flaglist, validator_extra_aok):
144143
[
145144
["all", "markers", "text+markers"],
146145
["lines", "lines+markers", "markers+lines+text"],
147-
["all", "all", "lines+text", "none"],
146+
["all", "all", "lines+text"] + EXTRAS,
148147
],
149148
)
150149
def test_acceptance_aok_list_flaglist(val, validator_extra_aok):
@@ -158,8 +157,8 @@ def test_acceptance_aok_list_flaglist(val, validator_extra_aok):
158157
"in_val,expected",
159158
[
160159
(
161-
[" lines ", " lines + markers ", "lines ,markers"],
162-
["lines", "lines+markers", "lines+markers"],
160+
[" lines ", " lines + markers ", "lines ,markers", " all "],
161+
["lines", "lines+markers", "lines+markers", "all"],
163162
),
164163
(np.array(["text +lines"]), np.array(["text+lines"], dtype="unicode")),
165164
],

packages/python/plotly/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def get_latest_publish_build_info(repo, branch):
286286

287287
url = (
288288
r"https://circleci.com/api/v1.1/project/github/"
289-
r"{repo}/tree/{branch}?limit=10000\&filter=completed"
289+
r"{repo}/tree/{branch}?limit=100&filter=completed"
290290
).format(repo=repo, branch=branch)
291291

292292
branch_jobs = request_json(url)

0 commit comments

Comments
 (0)