Skip to content

Commit

Permalink
remove some more py2 cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Sep 15, 2023
1 parent fd9de78 commit 6fd9e96
Show file tree
Hide file tree
Showing 108 changed files with 41 additions and 362 deletions.
12 changes: 6 additions & 6 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ pytest plotly/tests/test_plotly/test_plot.py::test_function

Running tests with tox is much more powerful, but requires a bit more setup.

You'll need to export an environment variable for *each* tox environment you wish to test with. For example, if you want to test with `Python 2.7` and
You'll need to export an environment variable for *each* tox environment you wish to test with. For example, if you want to test with `Python 3.9` and
`Python 3.6`, but only care to check the `core` specs, you would need to ensure that the following variables are exported:
```
export PLOTLY_TOX_PYTHON_27=<python binary>
export PLOTLY_TOX_PYTHON_39=<python binary>
export PLOTLY_TOX_PYTHON_36=<python binary>
```
Expand All @@ -286,15 +286,15 @@ Where the `<python binary` is going to be specific to your development setup. As
# tox envs #
############
export PLOTLY_TOX_PYTHON_27=python2.7
export PLOTLY_TOX_PYTHON_34=python3.4
export TOXENV=py27-core,py34-core
export PLOTLY_TOX_PYTHON_39=python3.9
export PLOTLY_TOX_PYTHON_36=python3.6
export TOXENV=py39-core,py36-core
```
Where `TOXENV` is the environment list you want to use when invoking `tox` from the command line. Note that the `PLOTLY_TOX_*` pattern is used to pass in variables for use in the `tox.ini` file. Though this is a little setup, intensive, you'll get the following benefits:

* `tox` will automatically manage a virtual env for each environment you want to test in.
* You only have to run `tox` and know that the module is working in both `Python 2` and `Python 3`.
* You only have to run `tox` and know that the module is working in all included Python versions.

Finally, `tox` allows you to pass in additional command line arguments that are formatted in (by us) in the `tox.ini` file, see `{posargs}`. This is setup to help with our configuration of [pytest markers](http://doc.pytest.org/en/latest/example/markers.html), which are set up in `packages/python/plotly/pytest.ini`. To run only tests that are *not* tagged with `nodev`, you could use the following command:

Expand Down
2 changes: 0 additions & 2 deletions doc/apidoc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
Expand Down
2 changes: 0 additions & 2 deletions doc/unconverted/python/amazon-redshift.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ This notebook will go over one of the easiest ways to graph data from your [Amaz
In this notebook we'll be using [Amazon's Sample Redshift Data](http://docs.aws.amazon.com/redshift/latest/gsg/rs-gsg-create-sample-db.html) for this notebook. Although we won't be connecting through a JDBC/ODBC connection we'll be using the [psycopg2 package](http://initd.org/psycopg/docs/index.html) with [SQLAlchemy](http://www.sqlalchemy.org/) and [pandas](http://pandas.pydata.org/) to make it simple to query and analyze our data.

```python
from __future__ import print_function #python 3 support

import plotly.plotly as py
import plotly.graph_objs as go
import plotly.tools as tls
Expand Down
1 change: 0 additions & 1 deletion doc/unconverted/python/apache-spark.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ We can test for the Spark Context's existence with `print sc`.
<!-- #endregion -->

```python
from __future__ import print_function #python 3 support
print(sc)
```

Expand Down
4 changes: 1 addition & 3 deletions packages/python/plotly/_plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import base64
import numbers
import textwrap
Expand Down Expand Up @@ -146,7 +144,7 @@ def copy_to_readonly_numpy_array(v, kind=None, force_numeric=False):
# --------------------------
if force_numeric and new_v.dtype.kind not in numeric_kinds:
raise ValueError(
"Input value is not numeric and" "force_numeric parameter set to True"
"Input value is not numeric and force_numeric parameter set to True"
)

