Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix to_scalar_or_list when v.ndim == 0 #1444

Merged
merged 2 commits into from
Mar 6, 2019
Merged

Conversation

ankokumoyashi
Copy link
Contributor

  • test code
import plotly.graph_objs as go
import numpy as np
go.Scatter(
    y=[np.array(1), np.array(2)],
    x=[1, 1]
)
  • before fix
sh-4.2# python test.py
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    x=[1, 1]
  File "/root/review/plotly.py/plotly/graph_objs/_scatter.py", line 2567, in __init__
    self['y'] = y if y is not None else _v
  File "/root/review/plotly.py/plotly/basedatatypes.py", line 2841, in __setitem__
    self._set_prop(prop, value)
  File "/root/review/plotly.py/plotly/basedatatypes.py", line 3077, in _set_prop
    val = validator.validate_coerce(val)
  File "/root/review/plotly.py/_plotly_utils/basevalidators.py", line 382, in validate_coerce
    v = to_scalar_or_list(v)
  File "/root/review/plotly.py/_plotly_utils/basevalidators.py", line 56, in to_scalar_or_list
    return [to_scalar_or_list(e) for e in v]
  File "/root/review/plotly.py/_plotly_utils/basevalidators.py", line 56, in <listcomp>
    return [to_scalar_or_list(e) for e in v]
  File "/root/review/plotly.py/_plotly_utils/basevalidators.py", line 58, in to_scalar_or_list
    return [to_scalar_or_list(e) for e in v]
TypeError: iteration over a 0-d array
  • after fix
sh-4.2# python test.py
sh-4.2#

@jonmmease
Copy link
Contributor

Thanks for the fix @ankokumoyashi! We should add a small test for this to protect against future regressions. I think an additional test in _plotly_utils/tests/validators/test_dataarray_validator.py would be a good place for it. Basically to test that [np.array(1), np.array(2)] is coerced into [1, 2].

I can add it in a few days if you don't have time, thanks again for the contribution!

@jonmmease jonmmease added this to the v3.7.0 milestone Mar 4, 2019
@ankokumoyashi
Copy link
Contributor Author

I added test. Thank you for your kind instruction!

@jonmmease
Copy link
Contributor

Great! Thanks for the contribution @ankokumoyashi!

@jonmmease jonmmease merged commit 2718db3 into plotly:master Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants