Skip to content

API: deprecate show_in_notebook - #15905

Merged
taldcroft merged 8 commits into
astropy:mainfrom
MridulS:deprecate_js
Feb 20, 2024
Merged

taldcroft merged 8 commits into
astropy:mainfrom
MridulS:deprecate_js

Conversation

@MridulS

@MridulS MridulS commented Jan 17, 2024 •

Copy link
Copy Markdown
Contributor

Description

Let's take a bit agressive way to fix #15566, this PR proposes to deprecate show_in_notebook() and all notebook (classic) specific JS code. The Jupyter Notebook has moved to using the JupyterLab plumbing (from v7) and the classic notebook is on maintainence mode. Things will probably move fast in the JupyterLab world and the JS specific code in astropy will only work with classic notebook. I would argue that astropy shouldn't be in the business of JS specific logic, this should either be delagated to other third party tools like https://github.com/bloomberg/ipydatagrid, https://github.com/mwouts/itables or the jupyter specific code be moved to a new package something like astropy-jupyter-extension. This should make the maintenance much more sustainable.

There is some conversation on Slack regarding this: https://astropy.slack.com/archives/C067V74GK/p1705405195253679

Well this "fixes" a lot of show_in_notebook issues 😅

cc @hamogu @pllim @mwcraig @dhomeier

fix #11836, fix #9660 (partially, as this feature could still be added to show_in_browser), fix #15566, fix #10317

@MridulS
MridulS requested a review from taldcroft as a code owner January 17, 2024 18:19
@github-actions github-actions Bot added the table label Jan 17, 2024
@github-actions

github-actions Bot commented Jan 17, 2024 •

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim pllim added this to the v6.1.0 milestone Jan 17, 2024
@pllim pllim added the API change PRs and issues that change an existing API, possibly requiring a deprecation period label Jan 17, 2024
@pllim
pllim requested a review from mwcraig January 17, 2024 22:14
@pllim

pllim commented Jan 17, 2024

Copy link
Copy Markdown
Member

I'll defer to subpackage maintainers and Jupyter experts here. The test fails because you need to handle this new warning. Also would need a change log.

Thanks!

Comment thread astropy/table/table.py
return HTML(html)

