Skip to content

[v4 integration] Remove future flags #1594

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

Merged
merged 14 commits into from
Jun 3, 2019
Merged
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
45 changes: 31 additions & 14 deletions _plotly_future_/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import warnings
import functools

_future_flags = set()
# Initialize _future_flags with all future flags that are now always in
# effect.
_future_flags = {
'renderer_defaults',
'template_defaults',
'extract_chart_studio',
'remove_deprecations',
'v4_subplots',
'orca_defaults',
'timezones',
'trace_uids',
}


def _assert_plotly_not_imported():
Expand All @@ -19,13 +30,20 @@ def _assert_plotly_not_imported():


def _chart_studio_warning(submodule):
if 'extract_chart_studio' in _future_flags:
warnings.warn(
'The plotly.{submodule} module is deprecated, '
'please use chart_studio.{submodule} instead'
.format(submodule=submodule),
DeprecationWarning,
stacklevel=2)
warnings.warn(
'The plotly.{submodule} module is deprecated, '
'please use chart_studio.{submodule} instead'
.format(submodule=submodule),
DeprecationWarning,
stacklevel=2)


def _chart_studio_error(submodule):
raise ImportError("""
The plotly.{submodule} module is deprecated,
please install the chart_studio package and use the
chart_studio.{submodule} module instead.
""".format(submodule=submodule))


def _chart_studio_deprecation(fn):
Expand All @@ -43,15 +61,14 @@ def _chart_studio_deprecation(fn):

@functools.wraps(fn)
def wrapper(*args, **kwargs):
if 'extract_chart_studio' in _future_flags:
warnings.warn(
msg,
DeprecationWarning,
stacklevel=2)
warnings.warn(
msg,
DeprecationWarning,
stacklevel=2)

return fn(*args, **kwargs)

return wrapper


__all__ = ['_future_flags', '_chart_studio_warning']
__all__ = ['_future_flags', '_chart_studio_error']
5 changes: 0 additions & 5 deletions _plotly_future_/extract_chart_studio.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('extract_chart_studio')
5 changes: 0 additions & 5 deletions _plotly_future_/orca_defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('orca_defaults')
5 changes: 0 additions & 5 deletions _plotly_future_/remove_deprecations.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('remove_deprecations')
5 changes: 0 additions & 5 deletions _plotly_future_/renderer_defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('renderer_defaults')
5 changes: 0 additions & 5 deletions _plotly_future_/template_defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('template_defaults')
5 changes: 0 additions & 5 deletions _plotly_future_/timezones.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('timezones')
5 changes: 0 additions & 5 deletions _plotly_future_/trace_uids.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('trace_uids')
12 changes: 0 additions & 12 deletions _plotly_future_/v4.py
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import (
renderer_defaults,
template_defaults,
extract_chart_studio,
remove_deprecations,
v4_subplots,
orca_defaults,
timezones,
trace_uids,
)

5 changes: 0 additions & 5 deletions _plotly_future_/v4_subplots.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import absolute_import
from _plotly_future_ import _future_flags, _assert_plotly_not_imported

_assert_plotly_not_imported()
_future_flags.add('v4_subplots')
5 changes: 1 addition & 4 deletions _plotly_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import re
import pytz
from _plotly_future_ import _future_flags

from _plotly_utils.optional_imports import get_module

Expand Down Expand Up @@ -104,9 +103,7 @@ def default(self, obj):
self.encode_as_sage,
self.encode_as_numpy,
self.encode_as_pandas,
(self.encode_as_datetime_v4
if 'timezones' in _future_flags
else self.encode_as_datetime),
self.encode_as_datetime_v4,
self.encode_as_date,
self.encode_as_list, # because some values have `tolist` do last.
self.encode_as_decimal
Expand Down
35 changes: 19 additions & 16 deletions chart_studio/tests/test_optional/test_utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json as _json
from unittest import TestCase

import _plotly_utils.utils
from chart_studio.grid_objs import Column
Expand All @@ -7,19 +8,21 @@
mixed_list, np_list


