Skip to content

Commit 2a44ce3

Browse files
authored
[v4 integration] Remove future flags (plotly#1594)
* Init all future flags as enabled * Remove future flag disabled logic * Update v4 template colors * Remove deprecated imports, replace with error pointing to chart_studio package * Remove future flag specifications from tests * Fix test_core tests for v4 functionality * Update test_optional tests for v4 behavior * Remove test_plotly tests from the plotly project these still live in the chart_studio project * Disable template for test_offline tests * Update expected JSON encoding of Column dates * Only enable 'browser' default renderer if default browser can be found * Fix orca image renderers test * Fix JSON encoding tests * Disable template in orca image tests
1 parent 7cce283 commit 2a44ce3

File tree

111 files changed

+487
-7689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+487
-7689
lines changed

Diff for: _plotly_future_/__init__.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import warnings
22
import functools
33

4-
_future_flags = set()
4+
# Initialize _future_flags with all future flags that are now always in
5+
# effect.
6+
_future_flags = {
7+
'renderer_defaults',
8+
'template_defaults',
9+
'extract_chart_studio',
10+
'remove_deprecations',
11+
'v4_subplots',
12+
'orca_defaults',
13+
'timezones',
14+
'trace_uids',
15+
}
516

617

718
def _assert_plotly_not_imported():
@@ -19,13 +30,20 @@ def _assert_plotly_not_imported():
1930

2031

2132
def _chart_studio_warning(submodule):
22-
if 'extract_chart_studio' in _future_flags:
23-
warnings.warn(
24-
'The plotly.{submodule} module is deprecated, '
25-
'please use chart_studio.{submodule} instead'
26-
.format(submodule=submodule),
27-
DeprecationWarning,
28-
stacklevel=2)
33+
warnings.warn(
34+
'The plotly.{submodule} module is deprecated, '
35+
'please use chart_studio.{submodule} instead'
36+
.format(submodule=submodule),
37+
DeprecationWarning,
38+
stacklevel=2)
39+
40+
41+
def _chart_studio_error(submodule):
42+
raise ImportError("""
43+
The plotly.{submodule} module is deprecated,
44+
please install the chart_studio package and use the
45+
chart_studio.{submodule} module instead.
46+
""".format(submodule=submodule))
2947

3048

3149
def _chart_studio_deprecation(fn):
@@ -43,15 +61,14 @@ def _chart_studio_deprecation(fn):
4361

4462
@functools.wraps(fn)
4563
def wrapper(*args, **kwargs):
46-
if 'extract_chart_studio' in _future_flags:
47-
warnings.warn(
48-
msg,
49-
DeprecationWarning,
50-
stacklevel=2)
64+
warnings.warn(
65+
msg,
66+
DeprecationWarning,
67+
stacklevel=2)
5168

5269
return fn(*args, **kwargs)
5370

5471
return wrapper
5572

5673

57-
__all__ = ['_future_flags', '_chart_studio_warning']
74+
__all__ = ['_future_flags', '_chart_studio_error']

Diff for: _plotly_future_/extract_chart_studio.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('extract_chart_studio')

Diff for: _plotly_future_/orca_defaults.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('orca_defaults')

Diff for: _plotly_future_/remove_deprecations.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('remove_deprecations')

Diff for: _plotly_future_/renderer_defaults.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('renderer_defaults')

Diff for: _plotly_future_/template_defaults.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('template_defaults')

Diff for: _plotly_future_/timezones.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('timezones')

Diff for: _plotly_future_/trace_uids.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('trace_uids')

Diff for: _plotly_future_/v4.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import (
3-
renderer_defaults,
4-
template_defaults,
5-
extract_chart_studio,
6-
remove_deprecations,
7-
v4_subplots,
8-
orca_defaults,
9-
timezones,
10-
trace_uids,
11-
)
12-

Diff for: _plotly_future_/v4_subplots.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
from __future__ import absolute_import
2-
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3-
4-
_assert_plotly_not_imported()
5-
_future_flags.add('v4_subplots')

Diff for: _plotly_utils/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import sys
55
import re
66
import pytz
7-
from _plotly_future_ import _future_flags
87

98
from _plotly_utils.optional_imports import get_module
109

@@ -104,9 +103,7 @@ def default(self, obj):
104103
self.encode_as_sage,
105104
self.encode_as_numpy,
106105
self.encode_as_pandas,
107-
(self.encode_as_datetime_v4
108-
if 'timezones' in _future_flags
109-
else self.encode_as_datetime),
106+
self.encode_as_datetime_v4,
110107
self.encode_as_date,
111108
self.encode_as_list, # because some values have `tolist` do last.
112109
self.encode_as_decimal
+19-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json as _json
2+
from unittest import TestCase
23

34
import _plotly_utils.utils
45
from chart_studio.grid_objs import Column
@@ -7,19 +8,21 @@
78
mixed_list, np_list
89

910

10-
def test_column_json_encoding():
11-
columns = [
12-
Column(numeric_list, 'col 1'),
13-
Column(mixed_list, 'col 2'),
14-
Column(np_list, 'col 3')
15-
]
16-
json_columns = _json.dumps(
17-
columns, cls=_plotly_utils.utils.PlotlyJSONEncoder, sort_keys=True
18-
)
19-
assert('[{"data": [1, 2, 3], "name": "col 1"}, '
20-
'{"data": [1, "A", "2014-01-05", '
21-
'"2014-01-05 01:01:01", '
22-
'"2014-01-05 01:01:01.000001"], '
23-
'"name": "col 2"}, '
24-
'{"data": [1, 2, 3, null, null, null, '
25-
'"2014-01-05"], "name": "col 3"}]' == json_columns)
11+
class TestJSONEncoder(TestCase):
12+
def test_column_json_encoding(self):
13+
columns = [
14+
Column(numeric_list, 'col 1'),
15+
Column(mixed_list, 'col 2'),
16+
Column(np_list, 'col 3')
17+
]
18+
json_columns = _json.dumps(
19+
columns, cls=_plotly_utils.utils.PlotlyJSONEncoder, sort_keys=True
20+
)
21+
print(json_columns)
22+
assert('[{"data": [1, 2, 3], "name": "col 1"}, '
23+
'{"data": [1, "A", "2014-01-05T00:00:00", '
24+
'"2014-01-05T01:01:01", '
25+
'"2014-01-05T01:01:01.000001"], '
26+
'"name": "col 2"}, '
27+
'{"data": [1, 2, 3, null, null, null, '
28+
'"2014-01-05T00:00:00"], "name": "col 3"}]' == json_columns)

Diff for: codegen/figure.py

-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def build_figure_py(trace_node, base_package, base_classname, fig_classname,
5757
# ### Import trace graph_obj classes ###
5858
trace_types_csv = ', '.join([n.name_datatype_class for n in trace_nodes])
5959
buffer.write(f'from plotly.graph_objs import ({trace_types_csv})\n')
60-
buffer.write("from plotly.subplots import _validate_v4_subplots\n")
6160

6261
# Write class definition
6362
# ----------------------
@@ -253,8 +252,6 @@ def select_{plural_name}(
253252
Generator that iterates through all of the {singular_name}
254253
objects that satisfy all of the specified selection criteria
255254
\"\"\"
256-
if row is not None or col is not None:
257-
_validate_v4_subplots('select_{plural_name}')
258255
259256
return self._select_layout_subplots_by_prefix(
260257
'{singular_name}', selector, row, col{secondary_y_2})

Diff for: plotly/__init__.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"""
2828

2929
from __future__ import absolute_import
30-
from _plotly_future_ import _future_flags
3130

3231
from plotly import (
3332
graph_objs,
@@ -41,16 +40,5 @@
4140

4241
from plotly.version import __version__
4342

44-
if ('extract_chart_studio' not in _future_flags
45-
and 'remove_deprecations' not in _future_flags):
46-
from plotly import (
47-
plotly,
48-
dashboard_objs,
49-
grid_objs,
50-
session)
51-
52-
5343
# Set default template here to make sure import process is complete
54-
if 'template_defaults' in _future_flags:
55-
# Set _default to skip validation
56-
io.templates._default = 'plotly'
44+
io.templates._default = 'plotly'

Diff for: plotly/api/utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Deprecations
2-
from _plotly_future_ import _future_flags
3-
if 'remove_deprecations' not in _future_flags:
4-
from chart_studio.api.utils import *
1+
from __future__ import absolute_import
2+
from _plotly_future_ import _chart_studio_error
3+
_chart_studio_error('api.utils')

Diff for: plotly/api/v1.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
from __future__ import absolute_import
2-
3-
from _plotly_future_ import _future_flags
4-
5-
6-
if 'remove_deprecations' not in _future_flags:
7-
from _plotly_future_ import _chart_studio_warning
8-
_chart_studio_warning('api.v1')
9-
from chart_studio.api.v1 import *
2+
from _plotly_future_ import _chart_studio_error
3+
_chart_studio_error('api.v1')

Diff for: plotly/api/v2.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
from __future__ import absolute_import
2-
3-
from _plotly_future_ import _future_flags
4-
5-
6-
if 'remove_deprecations' not in _future_flags:
7-
from _plotly_future_ import _chart_studio_warning
8-
_chart_studio_warning('api.v2')
9-
from chart_studio.api.v2 import *
2+
from _plotly_future_ import _chart_studio_error
3+
_chart_studio_error('api.v2')

Diff for: plotly/basedatatypes.py

+4-41
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
from plotly.subplots import (
1414
_set_trace_grid_reference,
1515
_get_grid_subplot,
16-
_get_subplot_ref_for_trace,
17-
_validate_v4_subplots)
16+
_get_subplot_ref_for_trace)
1817
from .optional_imports import get_module
1918

2019
from _plotly_utils.basevalidators import (
@@ -26,8 +25,6 @@
2625
from plotly.utils import ElidedPrettyPrinter
2726
from .validators import (DataValidator, LayoutValidator, FramesValidator)
2827

29-
from _plotly_future_ import _future_flags
30-
3128
# Create Undefined sentinel value
3229
# - Setting a property to None removes any existing value
3330
# - Setting a property to Undefined leaves existing value unmodified
@@ -51,7 +48,7 @@ class BaseFigure(object):
5148
'plot_bgcolor': 'plot-bgcolor'
5249
}
5350

54-
_set_trace_uid = 'trace_uids' not in _future_flags
51+
_set_trace_uid = False
5552

5653
# Constructor
5754
# -----------
@@ -683,7 +680,6 @@ def select_traces(
683680
selector = {}
684681

685682
if row is not None or col is not None or secondary_y is not None:
686-
_validate_v4_subplots('select_traces')
687683
grid_ref = self._validate_get_grid_ref()
688684
filter_by_subplot = True
689685

@@ -1610,41 +1606,8 @@ def append_trace(self, trace, row, col):
16101606
def _set_trace_grid_position(
16111607
self, trace, row, col, secondary_y=False):
16121608
grid_ref = self._validate_get_grid_ref()
1613-
1614-
from _plotly_future_ import _future_flags
1615-
if 'v4_subplots' in _future_flags:
1616-
return _set_trace_grid_reference(
1617-
trace, self.layout, grid_ref, row, col, secondary_y)
1618-
1619-
if row <= 0:
1620-
raise Exception("Row value is out of range. "
1621-
"Note: the starting cell is (1, 1)")
1622-
if col <= 0:
1623-
raise Exception("Col value is out of range. "
1624-
"Note: the starting cell is (1, 1)")
1625-
try:
1626-
ref = grid_ref[row - 1][col - 1]
1627-
except IndexError:
1628-
raise Exception("The (row, col) pair sent is out of "
1629-
"range. Use Figure.print_grid to view the "
1630-
"subplot grid. ")
1631-
if 'scene' in ref[0]:
1632-
trace['scene'] = ref[0]
1633-
if ref[0] not in self['layout']:
1634-
raise Exception("Something went wrong. "
1635-
"The scene object for ({r},{c}) "
1636-
"subplot cell "
1637-
"got deleted.".format(r=row, c=col))
1638-
else:
1639-
xaxis_key = "xaxis{ref}".format(ref=ref[0][1:])
1640-
yaxis_key = "yaxis{ref}".format(ref=ref[1][1:])
1641-
if (xaxis_key not in self['layout']
1642-
or yaxis_key not in self['layout']):
1643-
raise Exception("Something went wrong. "
1644-
"An axis object for ({r},{c}) subplot "
1645-
"cell got deleted.".format(r=row, c=col))
1646-
trace['xaxis'] = ref[0]
1647-
trace['yaxis'] = ref[1]
1609+
return _set_trace_grid_reference(
1610+
trace, self.layout, grid_ref, row, col, secondary_y)
16481611

16491612
def _validate_get_grid_ref(self):
16501613
try:

Diff for: plotly/config.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
from __future__ import absolute_import
2-
3-
from _plotly_future_ import _chart_studio_warning
4-
_chart_studio_warning('config')
5-
from chart_studio.config import *
2+
from _plotly_future_ import _chart_studio_error
3+
_chart_studio_error('config')

Diff for: plotly/dashboard_objs.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
from __future__ import absolute_import
2-
3-
from _plotly_future_ import _future_flags
4-
5-
6-
if 'remove_deprecations' not in _future_flags:
7-
from _plotly_future_ import _chart_studio_warning
8-
_chart_studio_warning('dashboard_objs')
9-
from chart_studio.dashboard_objs import *
2+
from _plotly_future_ import _chart_studio_error
3+
_chart_studio_error('dashboard_objs')

Diff for: plotly/exceptions.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1+
from __future__ import absolute_import
12
from _plotly_utils.exceptions import *
2-
3-
# Deprecations
4-
from _plotly_future_ import _future_flags
5-
if 'remove_deprecations' not in _future_flags:
6-
from chart_studio.exceptions import *

Diff for: plotly/figure_factory/_facet_grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from plotly import exceptions, optional_imports
44
import plotly.colors as clrs
55
from plotly.figure_factory import utils
6-
from plotly.tools import make_subplots
6+
from plotly.subplots import make_subplots
77

88
import math
99
from numbers import Number

Diff for: plotly/files.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1+
from __future__ import absolute_import
12
from _plotly_utils.files import *
2-
3-
# Deprecations
4-
from _plotly_future_ import _future_flags
5-
if 'remove_deprecations' not in _future_flags:
6-
from chart_studio.files import *

0 commit comments

Comments
 (0)