@deprecated_renamed_argument("jsviewer", None, "6.1", pending=True)
def show_in_browser(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

show_in_browser is not related to Jupyter, and is not broken. It creates a standalone HTML file and was the original reason of using datatables etc., the notebook integration came later.
Not sure if it's widely used though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, but if we are going to remove all JS code, it might make sense to remove all the related bits. It should also help with resolving issues like #10420 and #11188

I know I'm being a bit bold here and marking it as a pending deprecation may tell us if there are people out there using this bit :D

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree show_in_browser is not Jupyter-related. What about splitting this into two PRs? I think deprecating show_in_notebook is the right call, and that we shouldn't replace it. The underpinnings of notebook change too often for us to support well in astropy.

I'm less clear about show_in_browser.

On the one hand, it works. On the other hand, it adds dependencies that we are bundling in jsviewer.py that are not update regularly by dependabot. If we are going to supply show_in_browser then it seems worth discussing separately from show_in_notebook.

At the end of the day, I lean towards deprecating show_in_browser too and seeing what the reaction from the community is...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find show_in_browser to be very useful fwiw, although I don't really use the jsviewer flag that often.

@mwcraig mwcraig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See my inline comments. To summarize, I'd recommend changing this notebook to deprecate show_in_notebook and a separate PR to handle show_in_browser.

@hamogu

hamogu commented Jan 19, 2024 •

Copy link
Copy Markdown
Member

As a developer, I agree to deprecating both (but I also support @mwcraig 's suggestion of discussing that in two separate PRs, since one case is more clear than the other).

As a user, I always forget that show_in_browser exists. I re-discover it about every other year, find that I love the feature, use if for a while and then forget about it again.

We already have a .to_pandas methods for tables and pandas has extensive styling support. Maybe we can just recommend to to use that for display in a notebook in one of our examples? Sure, it requires pandas to be installed, but that's not hard for most users and it actually offers functionality that the current show_in_notebook does not have, in particular the pandas build-in styles look pretty good. Maybe that extra styling functionality can compensate for the slightly less convenient use (pandas needs to be installed, need to click to the pandas docs to see how to use it)?

If we can make the same work for show_in_browser, then again that "extra functionality" makes up for the loss of convenience for me.

panel is less commonly used than pandas, but their Tabulator widgets displays a table sortable per column, which is often useful.

Edit: Add link to Tabulator widget.

@hamogu

hamogu commented Jan 19, 2024

Copy link
Copy Markdown
Member

Similarly, one might also use a bokeh DataTable.

My point is that instead of offloading the task of displaying the html table to a js library that we bundle, we could do that indirectly and offload to some other python package from the scientific ecosystem where js support is closer to their core mission and have them worry about which version to bundle and howto handle notebook updates etc.

I think of this a mostly a documentation task: "If you want to display your astropy.table.Table nicely, here are a few packages that can do that for you and here is a simple example how your astropy table can be passed to them and displayed ... "

@MridulS

MridulS commented Jan 19, 2024

Copy link
Copy Markdown
Contributor Author

Thanks all for your reviews!

Yes I think it probably makes sense to link to other well maintained libraries for working with Tables interactively inside a jupyter environment. I have removed the deprecation of JSViewer in this PR, I'll open a new one so we can discuss this it there.

@MridulS MridulS changed the title API: deprecate show_in_notebook and JSViewer API: deprecate show_in_notebook Jan 19, 2024
@taldcroft

Copy link
Copy Markdown
Member

👍 in general on deprecating these methods. I never found them all that useful in practice and the interactive browser is a bit clunky.

@taldcroft

taldcroft commented Jan 22, 2024 •

Copy link
Copy Markdown
Member

pandas has extensive styling support. Maybe we can just recommend to to use that for display in a notebook in one of our examples?

I just had a look at the pandas styling and I don't think that would be useful for the most-common use case of someone that was previously using show_in_notebook or show_in_browser using default styling (i.e. not supplying some custom CSS to make a fancy looking table).

The pandas machinery does not (AFAIK) provide a way to interactively browse a table. It just clips the table in the same way that astropy does. (Maybe I'm missing something?). So I would be against recommending a workflow that uses pandas styling. For the 98% use case here (setting precision of floats), astropy table formatting does the job and is way more convenient (IMHO).

@mwcraig mwcraig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the short run we can just open an issue to note that it would be nice to recommend a replacement rather than hashing that out here.

pllim
pllim previously requested changes Jan 22, 2024

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, but I have a question and a comment.

Comment thread astropy/table/table.py Resolved
@eerovaher

Copy link
Copy Markdown
Member

There are good reasons to deprecate the functions in question, but I would like there to be documentation about available alternatives, and if we do write such documentation then the deprecation message should point to it.

@taldcroft

Copy link
Copy Markdown
Member

There are good reasons to deprecate the functions in question, but I would like there to be documentation about available alternatives, and if we do write such documentation then the deprecation message should point to it.

I'm not aware of any easy alternatives to show_in_notebook(). The pandas styling stuff is basically equivalent to the table repr in a notebook but AFAIK it does not have any javascript bling like showing only 50 rows or sorting by columns.

@pllim
pllim dismissed their stale review February 14, 2024 15:29

Outdated

@pllim

pllim commented Feb 14, 2024

Copy link
Copy Markdown
Member

tl;dr -- I see one approval, so is the diff okay as-is or more discussion needed? If so, what?

Comment thread docs/changes/table/15905.api.rst Resolved
@mwcraig

mwcraig commented Feb 14, 2024

Copy link
Copy Markdown
Member

ipydatagrid is what I would have recommended -- I think that with the alternatives listed now this is good to go. May want to wait for @taldcroft though?

@MridulS

MridulS commented Feb 19, 2024

Copy link
Copy Markdown
Contributor Author

@taldcroft just wanted to bump this up.

Comment thread astropy/table/table.py Resolved
@eerovaher

Copy link
Copy Markdown
Member

One more thing that we have failed to notice so far is that show_in_notebook() is mentioned in the table documentation:

Or you can get a fancier notebook interface with in-browser search, and sort
using :meth:`~astropy.table.Table.show_in_notebook`:

If we are deprecating the function then we shouldn't be advertising it in our documentation anymore.

@pllim

pllim commented Feb 19, 2024

Copy link
Copy Markdown
Member

Just in case, you could do a recursive grep on the whole repo checkout too, to smoke out the rest.

@eerovaher eerovaher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should now be good enough to squash and merge, but I'm not a table maintainer.

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great, thanks @MridulS for getting this done!

@taldcroft

Copy link
Copy Markdown
Member

And thanks to other reviewers for the inputs.

@taldcroft

Copy link
Copy Markdown
Member

@MridulS - I've approved this, but can you track down the "show-in-notebook" issues that this fixes and put them in the description before we merge so they all get auto-closed?

@MridulS

MridulS commented Feb 20, 2024

Copy link
Copy Markdown
Contributor Author

@taldcroft thanks! updated #15905 (comment) with the relevant issues.

@pllim

pllim commented Feb 20, 2024

Copy link
Copy Markdown
Member

So, is this good to merge now? 😸

@taldcroft
taldcroft merged commit e1b6a24 into astropy:main Feb 20, 2024
@taldcroft

Copy link
Copy Markdown
Member

So, is this good to merge now? 😸

YES!

@pllim

pllim commented Feb 20, 2024

Copy link
Copy Markdown
Member

So happy to see one PR closes multiple issues. Thanks, all!

@pllim

pllim commented Jul 11, 2024 •

Copy link
Copy Markdown
Member

Looks like not everyone is happy with this, please see #16702 and advise. Thanks!

d-giles referenced this pull request in d-giles/astropy-abdufork Jul 26, 2024
* API: deprecate show_in_notebook and JSViewer

* do not deprecate jsviewer, add test

* remove pending deprecation

* Add links to alternatives

* add API doc

* Update docs/changes/table/15905.api.rst

Co-authored-by: P. L. Lim <[email protected]>

* Update astropy/table/table.py

Co-authored-by: Eero Vaher <[email protected]>

* remove show_in_notebook for table docs

---------

Co-authored-by: P. L. Lim <[email protected]>
Co-authored-by: Eero Vaher <[email protected]>
@bsipocz

bsipocz commented Oct 9, 2024

Copy link
Copy Markdown
Member

I run into this today as prepping notebooks for an upcoming AAS workshop. I see why it is removed, but otoh none of the offered alternatives are as nice our of the box experience, I mean I don't want to pull in all of bokeh just to have nicely formatted tables in a notebook.

(we didn't use the show_in_notebook for anything fancy and interactive just to have a sensibly formatted, and not ellipsed table with nicely defaulted scroller and such. Part of the workshop was to showcase astropy, too and why Table is "better" than pandas (the question comes up regularly), but if any of these third-party table tools need to be pulled in we may just pull the plug and switch to pandas?).

@taldcroft

Copy link
Copy Markdown
Member

why Table is "better" than pandas (the question comes up regularly)

We should have a FAQ, but for the record (and for your tutorial), Table provides these capabilities that are not in pandas DataFrame:

  • Robust support for table and column metadata. This is needed for representing data in file formats like FITS and VOTable.
  • Support for N-dimensional column data, for example a table of thumbnail images in a source catalog.
  • Support for columns of astropy Time, Quantity, and SkyCoord / Frame objects.
  • General support for external "mixin" columns, for instance dask arrays.

@taldcroft

Copy link
Copy Markdown
Member

As far as I can tell (from quick googling), pandas does not provide an interactive scrollable notebook interface for exploring notebooks. Google just shows 3rd party solutions. This choice by pandas would seem to support the astropy decision to delegate this kind of functionality to 3rd party packages.

I mean I don't want to pull in all of bokeh just to have nicely formatted tables in a notebook.

This sort of comment comes up regularly, and I respect your perspective but honestly do not understand it. I just installed bokeh and it required 6.9 Mb and completed in under a second, so I would just do it without a second thought and then use it.

@taldcroft

Copy link
Copy Markdown
Member

There is this interesting news: https://blog.jupyter.org/ipydatagrid-is-now-part-of-project-jupyter-3b3dfb877664

I haven't looked into it carefully, but maybe we can leverage ipydatagrid and provide interactive Table display using this as the optional (?) dependency. BTW standalone ipydatagrid install is a little lighter at 3.1 Mb.

@pllim

pllim commented Oct 9, 2024

Copy link
Copy Markdown
Member

@bsipocz

bsipocz commented Oct 9, 2024

Copy link
Copy Markdown
Member

If you forget interactivity (I don't necessarily need that, for more complex interactivity tasks we use firefly anyway), but if there was an easy opt in config list that would make Table printing look pretty in a notebook by default, I would be super happy with it.
I know it shouldn't really be astropy's task to come up with this and keep maintaining it, but in practice, we already do something similar for visualization etc.

(I am thinking for my users who work in notebooks, and I really can't see it being a nice workflow to have them work with tables and any time they need to print more than a handful or rows I suggest them to pop into a third-party library instead. )

And my issue with adding bokeh just for this is not about size, but past experience of their changing API (it may very well be more stable now), and the technical debt I would introduce to this material just by introducing a new dependency with the sole purpose of pretty printing tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change PRs and issues that change an existing API, possibly requiring a deprecation period table

Projects

None yet

9 participants