if "U" not in kind:
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
Be careful! If you have a lot of unique numbers in your color column you will
end up with a colormap that is massive and may slow down graphing performance.
"""
from __future__ import absolute_import

import decimal
from numbers import Number

Expand Down
4 changes: 1 addition & 3 deletions packages/python/plotly/_plotly_utils/optional_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
Stand-alone module to provide information about whether optional deps exist.
"""
from __future__ import absolute_import

from importlib import import_module
import logging
import sys
Expand All @@ -30,7 +28,7 @@ def get_module(name, should_load=True):
return import_module(name)
except ImportError:
_not_importable.add(name)
except Exception as e:
except Exception:
_not_importable.add(name)
msg = f"Error importing optional module {name}"
logger.exception(msg)
3 changes: 0 additions & 3 deletions packages/python/plotly/_plotly_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from _plotly_utils.basevalidators import ImageUriValidator


PY36_OR_LATER = sys.version_info >= (3, 6)


def cumsum(x):
"""
Custom cumsum to avoid a numpy import.
Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
- exceptions: defines our custom exception classes
"""
from __future__ import absolute_import
import sys
from typing import TYPE_CHECKING
from _plotly_utils.importers import relative_import
Expand Down
3 changes: 0 additions & 3 deletions packages/python/plotly/plotly/_subplots.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

# Constants
# ---------
# Subplot types that are each individually positioned with a domain
Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from _plotly_future_ import _chart_studio_error

_chart_studio_error("api.utils")
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/api/v1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from _plotly_future_ import _chart_studio_error

_chart_studio_error("api.v1")
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/api/v2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from _plotly_future_ import _chart_studio_error

_chart_studio_error("api.v2")
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/basedatatypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import collections
from collections import OrderedDict
import re
Expand Down
11 changes: 1 addition & 10 deletions packages/python/plotly/plotly/basewidget.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import uuid
from importlib import import_module
import os
import numbers

try:
from urllib import parse
except ImportError:
from urlparse import urlparse as parse

import ipywidgets as widgets
from traitlets import List, Unicode, Dict, observe, Integer

from .basedatatypes import BaseFigure, BasePlotlyType
from .callbacks import BoxSelector, LassoSelector, InputDeviceState, Points
from .serializers import custom_serializers
Expand Down
11 changes: 5 additions & 6 deletions packages/python/plotly/plotly/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from plotly.utils import _list_repr_elided


