examples icon indicating copy to clipboard operation
examples copied to clipboard

nyc_taxi: Modernize notebooks

Open Azaya89 opened this issue 3 months ago • 17 comments

This PR modernizes the nyc_taxi.ipynb, nyc_taxi-nongeo, and dashboard.ipynb notebooks. After updating the dependencies however, I noticed a bug with the current holoviews version which was fixed here. This will require updating the channels when the new holoviews version is released.

  • [x] Tests passed.

Modernizing an example checklist

Preliminary checks

  • [ ] Look for open PRs and issues that reference the project you are updating. It is possible previous unmerged work in PR could be re-used to modernize the project. Comment on these PRs and issues when appropriate, hopefully we should be able to close some of them after your modernizing work.

Change ‘anaconda-project.yml’ to use the latest workable version of packages

  • [x] Pin python=3.11
  • [x] Remove the upper pin (e.g. hvplot<0.9 to hvplot, panel>=0.12,<1.0 to panel>=0.12) of all other dependencies. Removing the upper pins of dependencies could necessitate code revisions in the notebooks to address any errors encountered in the updated environment. Should complexities or extensive time requirements arise, document issues for team discussion on whether to re-pin specific packages or explore other solutions.
  • [x] Add/update the lower pin of all other dependencies (e.g. hvplot to hvplot>=0.9.2, hvplot>=0.8 to hvplot>=0.9.2). Usually, the new/updated lower pin of a dependency will be the version resolved after anaconda prepare has been run. Execute !conda list in a notebook, or anaconda run conda list in the terminal, to display the version of each dependency installed in the environment. Adjusting the lower pin helps ensure that the locks produced for each platform (linux-64, win-64, osx-64, osx-arm64) rely on the tested dependencies and not on some older versions.
  • [ ] If one of the channels include conda-forge or pyviz, ask Maxime if it can be removed

Plot API updates (discussed on a per-example basis)

  • [ ] Generally, try to replace HoloViews usage with hvPlot. At a certain point of complexity, such as with the use of ‘.select’, it might be better to stick with HoloViews. Additional examples of ‘complexity boundaries’ should be documented in this document.
  • [x] Almost always, try to replace the use of datashade with rasterize (read this page). Essentially, rasterize allows Bokeh to handle the colormapping instead of Datashader.

Interactivity API updates (discussed on a per-example basis)

  • [x] Remove all pn.interact usage
  • [ ] Avoid .param.watch() usage. This is pretty low-level and verbose approach and should not be used in Examples unless required, or an Example is specifically trying to demo its usage in an advanced workflow.
  • [ ] Prefer using pn.bind(). Read this page for explanation.
  • [ ] For apps built using a class approach, when they create a view() method and call it directly, update the class by inheriting from pn.viewable.Viewer and replace view() by __panel__(). Here is an example.

Panel App updates (discussed on a per-example basis)

  • [ ] If the project doesn’t at any point create a Panel app at all, consider creating one. It can be as simple as wrapping a plot in pn.Column, or more complicated to incorporate widgets, etc. Make the final app .servable().
  • [ ] If the project creates an app in a notebook but doesn’t deploy it (i.e. there is no command: dashboard declaration in the anaconda-project.yml file), try adding it.
  • [ ] If the project already deploys an app but doesn’t wrap it in a nice template, consider wrapping it in a template.
  • [ ] If the project deploys an app wrapped in a template, customize the template a little so all the apps don’t look similar (e.g. change the header background color). This doesn’t need to be discussed.
  • [ ] Comment start If you are building the application in a single cell, you can construct a template explicitly, like template = pn.template.BootstrampTemplate, but if building up an app across multiple cells, it is probably cleaner to declare the template at the top with pn.extension(template='bootstrap'). See how to guide on setting a template.

