Skip to content

Commit bd0d368

Browse files
validate trendline_options
1 parent 03c146c commit bd0d368

File tree

1 file changed

+16
-0
lines changed
  • packages/python/plotly/plotly/express/trendline_functions

1 file changed

+16
-0
lines changed

packages/python/plotly/plotly/express/trendline_functions/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def ols(trendline_options, x_raw, x, y, x_label, y_label, non_missing):
3030
respect to the base 10 logarithm of the input. Note that this means no zeros can
3131
be present in the input.
3232
"""
33+
valid_options = ["add_constant", "log_x", "log_y"]
34+
for k in trendline_options.keys():
35+
if k not in valid_options:
36+
raise ValueError(
37+
"OLS trendline_options keys must be one of [%s] but got '%s'"
38+
% (", ".join(valid_options), k)
39+
)
3340

3441
import statsmodels.api as sm
3542

@@ -83,6 +90,15 @@ def lowess(trendline_options, x_raw, x, y, x_label, y_label, non_missing):
8390
- `frac` (`float`, default `0.6666666`): the `frac` parameter from the
8491
`statsmodels.api.nonparametric.lowess` function
8592
"""
93+
94+
valid_options = ["frac"]
95+
for k in trendline_options.keys():
96+
if k not in valid_options:
97+
raise ValueError(
98+
"LOWESS trendline_options keys must be one of [%s] but got '%s'"
99+
% (", ".join(valid_options), k)
100+
)
101+
86102
import statsmodels.api as sm
87103

88104
frac = trendline_options.get("frac", 0.6666666)

0 commit comments

Comments
 (0)