Expand All @@ -17,11 +16,11 @@ def __init__(
def __repr__(self):
return """\
InputDeviceState(
ctrl={ctrl},
alt={alt},
shift={shift},
meta={meta},
button={button},
ctrl={ctrl},
alt={alt},
shift={shift},
meta={meta},
button={button},
buttons={buttons})""".format(
ctrl=repr(self.ctrl),
alt=repr(self.alt),
Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* sequential
"""

from __future__ import absolute_import
from _plotly_utils.colors import * # noqa: F401

__all__ = [
Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from _plotly_future_ import _chart_studio_error

_chart_studio_error("config")
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
import os


Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/dashboard_objs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from _plotly_future_ import _chart_studio_error

_chart_studio_error("dashboard_objs")
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from __future__ import absolute_import
from _plotly_utils.exceptions import *
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/express/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
`plotly.express` is a terse, consistent, high-level wrapper around `plotly.graph_objects`
for rapid data exploration and figure generation. Learn more at https://plotly.com/python/plotly-express/
"""
from __future__ import absolute_import
from plotly import optional_imports

pd = optional_imports.get_module("pandas")
Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/express/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* sequential
"""

from __future__ import absolute_import
from plotly.colors import *


Expand Down
1 change: 0 additions & 1 deletion packages/python/plotly/plotly/express/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Built-in datasets for demonstration, educational and test purposes.
"""

from __future__ import absolute_import
from plotly.data import *

__all__ = [
Expand Down
34 changes: 13 additions & 21 deletions packages/python/plotly/plotly/figure_factory/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Add A Figure Factory to the Plotly [Python Library](https://plot.ly/python/)

Note: we are generally NOT accepting new figure factories anymore. We'll keep this doc around for context and in case we decide to make an exception, but we've found that figure factories expand the scope of the library (and its maintenance burden) beyond what really makes sense, and generates confusion about how these figures relate to the underlying plotly.js objects.

That doesn't mean this pattern is discouraged though, far from it! We encourage you to make more such high-level functions and share them with the community as separate PyPI packages, GitHub Gists, or posts on https://community.plotly.com.

## What is a Figure Factory?
In the Python Plotly Library:

Expand Down Expand Up @@ -61,8 +65,6 @@ If you are making a chart called `foo`, then you must create `_foo.py` in this d
The inside of the `__init__.py` looks like:

```
from __future__ import absolute_import
# Require that numpy exists for figure_factory
import numpy
Expand All @@ -78,19 +80,9 @@ Now add the following line to the end of `__init__.py`:
from plotly.figure_factory._foo import create_foo
```

3. Imports
3. The main function

In `_foo.py` write

```
from __future__ import absolute_import
```

at line 1. You can add other imports later if you will need them.

4. The main function

It's now time to write the main function `create_foo` that will be called directly by the user. It has the form:
It's now time to write the main function `create_foo` that will be called directly by the user. It lives in `_foo.py` and has the form:

```
def create_foo(attribute1, attribute2=value, ...):
Expand All @@ -101,15 +93,15 @@ def create_foo(attribute1, attribute2=value, ...):
:param (type) attribute2: description of what 'attribute2' is.
Default = value
# ...
Example 1:
'''
'''
Example 2:
'''
'''
"""
# code goes here
Expand All @@ -136,15 +128,15 @@ py.iplot(fig, filename='my_figure')

The figure `fig` must be a Plotly Figure, meaning it must have the form `fig = graph_objs.Figure(data=data, layout=layout)`.

5. Useful Tips
4. Useful Tips

It is often not a good idea to put all your code into your `create_foo()` function. It is best practice to not repeat yourself and this requires taking repeated blocks of code and putting them into a separate function.

It is best to make all other functions besides `create_foo()` secret so a user cannot access them. This is done by placing a `_` before the name of the function, so `_aux_func()` for example.

6. Tests
5. Tests

Add unit tests in
Add unit tests in
`plotly/tests/test_optional/test_figure_factory/test_figure_factory.py`.

## Create a Pull Request
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_2d_density.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from numbers import Number

import plotly.exceptions
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from plotly import optional_imports

# Require that numpy exists for figure_factory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division

import plotly.colors as clrs
from plotly import exceptions, optional_imports
from plotly.figure_factory import utils
Expand Down
3 changes: 0 additions & 3 deletions packages/python/plotly/plotly/figure_factory/_bullet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import

import collections
import math

from plotly import exceptions, optional_imports
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_candlestick.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from plotly.figure_factory import utils
from plotly.figure_factory._ohlc import (
_DEFAULT_INCREASING_COLOR,
Expand Down
4 changes: 0 additions & 4 deletions packages/python/plotly/plotly/figure_factory/_dendrogram.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-

from __future__ import absolute_import

from collections import OrderedDict

from plotly import exceptions, optional_imports
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_distplot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from plotly import exceptions, optional_imports
from plotly.figure_factory import utils
from plotly.graph_objs import graph_objs
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_facet_grid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from plotly import exceptions, optional_imports
import plotly.colors as clrs
from plotly.figure_factory import utils
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_gantt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from numbers import Number

import copy
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_ohlc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from plotly import exceptions
from plotly.graph_objs import graph_objs
from plotly.figure_factory import utils
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_quiver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import math

from plotly import exceptions
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_scatterplot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from plotly import exceptions, optional_imports
import plotly.colors as clrs
from plotly.figure_factory import utils
Expand Down
2 changes: 0 additions & 2 deletions packages/python/plotly/plotly/figure_factory/_streamline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import math

from plotly import exceptions, optional_imports
Expand Down
Loading

0 comments on commit 6fd9e96

Please sign in to comment.