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 5 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
12 changes: 6 additions & 6 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ We will support Python 3.12 and higher versions soon.

### Install 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-install.txt
Copy link
Member

Choose a reason for hiding this comment

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

Is this step required in contributing.md? I think it's covered by the editable install of plotly further down.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ndrezn @emilykl if you can spare time today, it would be great to get this one in - thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch @LiamConnors , I'll remove this

(I verified that the setup instructions still work without this step, at least on Mac)

(plotly_dev) $ pip install -r packages/python/plotly/requires-dev.txt
```
### Install 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) $ pip install -r packages/python/plotly/requires-install.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-dev.txt
```

### Editable install of plotly packages
Expand All @@ -173,7 +173,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-dev.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 @@ -261,7 +261,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-dev.txt` as explained above.

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

Expand Down
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

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

$ pip install pandas

Or install Plotly Express and its dependencies directly with:

$ pip install "plotly[pandas]"

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

from ._imshow import imshow
Expand Down
9 changes: 0 additions & 9 deletions packages/python/plotly/requirements.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### Optional Dependencies for Additional Plotly Functionality ###
### ###
### To install, run: ###
### $ pip install -r optional-requirements.txt ###
### $ pip install -r requires-dev.txt ###
### ###
###################################################################

Expand Down
2 changes: 2 additions & 0 deletions packages/python/plotly/requires-install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tenacity>=6.2.0
packaging
2 changes: 2 additions & 0 deletions packages/python/plotly/requires-pandas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas; python_version <= '3.8' # Loose requirement for older Python as older numpy is not supported
pandas>=2.2.0; python_version > '3.0' # Minimum pin to ensure compatibility with all versions of numpy
24 changes: 16 additions & 8 deletions packages/python/plotly/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
else:
skip_npm = False


# Load plotly.js version from js/package.json
def plotly_js_version():
path = os.path.join(
Expand Down Expand Up @@ -273,9 +274,7 @@ def overwrite_plotlyjs_version_file(plotlyjs_version):
# DO NOT EDIT
# This file is generated by the updatebundle setup.py command
__plotlyjs_version__ = "{plotlyjs_version}"
""".format(
plotlyjs_version=plotlyjs_version
)
""".format(plotlyjs_version=plotlyjs_version)
)


Expand All @@ -289,9 +288,7 @@ def overwrite_plotlywidget_version_file(version):
#
# It is edited by hand prior to official releases
__frontend_version__ = "{version}"
""".format(
version=version
)
""".format(version=version)
)


Expand All @@ -303,7 +300,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 @@ -537,6 +533,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 @@ -603,7 +607,11 @@ def run(self):
data_files=[
("etc/jupyter/nbconfig/notebook.d", ["jupyterlab-plotly.json"]),
],
install_requires=["tenacity>=6.2.0", "packaging"],
install_requires=read_req_file("install"),
extras_require={
"pandas": read_req_file("pandas"),
"dev": read_req_file("dev"),
},
zip_safe=False,
cmdclass=dict(
build_py=js_prerelease(versioneer_cmds["build_py"]),
Expand Down