Skip to content

Add plotly[express] extra for easily installing Plotly Express dependencies #4644

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 21 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
14 changes: 6 additions & 8 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,17 @@ We will support Python 3.12 and higher versions soon.
[conda-env]: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands
[virtualenv]: http://docs.python-guide.org/en/latest/dev/virtualenvs/

### Install requirements - (Non-Windows)
### Install development requirements (Non-Windows)
```bash
(plotly_dev) $ pip install -r packages/python/plotly/requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/optional-requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/requires-optional.txt
```
### Install requirements - (Windows + Conda)
### Install development requirements (Windows + Conda)
Because Windows requires Visual Studio libraries to compile some of the optional dependencies, follow these steps to
complete installation and avoid gdal-config errors.

```bash
(plotly_dev) $ pip install -r packages/python/plotly/requirements.txt
(plotly_dev) $ conda install fiona
(plotly_dev) $ pip install -r packages/python/plotly/optional-requirements.txt
(plotly_dev) $ pip install -r packages/python/plotly/requires-optional.txt
```

### Editable install of plotly packages
Expand Down Expand Up @@ -178,7 +176,7 @@ documentation on _development mode_.
This repo uses the [Black](https://black.readthedocs.io/en/stable/) code formatter,
and the [pre-commit](https://pre-commit.com/) library to manage a git commit hook to
run Black prior to each commit. Both pre-commit and black are included in the
`packages/python/plotly/optional-requirements.txt` file, so you should have them
`packages/python/plotly/requires-optional.txt` file, so you should have them
installed already if you've been following along.

To enable the Black formatting git hook, run the following from within your virtual
Expand Down Expand Up @@ -266,7 +264,7 @@ We take advantage of two tools to run tests:

### Running Tests with `pytest`

Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `optional-requirements.txt` as explained above.
Since our tests cover *all* the functionality, to prevent tons of errors from showing up and having to parse through a messy output, you'll need to install `requires-optional.txt` as explained above.

After you've done that, go ahead and run the test suite!

Expand Down
2 changes: 2 additions & 0 deletions packages/python/plotly/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ include LICENSE.txt
include README.md
include versioneer.py
include plotly/_version.py
include requires-install.txt
include requires-express.txt
include plotly/package_data/widgetbundle.js
58 changes: 0 additions & 58 deletions packages/python/plotly/optional-requirements.txt

This file was deleted.

13 changes: 12 additions & 1 deletion packages/python/plotly/plotly/express/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
`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 plotly import optional_imports

np = optional_imports.get_module("numpy")
if np is None:
raise ImportError(
"""\
Plotly express requires numpy to be installed."""
Plotly Express requires numpy to be installed. You can install numpy using pip with:

$ pip install numpy

Or install Plotly Express and its dependencies directly with:

$ pip install "plotly[express]"

You can also use Plotly Graph Objects to create a large number of charts without installing
numpy. See examples here: https://plotly.com/python/graph-objects/
"""
)

from ._imshow import imshow
Expand Down
8 changes: 8 additions & 0 deletions packages/python/plotly/requires-express.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Required dependencies for Plotly Express ###
### ###
### To install, run: ###
### $ pip install -r requires-express.txt ###
### ###
###################################################

numpy
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
### Dependencies for Core Plotly Functionality ###
### ###
### To install, run: ###
### $ pip install -r requirements.txt ###
### $ pip install -r requires-install.txt ###
### ###
###################################################

## dataframe agnostic layer ##
narwhals>=1.13.3
packaging
59 changes: 59 additions & 0 deletions packages/python/plotly/requires-optional.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
### Optional Dependencies for Additional Plotly Functionality ###
### ###
### This file lists packages which are not strictly required ###
### by Plotly.py, but which are needed to use some of the ###
### library's functionality. See headings below for more ###
### See headings below for more detail. ###
### ###
### Packages used in the development process are also listed ###
### here. ###
### ###
### To install, run: ###
### $ pip install -r requires-optional.txt ###
### ###
###################################################################

## numpy (required by Plotly Express) ##
numpy

## matplotlylib dependencies ##
# matplotlib==2.2.2

## testing dependencies ##
coverage==4.3.1
mock==2.0.0
pytest==8.1.1
xarray
pytz

## orca dependencies ##
requests
psutil

## code formatting ##
pre-commit
black==22.3.0

## codegen dependencies ##
inflect

## template generation ##
colorcet

## pandas (for some matplotlib functionality) ##
pandas

## scipy deps (for some FigureFactory functions) ##
scipy

## jupyter ##
jupyter
anywidget

## deps for _county_choropleth.py figure factory ##
pyshp
geopandas
shapely

## image uri conversion ##
pillow
15 changes: 13 additions & 2 deletions packages/python/plotly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
else:
skip_npm = False


# Load plotly.js version from js/package.json
def plotly_js_version():
path = os.path.join(here, "js", "package.json")
Expand Down Expand Up @@ -260,7 +261,6 @@ def request_json(url):


def get_latest_publish_build_info(repo, branch):

url = (
r"https://circleci.com/api/v1.1/project/github/"
r"{repo}/tree/{branch}?limit=100&filter=completed"
Expand Down Expand Up @@ -494,6 +494,14 @@ def run(self):
]

versioneer_cmds = versioneer.get_cmdclass()


def read_req_file(req_type):
with open(f"requires-{req_type}.txt", encoding="utf-8") as fp:
requires = (line.strip() for line in fp)
return [req for req in requires if req and not req.startswith("#")]


setup(
name="plotly",
version=versioneer.get_version(),
Expand Down Expand Up @@ -551,7 +559,10 @@ def run(self):
"package_data/datasets/*",
],
},
install_requires=["narwhals>=1.13.3", "packaging"],
install_requires=read_req_file("install"),
extras_require={
"express": read_req_file("express"),
},
zip_safe=False,
cmdclass=dict(
build_py=js_prerelease(versioneer_cmds["build_py"]),
Expand Down