General code quality updates

  • [ ] If the notebook disables warnings (e.g. with warnings.simplefilter(‘ignore’) somewhere at the start of the notebook, remove this line. Try to update the code to remove the warnings, if any. If updating the code to remove the warnings is taking significant amount of time and effort, bring it up for discussion and we may decide to disable warnings again.

Text content

  • [ ] Edit the text content anywhere and everywhere that it can be improved for clarity.
  • [ ] Check the links are valid, and update old links (e.g. http -> https, xyz.pyviz.org -> xyz.holoviz.org)
  • [ ] Remove instructions to install packages inside an example

Visual appearance - Example

  • [ ] Check that the titles/headings make sense and are succinct.
  • [ ] Check that the text content blocks are easily readable; revise into additional paragraphs if needed.
  • [ ] Check that the code blocks are easily readable; revise as needed. (e.g. add spaces after commas in a list if there are none, wrap long lines, etc.)
  • [ ] Check image and plot sizes. If possible, making them responsive is highly recommended.
  • [ ] Check the appearance on a smartphone (check Google to see how to adapt the appearance of your browser to display pages as if they were seen from a smartphone, this is usually done via the web developer tools). This is not a top priority for all examples, but if there are a few easy and straightforward changes to make that can improve the experience, let’s do it.
  • [ ] Check the updated notebook with the original notebook

Visual appearance - Gallery

  • [ ] Check the thumbnail is visually appealing
  • [ ] Check the project title is well formatted (e.g. Ml Annotators to ML Annotators), if not, add/update the examples_config.title field in anaconda-project.yml
  • [ ] Check the project description is appropriate, if not, update the description field in anaconda-project.yml

Workflow (after you have made the changes above)

  • [ ] Run successfully doit validate:<projectname>
  • [ ] Run successfully doit test:<projectname>
  • [ ] Run successfully doit doc_one –name <projectname>. It’s better if the project notebook(s) is saved with its outputs (but be sure to clear outputs before committing to the examples repo!) when building the docs. Then open this file in your browser ./builtdocs/index.html and check how the site looks.
  • [ ] If you’re happy with all the above, open a PR. Reminder, clear notebook outputs before pushing to the PR.

Azaya89 avatar Mar 21 '24 15:03 Azaya89

Thanks! Can you tell me what steps will let me reproduce this running project? E.g. anaconda-project prepare followed by something to use the git master version of holoviews (or maybe make a dev release?)?

jbednar avatar Mar 21 '24 20:03 jbednar

Thanks! Can you tell me what steps will let me reproduce this running project? E.g. anaconda-project prepare followed by something to use the git master version of holoviews (or maybe make a dev release?)?

It's been updated to depend on pyviz/label/dev. One question though, didn't we say we wanted the projects to depend on defaults as much as possible? During the big update end of last year, I removed pyviz and conda-forge as much as possible.

maximlt avatar Mar 21 '24 20:03 maximlt

Thanks! Can you tell me what steps will let me reproduce this running project? E.g. anaconda-project prepare followed by something to use the git master version of holoviews (or maybe make a dev release?)?

I think you can just run it the same way as before (i.e, anaconda-project run), since I've updated the lock files to use the dev version of holoviews.

It's been updated to depend on pyviz/label/dev. One question though, didn't we say we wanted the projects to depend on defaults as much as possible? During the big update end of last year, I removed pyviz and conda-forge as much as possible.

I think this is only temporary until the new holoviews version is released. Afterwards, we can update the lock files. @Hoxbro

Azaya89 avatar Mar 21 '24 20:03 Azaya89

As @Azaya89 said, it is temporary until the next release of HoloViews is out.

hoxbro avatar Mar 25 '24 08:03 hoxbro

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Mar 25 '24 14:03 github-actions[bot]

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Mar 25 '24 14:03 github-actions[bot]

As @Azaya89 said, it is temporary until the next release of HoloViews is out.

Ok noted thanks. Let's switch back to the defaults channel when HoloViews is released with this fix.

maximlt avatar Mar 25 '24 23:03 maximlt

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Mar 26 '24 08:03 github-actions[bot]

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Mar 27 '24 16:03 github-actions[bot]

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Apr 08 '24 08:04 github-actions[bot]

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Apr 11 '24 09:04 github-actions[bot]

I'm getting this warning when I run doit validate:nyc_taxi: "WARNING: Notebook nyc_taxi/index.ipynb must not contain any code cell outputs, please clear it." but the index.ipynb file doesn't even have any code cell output in the first place.

Does it have something to do with #377 ? @maximlt

Azaya89 avatar Apr 11 '24 11:04 Azaya89

I'm getting this warning when I run doit validate:nyc_taxi: "WARNING: Notebook nyc_taxi/index.ipynb must not contain any code cell outputs, please clear it." but the index.ipynb file doesn't even have any code cell output in the first place.

Does it have something to do with #377 ? @maximlt

Good catch thanks! Should be fixed by https://github.com/holoviz-topics/examples/pull/380.

maximlt avatar Apr 11 '24 18:04 maximlt

I updated your original post with the modernizing checklist.

maximlt avatar Apr 11 '24 22:04 maximlt

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar Apr 12 '24 12:04 github-actions[bot]

I have effected most of the requested changes. Pls let me know if I missed anything while we wait for the new holoviews version to be released :)

Azaya89 avatar Apr 12 '24 12:04 Azaya89

@Azaya89 I reviewed the changes you made, they look good to me. What is left I think:

  • [x] Use next version of hvPlot when released
    • No longer call df.hvplot.<>(...).opts(bgcolor='...') but instead df.hvplot.<>(..., bgcolor='...')
  • [x] Add min pins (e.g. package >=X.X) to the dependencies in the anaconda-project.yml file
  • [x] Go through the whole checklist and check all items
  • [x] Ping Jim when done for a final review

maximlt avatar Apr 19 '24 06:04 maximlt

@Azaya89 hvPlot 0.10.0 has been released so you can now update the code to use bgcolor directly when calling hvPlot instead of via .opts(). When done, please ask Jim if he wants to review.

maximlt avatar May 07 '24 04:05 maximlt

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar May 07 '24 15:05 github-actions[bot]

Your changes were successfully integrated in the dev site, make sure to review the pages of the projects you touched before merging this PR: https://holoviz-dev.github.io/examples/. You can also download an archive of the site from the workflow summary page which comes in handy when your dev site built was overriden by another PR (we have a single dev site!).

github-actions[bot] avatar May 17 '24 08:05 github-actions[bot]

Merging, thanks @Azaya89, great job!

maximlt avatar May 17 '24 08:05 maximlt