plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Add optional download requirements for dev and plotly express

Open ndrezn opened this issue 1 year ago • 17 comments

Closes #2279

This PR adds the ability to install Plotly with:

pip install plotly[pandas]

which bundles pandas in the install, required by plotly.express and:

pip install plotly[dev]

which installs dev requirements for the package.

This also revises the warning when using plotly.express if pandas is not installed.

Open to ideas on better wording.

(plotly.py) ➜  plotly.py git:(better-pandas-warning) python
Python 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import plotly.express
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/nathandrezner/Plotly/plotly.py/packages/python/plotly/plotly/express/__init__.py", line 10, in <module>
    raise ImportError(
ImportError: 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/

ndrezn avatar Jun 19 '24 19:06 ndrezn

We can plausibly drop the note about graph objects but basically I want some sort of explanation of why pandas isn't a dependency.

ndrezn avatar Jun 19 '24 19:06 ndrezn

We shouldn't recommend pip install plotly.express , I believe it only exists for backwards compatibility and it's confusing to have multiple install paths.

If we want to have a one-liner "install everything" command that should be a change made inside Plotly.py.

emilykl avatar Jun 19 '24 19:06 emilykl

I was thinking of adding:

pip install plotly[express]

as an option which goes with usual pip patterns for optional dependencies. If we went that route I would expect that we drop support for pip install plotly.express entirely.

ndrezn avatar Jun 19 '24 20:06 ndrezn

@gvwilson there are other changes following @emilykl 's comment. It might make sense to break this into two PRs to be honest...

ndrezn avatar Jun 19 '24 20:06 ndrezn

:+1: on breaking the PR - thank you

gvwilson avatar Jun 19 '24 20:06 gvwilson

IMO the naming should be plotly[pandas] rather than plotly[express] -- much more clear what it's actually doing.

I'm in favor of this change, but let's not merge it right away. This PR changes a number of lines in setup.py so it's not just an addition; it could feasibly break the install process for some users. Need to do really solid QA to make sure it runs smoothly.

emilykl avatar Jun 19 '24 20:06 emilykl

@gvwilson on further thought I think it makes sense to keep these changes in one PR. The text in the warning message is directly related to the installation recommendations that are also added in this PR -- I've updated the title & description to make the primary change more clear.

ndrezn avatar Jun 19 '24 21:06 ndrezn

:+1:

gvwilson avatar Jun 19 '24 22:06 gvwilson

@emilykl is this PR good to go with the latest changes?

ndrezn avatar Jul 29 '24 20:07 ndrezn

@marthacryan could you take a look at this?

ndrezn avatar Oct 09 '24 15:10 ndrezn

See also #4790

gvwilson avatar Oct 09 '24 19:10 gvwilson

@ndrezn So is pip install plotly[pandas] exactly the same as pip install pandas?

marthacryan avatar Oct 15 '24 15:10 marthacryan

@marthacryan pip install plotly[pandas] would be roughly equivalent to pip install plotly && pip install pandas I believe.

emilykl avatar Oct 15 '24 15:10 emilykl

Oh interesting. What is the benefit here over just using pip install plotly pandas?

marthacryan avatar Oct 15 '24 15:10 marthacryan

The benefit is we recommend a specific version number for compatibility. I don't think we have issues with different versions of Pandas but this makes it easy to pin a version of Pandas for use with Plotly if we ever encounter issues.

In fact we're doing that here, where we install the latest pandas for new versions of Python but force older pandas for older Python. People in the original issue were having funky errors caused by this incompatibility: https://github.com/plotly/plotly.py/issues/2279#issuecomment-721024313

ndrezn avatar Oct 15 '24 15:10 ndrezn

conversation with @ndrezn he believes this should go in before #4790 (Narwhals support) so moving it to the 3.0 release cycle.

gvwilson avatar Oct 18 '24 14:10 gvwilson

The benefit is we recommend a specific version number for compatibility. I don't think we have issues with different versions of Pandas but this makes it easy to pin a version of Pandas for use with Plotly if we ever encounter issues.

In fact we're doing that here, where we install the latest pandas for new versions of Python but force older pandas for older Python. People in the original issue were having funky errors caused by this incompatibility: #2279 (comment)

Oh ok that makes sense! Maybe for documenting the usage of that we could make that more clear?

marthacryan avatar Oct 18 '24 20:10 marthacryan

Looks good to me. Could you add a changelog entry for it too.

LiamConnors avatar Nov 21 '24 14:11 LiamConnors