Skip to content

Commit 488f117

Browse files
Merge pull request #4013 from plotly/angle_arrayOk
angle can now be arrayOK
2 parents 1e9e4bd + 6660820 commit 488f117

File tree

74 files changed

+209
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+209
-153
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1515
### Fixed
1616
- Fixed the usage of some deprecated NumPy types which were removed in NumPy 1.24 [[#3997](https://github.com/plotly/plotly.py/pull/3997)]
1717
- Fixed bug for trendlines with datetime axes [[#3683](https://github.com/plotly/plotly.py/issues/3683)]
18+
- `marker.angle` attribute now accepts iterables where appropriate [[#4013](https://github.com/plotly/plotly.py/issues/4013)]
1819

1920
## [5.11.0] - 2022-10-27
2021

packages/python/plotly/_plotly_utils/basevalidators.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -1660,24 +1660,29 @@ class AngleValidator(BaseValidator):
16601660
"description": "A number (in degree) between -180 and 180.",
16611661
"requiredOpts": [],
16621662
"otherOpts": [
1663-
"dflt"
1663+
"dflt",
1664+
"arrayOk"
16641665
]
16651666
},
16661667
"""
16671668

1668-
def __init__(self, plotly_name, parent_name, **kwargs):
1669+
def __init__(self, plotly_name, parent_name, array_ok=False, **kwargs):
16691670
super(AngleValidator, self).__init__(
16701671
plotly_name=plotly_name, parent_name=parent_name, **kwargs
16711672
)
1673+
self.array_ok = array_ok
16721674

16731675
def description(self):
16741676
desc = """\
16751677
The '{plotly_name}' property is a angle (in degrees) that may be
1676-
specified as a number between -180 and 180. Numeric values outside this
1677-
range are converted to the equivalent value
1678+
specified as a number between -180 and 180{array_ok}.
1679+
Numeric values outside this range are converted to the equivalent value
16781680
(e.g. 270 is converted to -90).
16791681
""".format(
1680-
plotly_name=self.plotly_name
1682+
plotly_name=self.plotly_name,
1683+
array_ok=", or a list, numpy array or other iterable thereof"
1684+
if self.array_ok
1685+
else "",
16811686
)
16821687

16831688
return desc
@@ -1686,6 +1691,22 @@ def validate_coerce(self, v):
16861691
if v is None:
16871692
# Pass None through
16881693
pass
1694+
elif self.array_ok and is_homogeneous_array(v):
1695+
try:
1696+
v_array = copy_to_readonly_numpy_array(v, force_numeric=True)
1697+
except (ValueError, TypeError, OverflowError):
1698+
self.raise_invalid_val(v)
1699+
v = v_array # Always numeric numpy array
1700+
# Normalize v onto the interval [-180, 180)
1701+
v = (v + 180) % 360 - 180
1702+
elif self.array_ok and is_simple_array(v):
1703+
# Check numeric
1704+
invalid_els = [e for e in v if not isinstance(e, numbers.Number)]
1705+
1706+
if invalid_els:
1707+
self.raise_invalid_elements(invalid_els[:10])
1708+
1709+
v = [(x + 180) % 360 - 180 for x in to_scalar_or_list(v)]
16891710
elif not isinstance(v, numbers.Number):
16901711
self.raise_invalid_val(v)
16911712
else:

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

+36-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88
# Fixtures
99
# --------
10-
@pytest.fixture()
11-
def validator():
10+
@pytest.fixture
11+
def validator(request):
1212
return AngleValidator("prop", "parent")
1313

1414

15+
@pytest.fixture
16+
def validator_aok(request):
17+
return AngleValidator("prop", "parent", array_ok=True)
18+
19+
1520
# Tests
1621
# -----
1722
# ### Test acceptance ###
@@ -36,3 +41,32 @@ def test_rejection(val, validator):
3641
validator.validate_coerce(val)
3742

3843
assert "Invalid value" in str(validation_failure.value)
44+
45+
46+
# ### Test acceptance ###
47+
@pytest.mark.parametrize("val", [[0, 179, -179]])
48+
def test_aok_acceptance(val, validator_aok):
49+
assert validator_aok.validate_coerce(val) == val
50+
assert validator_aok.validate_coerce(tuple(val)) == val
51+
assert np.array_equal(validator_aok.validate_coerce(np.array(val)), np.array(val))
52+
53+
54+
# ### Test coercion above 180 ###
55+
@pytest.mark.parametrize(
56+
"val,expected",
57+
[(180, -180), (181, -179), (-180.25, 179.75), (540, -180), (-541, 179)],
58+
)
59+
def test_aok_coercion(val, expected, validator_aok):
60+
assert validator_aok.validate_coerce([val]) == [expected]
61+
assert np.array_equal(
62+
validator_aok.validate_coerce(np.array([val])), np.array([expected])
63+
)
64+
65+
66+
# ### Test rejection ###
67+
@pytest.mark.parametrize("val", [["hello"], [()], [[]], [set()], ["34"]])
68+
def test_aok_rejection(val, validator_aok):
69+
with pytest.raises(ValueError) as validation_failure:
70+
validator_aok.validate_coerce(val)
71+
72+
assert "Invalid element(s)" in str(validation_failure.value)

packages/python/plotly/plotly/graph_objs/_bar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,8 @@ def textangle(self):
13741374
the maximum size in bars.
13751375
13761376
The 'textangle' property is a angle (in degrees) that may be
1377-
specified as a number between -180 and 180. Numeric values outside this
1378-
range are converted to the equivalent value
1377+
specified as a number between -180 and 180.
1378+
Numeric values outside this range are converted to the equivalent value
13791379
(e.g. 270 is converted to -90).
13801380
13811381
Returns

packages/python/plotly/plotly/graph_objs/_funnel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,8 @@ def textangle(self):
11501150
the maximum size in bars.
11511151
11521152
The 'textangle' property is a angle (in degrees) that may be
1153-
specified as a number between -180 and 180. Numeric values outside this
1154-
range are converted to the equivalent value
1153+
specified as a number between -180 and 180.
1154+
Numeric values outside this range are converted to the equivalent value
11551155
(e.g. 270 is converted to -90).
11561156
11571157
Returns

packages/python/plotly/plotly/graph_objs/_histogram.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,8 @@ def textangle(self):
14501450
the maximum size in bars.
14511451
14521452
The 'textangle' property is a angle (in degrees) that may be
1453-
specified as a number between -180 and 180. Numeric values outside this
1454-
range are converted to the equivalent value
1453+
specified as a number between -180 and 180.
1454+
Numeric values outside this range are converted to the equivalent value
14551455
(e.g. 270 is converted to -90).
14561456
14571457
Returns

packages/python/plotly/plotly/graph_objs/_parcoords.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ def labelangle(self):
302302
margins when `labelposition` is set to "bottom".
303303
304304
The 'labelangle' property is a angle (in degrees) that may be
305-
specified as a number between -180 and 180. Numeric values outside this
306-
range are converted to the equivalent value
305+
specified as a number between -180 and 180.
306+
Numeric values outside this range are converted to the equivalent value
307307
(e.g. 270 is converted to -90).
308308
309309
Returns

packages/python/plotly/plotly/graph_objs/_pie.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@ def rotation(self):
970970
some other angle.
971971
972972
The 'rotation' property is a angle (in degrees) that may be
973-
specified as a number between -180 and 180. Numeric values outside this
974-
range are converted to the equivalent value
973+
specified as a number between -180 and 180.
974+
Numeric values outside this range are converted to the equivalent value
975975
(e.g. 270 is converted to -90).
976976
977977
Returns

packages/python/plotly/plotly/graph_objs/_sunburst.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,8 @@ def rotation(self):
10651065
default the first slice starts at 3 o'clock.
10661066
10671067
The 'rotation' property is a angle (in degrees) that may be
1068-
specified as a number between -180 and 180. Numeric values outside this
1069-
range are converted to the equivalent value
1068+
specified as a number between -180 and 180.
1069+
Numeric values outside this range are converted to the equivalent value
10701070
(e.g. 270 is converted to -90).
10711071
10721072
Returns

packages/python/plotly/plotly/graph_objs/_waterfall.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,8 @@ def textangle(self):
11731173
the maximum size in bars.
11741174
11751175
The 'textangle' property is a angle (in degrees) that may be
1176-
specified as a number between -180 and 180. Numeric values outside this
1177-
range are converted to the equivalent value
1176+
specified as a number between -180 and 180.
1177+
Numeric values outside this range are converted to the equivalent value
11781178
(e.g. 270 is converted to -90).
11791179
11801180
Returns

packages/python/plotly/plotly/graph_objs/bar/marker/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/barpolar/marker/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/box/_marker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def angle(self):
2626
Sets the marker angle in respect to `angleref`.
2727
2828
The 'angle' property is a angle (in degrees) that may be
29-
specified as a number between -180 and 180. Numeric values outside this
30-
range are converted to the equivalent value
29+
specified as a number between -180 and 180.
30+
Numeric values outside this range are converted to the equivalent value
3131
(e.g. 270 is converted to -90).
3232
3333
Returns

packages/python/plotly/plotly/graph_objs/carpet/_aaxis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,8 @@ def tickangle(self):
12531253
labels vertically.
12541254
12551255
The 'tickangle' property is a angle (in degrees) that may be
1256-
specified as a number between -180 and 180. Numeric values outside this
1257-
range are converted to the equivalent value
1256+
specified as a number between -180 and 180.
1257+
Numeric values outside this range are converted to the equivalent value
12581258
(e.g. 270 is converted to -90).
12591259
12601260
Returns

packages/python/plotly/plotly/graph_objs/carpet/_baxis.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,8 @@ def tickangle(self):
12531253
labels vertically.
12541254
12551255
The 'tickangle' property is a angle (in degrees) that may be
1256-
specified as a number between -180 and 180. Numeric values outside this
1257-
range are converted to the equivalent value
1256+
specified as a number between -180 and 180.
1257+
Numeric values outside this range are converted to the equivalent value
12581258
(e.g. 270 is converted to -90).
12591259
12601260
Returns

packages/python/plotly/plotly/graph_objs/choropleth/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/choroplethmapbox/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/cone/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/contour/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/contourcarpet/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/densitymapbox/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/funnel/marker/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/heatmap/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/heatmapgl/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/histogram/marker/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/histogram2d/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/histogram2dcontour/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

packages/python/plotly/plotly/graph_objs/icicle/marker/_colorbar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def tickangle(self):
640640
labels vertically.
641641
642642
The 'tickangle' property is a angle (in degrees) that may be
643-
specified as a number between -180 and 180. Numeric values outside this
644-
range are converted to the equivalent value
643+
specified as a number between -180 and 180.
644+
Numeric values outside this range are converted to the equivalent value
645645
(e.g. 270 is converted to -90).
646646
647647
Returns

0 commit comments

Comments
 (0)