stable-baselines3 icon indicating copy to clipboard operation
stable-baselines3 copied to clipboard

[Feature Request] move pandas to extras

Open psarka opened this issue 4 years ago • 3 comments

🚀 Suggestion

Move pandas dependency to extras.

Motivation

Pandas is a heavy dependency, doing very little for stable baselines and quite annoying when running on a device such as Nvidia Jetson, as I need to build a wheel for it myself. I may find time to contribute this movement, if you would be interested.

### Checklist

  • [x] I have checked that there is no similar issue in the repo (required)

psarka avatar Nov 28 '21 20:11 psarka

Good point and I agree with this (heavy dependency for little functionality). @araffin what is your view on this? We could (potentially?) replace all panda functionality with other dependency-free code, unless that breaks some backwards-compatibility stuff. Changing the dependencies would also cause bit of headache to people (e.g. somebody takes an older project that does not sb3 version [they should have!], and now logger stuff would not work out of the box).

Miffyli avatar Nov 28 '21 21:11 Miffyli

I inspected the code, so let me make a more precise suggestion:

pandas is used only in three places:

  • monitor/load_results
  • logger/read_json
  • logger/read_csv

The last two functions are only used in tests, so they could be moved there. load_results is only used in results_plotter.

matplotlib, another dependency that I would like not to have, is only used in two places:

  • logger/Figure
  • results_plotter

in logger/Figure it is only used as a type annotation, so easy to do without.

That leaves the results_plotter as the only user of both pandas and matplotlib. So my updated proposal would be to:

  • move read_json to tests
  • move read_csv to tests
  • move load_results to results_plotter
  • move pandas and matplotlib to optional dependencies in the extra section, with the impact that results_plotter will no longer work with base installation. Logger will still work.
  • if needed, add pandas to optional dependencies tests section.

psarka avatar Nov 28 '21 22:11 psarka

Hello, rather than changing the install behavior, I would be more in favor of making SB3 run without pandas and matplotlib, so when you install it with pip install --no-deps flag. That would mean doing lazy import of pandas inside load_results (and other helpers) and using if typing.TYPE_CHECKING in the logger.

araffin avatar Nov 29 '21 09:11 araffin