def test_column_json_encoding():
columns = [
Column(numeric_list, 'col 1'),
Column(mixed_list, 'col 2'),
Column(np_list, 'col 3')
]
json_columns = _json.dumps(
columns, cls=_plotly_utils.utils.PlotlyJSONEncoder, sort_keys=True
)
assert('[{"data": [1, 2, 3], "name": "col 1"}, '
'{"data": [1, "A", "2014-01-05", '
'"2014-01-05 01:01:01", '
'"2014-01-05 01:01:01.000001"], '
'"name": "col 2"}, '
'{"data": [1, 2, 3, null, null, null, '
'"2014-01-05"], "name": "col 3"}]' == json_columns)
class TestJSONEncoder(TestCase):
def test_column_json_encoding(self):
columns = [
Column(numeric_list, 'col 1'),
Column(mixed_list, 'col 2'),
Column(np_list, 'col 3')
]
json_columns = _json.dumps(
columns, cls=_plotly_utils.utils.PlotlyJSONEncoder, sort_keys=True
)
print(json_columns)
assert('[{"data": [1, 2, 3], "name": "col 1"}, '
'{"data": [1, "A", "2014-01-05T00:00:00", '
'"2014-01-05T01:01:01", '
'"2014-01-05T01:01:01.000001"], '
'"name": "col 2"}, '
'{"data": [1, 2, 3, null, null, null, '
'"2014-01-05T00:00:00"], "name": "col 3"}]' == json_columns)
3 changes: 0 additions & 3 deletions codegen/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def build_figure_py(trace_node, base_package, base_classname, fig_classname,
# ### Import trace graph_obj classes ###
trace_types_csv = ', '.join([n.name_datatype_class for n in trace_nodes])
buffer.write(f'from plotly.graph_objs import ({trace_types_csv})\n')
buffer.write("from plotly.subplots import _validate_v4_subplots\n")

# Write class definition
# ----------------------
Expand Down Expand Up @@ -253,8 +252,6 @@ def select_{plural_name}(
Generator that iterates through all of the {singular_name}
objects that satisfy all of the specified selection criteria
\"\"\"
if row is not None or col is not None:
_validate_v4_subplots('select_{plural_name}')

return self._select_layout_subplots_by_prefix(
'{singular_name}', selector, row, col{secondary_y_2})
Expand Down
14 changes: 1 addition & 13 deletions plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"""

from __future__ import absolute_import
from _plotly_future_ import _future_flags

from plotly import (
graph_objs,
Expand All @@ -41,16 +40,5 @@

from plotly.version import __version__

if ('extract_chart_studio' not in _future_flags
and 'remove_deprecations' not in _future_flags):
from plotly import (
plotly,
dashboard_objs,
grid_objs,
session)


# Set default template here to make sure import process is complete
if 'template_defaults' in _future_flags:
# Set _default to skip validation
io.templates._default = 'plotly'
io.templates._default = 'plotly'
7 changes: 3 additions & 4 deletions plotly/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Deprecations
from _plotly_future_ import _future_flags
if 'remove_deprecations' not in _future_flags:
from chart_studio.api.utils import *
from __future__ import absolute_import
from _plotly_future_ import _chart_studio_error
_chart_studio_error('api.utils')
10 changes: 2 additions & 8 deletions plotly/api/v1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from __future__ import absolute_import

from _plotly_future_ import _future_flags


if 'remove_deprecations' not in _future_flags:
from _plotly_future_ import _chart_studio_warning
_chart_studio_warning('api.v1')
from chart_studio.api.v1 import *
from _plotly_future_ import _chart_studio_error
_chart_studio_error('api.v1')
10 changes: 2 additions & 8 deletions plotly/api/v2.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from __future__ import absolute_import

from _plotly_future_ import _future_flags


if 'remove_deprecations' not in _future_flags:
from _plotly_future_ import _chart_studio_warning
_chart_studio_warning('api.v2')
from chart_studio.api.v2 import *
from _plotly_future_ import _chart_studio_error
_chart_studio_error('api.v2')
45 changes: 4 additions & 41 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from plotly.subplots import (
_set_trace_grid_reference,
_get_grid_subplot,
_get_subplot_ref_for_trace,
_validate_v4_subplots)
_get_subplot_ref_for_trace)
from .optional_imports import get_module

from _plotly_utils.basevalidators import (
Expand All @@ -26,8 +25,6 @@
from plotly.utils import ElidedPrettyPrinter
from .validators import (DataValidator, LayoutValidator, FramesValidator)

from _plotly_future_ import _future_flags

# Create Undefined sentinel value
# - Setting a property to None removes any existing value
# - Setting a property to Undefined leaves existing value unmodified
Expand All @@ -51,7 +48,7 @@ class BaseFigure(object):
'plot_bgcolor': 'plot-bgcolor'
}

_set_trace_uid = 'trace_uids' not in _future_flags
_set_trace_uid = False

# Constructor
# -----------
Expand Down Expand Up @@ -683,7 +680,6 @@ def select_traces(
selector = {}

if row is not None or col is not None or secondary_y is not None:
_validate_v4_subplots('select_traces')
grid_ref = self._validate_get_grid_ref()
filter_by_subplot = True

Expand Down Expand Up @@ -1610,41 +1606,8 @@ def append_trace(self, trace, row, col):
def _set_trace_grid_position(
self, trace, row, col, secondary_y=False):
grid_ref = self._validate_get_grid_ref()

from _plotly_future_ import _future_flags
if 'v4_subplots' in _future_flags:
return _set_trace_grid_reference(
trace, self.layout, grid_ref, row, col, secondary_y)

if row <= 0:
raise Exception("Row value is out of range. "
"Note: the starting cell is (1, 1)")
if col <= 0:
raise Exception("Col value is out of range. "
"Note: the starting cell is (1, 1)")
try:
ref = grid_ref[row - 1][col - 1]
except IndexError:
raise Exception("The (row, col) pair sent is out of "
"range. Use Figure.print_grid to view the "
"subplot grid. ")
if 'scene' in ref[0]:
trace['scene'] = ref[0]
if ref[0] not in self['layout']:
raise Exception("Something went wrong. "
"The scene object for ({r},{c}) "
"subplot cell "
"got deleted.".format(r=row, c=col))
else:
xaxis_key = "xaxis{ref}".format(ref=ref[0][1:])
yaxis_key = "yaxis{ref}".format(ref=ref[1][1:])
if (xaxis_key not in self['layout']
or yaxis_key not in self['layout']):
raise Exception("Something went wrong. "
"An axis object for ({r},{c}) subplot "
"cell got deleted.".format(r=row, c=col))
trace['xaxis'] = ref[0]
trace['yaxis'] = ref[1]
return _set_trace_grid_reference(
trace, self.layout, grid_ref, row, col, secondary_y)

def _validate_get_grid_ref(self):
try:
Expand Down
6 changes: 2 additions & 4 deletions plotly/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from _plotly_future_ import _chart_studio_warning
_chart_studio_warning('config')
from chart_studio.config import *
from _plotly_future_ import _chart_studio_error
_chart_studio_error('config')
10 changes: 2 additions & 8 deletions plotly/dashboard_objs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from __future__ import absolute_import

from _plotly_future_ import _future_flags


if 'remove_deprecations' not in _future_flags:
from _plotly_future_ import _chart_studio_warning
_chart_studio_warning('dashboard_objs')
from chart_studio.dashboard_objs import *
from _plotly_future_ import _chart_studio_error
_chart_studio_error('dashboard_objs')
6 changes: 1 addition & 5 deletions plotly/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
from __future__ import absolute_import
from _plotly_utils.exceptions import *

# Deprecations
from _plotly_future_ import _future_flags
if 'remove_deprecations' not in _future_flags:
from chart_studio.exceptions import *
2 changes: 1 addition & 1 deletion plotly/figure_factory/_facet_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from plotly import exceptions, optional_imports
import plotly.colors as clrs
from plotly.figure_factory import utils
from plotly.tools import make_subplots
from plotly.subplots import make_subplots

import math
from numbers import Number
Expand Down
6 changes: 1 addition & 5 deletions plotly/files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
from __future__ import absolute_import
from _plotly_utils.files import *

# Deprecations
from _plotly_future_ import _future_flags
if 'remove_deprecations' not in _future_flags:
from chart_studio.files import *
Loading