Skip to content

Deep magic underscore error messages #2824

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

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Custom implementation of cumsum
to avoid importing numpy
  • Loading branch information
nicholas-esterer committed Oct 14, 2020
commit 9e64840aaa15c3bc34d4e799d77e6766a3fb3724
15 changes: 14 additions & 1 deletion packages/python/plotly/_plotly_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
import re
from functools import reduce
from numpy import cumsum

from _plotly_utils.optional_imports import get_module
from _plotly_utils.basevalidators import ImageUriValidator
Expand All @@ -12,6 +11,20 @@
PY36_OR_LATER = sys.version_info >= (3, 6)


def cumsum(x):
"""
Custom cumsum to avoid a numpy import.
"""

def _reducer(a, x):
if len(a) == 0:
return [x]
return a + [a[-1] + x]

ret = reduce(_reducer, x, [])
return ret


class PlotlyJSONEncoder(_json.JSONEncoder):
"""
Meant to be passed as the `cls` kwarg to json.dumps(obj, cls=..)
Expand Down