Skip to content

Revamp streaming #253

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 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@

from __future__ import absolute_import

from plotly import plotly, graph_objs, grid_objs, tools, utils, session, offline
from plotly import (plotly, graph_objs, grid_objs, tools, utils, session,
offline)
from plotly.version import __version__
43 changes: 25 additions & 18 deletions plotly/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@


"""
import sys
import six
import json

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json

## Base Plotly Error ##

# Base Plotly Error
class PlotlyError(Exception):
pass



class InputError(PlotlyError):
pass

Expand Down Expand Up @@ -63,8 +56,7 @@ def __str__(self):
return self.message


## Grid Errors ##

# Grid Errors #
COLUMN_NOT_YET_UPLOADED_MESSAGE = (
"Hm... it looks like your column '{column_name}' hasn't "
"been uploaded to Plotly yet. You need to upload your "
Expand All @@ -79,14 +71,14 @@ def __str__(self):
"can't have duplicate column names. Rename "
"the column \"{0}\" and try again."
)
## Would Cause Server Errors ##

# Would Cause Server Errors

class PlotlyEmptyDataError(PlotlyError):
pass


## Graph Objects Errors ##

# Graph Objects Errors
class PlotlyGraphObjectError(PlotlyError):
def __init__(self, message='', path=None, notes=None, plain_message=''):
self.message = message
Expand Down Expand Up @@ -202,8 +194,7 @@ def __init__(self, obj='', index='', **kwargs):
**kwargs)


## Local Config Errors ##

# Local Config Errors
class PlotlyLocalError(PlotlyError):
pass

Expand All @@ -224,8 +215,7 @@ def __init__(self):
super(PlotlyLocalCredentialsError, self).__init__(message)


## Server Errors ##

# Server Errors
class PlotlyServerError(PlotlyError):
pass

Expand All @@ -244,3 +234,20 @@ class PlotlyAccountError(PlotlyServerError):

class PlotlyRateLimitError(PlotlyServerError):
pass


class ClosedConnection(PlotlyConnectionError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, way better.

"""Raised when the Plotly streaming server has disconnected."""
def __init__(self, message, status_code=None):
self.message = "[Code: {}] {}".format(status_code, message)
self.status_code = status_code or None
super(ClosedConnection, self).__init__(self.message)


class TooManyConnectFailures(PlotlyConnectionError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

"""Raised when too many unsuccessful (re)connects were attempted"""
message = "Connecting or reconnecting to stream failed too many times."

def __init__(self, message=None):
message = message or self.message
super(TooManyConnectFailures, self).__init__(message)
16 changes: 6 additions & 10 deletions plotly/graph_objs/graph_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@
"""
from __future__ import absolute_import

import copy
import sys
import warnings
from collections import OrderedDict

import six

from plotly import exceptions, utils
from plotly.graph_objs import graph_objs_tools
from plotly.graph_objs.graph_objs_tools import (
INFO, OBJ_MAP, NAME_TO_KEY, KEY_TO_NAME
)

from plotly import exceptions
from plotly import utils

import copy
import sys
if sys.version[:3] == '2.6':
from ordereddict import OrderedDict
else:
from collections import OrderedDict

__all__ = None


Expand Down
25 changes: 7 additions & 18 deletions plotly/graph_objs/graph_objs_tools.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
from __future__ import absolute_import
from plotly import utils
import textwrap

import json
import os
import sys
if sys.version[:3] == '2.6':
try:
from ordereddict import OrderedDict
import simplejson as json
except ImportError:
raise ImportError(
"Looks like you're running Python 2.6. Plotly expects newer "
"standard library versions of ordereddict and json. You can "
"simply upgrade with these 'extras' with the following terminal "
"command:\npip install 'plotly[PY2.6]'"
)
else:
from collections import OrderedDict
import json
import textwrap
from collections import OrderedDict
from pkg_resources import resource_string

import six

from pkg_resources import resource_string
from plotly import utils


# Define graph reference loader
Expand Down
4 changes: 2 additions & 2 deletions plotly/grid_objs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
=========

"""
from __future__ import absolute_import


from . grid_objs import Grid, Column
from plotly.grid_objs.grid_objs import Grid, Column
9 changes: 2 additions & 7 deletions plotly/grid_objs/grid_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
"""
from __future__ import absolute_import

import sys
import json
from collections import MutableSequence
from plotly import exceptions
from plotly import utils

if sys.version[:3] == '2.6':
import simplejson as json
else:
import json
from plotly import exceptions, utils

__all__ = None

Expand Down
6 changes: 4 additions & 2 deletions plotly/matplotlylib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
'tools' module or 'plotly' package.

"""
from . renderer import PlotlyRenderer
from . mplexporter import Exporter
from __future__ import absolute_import

from plotly.matplotlylib.renderer import PlotlyRenderer
from plotly.matplotlylib.mplexporter import Exporter
2 changes: 1 addition & 1 deletion plotly/matplotlylib/mpltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
A module for converting from mpl language to plotly language.

"""

import math
import warnings

import matplotlib.dates
import pytz

Expand Down
4 changes: 2 additions & 2 deletions plotly/matplotlylib/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import warnings

from . mplexporter import Renderer
from . import mpltools
import plotly.graph_objs as go
from plotly.matplotlylib.mplexporter import Renderer
from plotly.matplotlylib import mpltools


# Warning format
Expand Down
7 changes: 3 additions & 4 deletions plotly/offline/offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
"""
from __future__ import absolute_import

import uuid
import json
import os
import uuid

import requests

from plotly import utils
from plotly import tools
from plotly import session, tools, utils
from plotly.exceptions import PlotlyError
from plotly import session

PLOTLY_OFFLINE_DIRECTORY = plotlyjs_path = os.path.expanduser(
os.path.join(*'~/.plotly/plotlyjs'.split('/')))
Expand Down
1 change: 1 addition & 0 deletions plotly/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
plot_mpl,
get_figure,
Stream,
StreamWriter,
image,
grid_ops,
meta_ops,
Expand Down
Loading