Skip to content
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

request: Pyodide support for polars; Use polars in shinylive examples #1576

Open
schloerke opened this issue Jul 26, 2024 · 2 comments
Open
Labels
enhancement New feature or request shinylive Related to hosting app with shinylive
Milestone

Comments

@schloerke
Copy link
Collaborator

Related:

Goal: Display an example app using polars on shinylive (wasm / pyodide).

Failing reprex: link

Error:

>>> Installing polars ...
Traceback (most recent call last):
  File "<exec>", line 369, in _start_app
  File "<exec>", line 302, in _install_requirements_from_dir
  File "/lib/python3.12/site-packages/micropip/_commands/install.py", line 142, in install
    await transaction.gather_requirements(requirements)
  File "/lib/python3.12/site-packages/micropip/transaction.py", line 55, in gather_requirements
    await asyncio.gather(*requirement_promises)
  File "/lib/python3.12/site-packages/micropip/transaction.py", line 62, in add_requirement
    return await self.add_requirement_inner(Requirement(req))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/micropip/transaction.py", line 151, in add_requirement_inner
    await self._add_requirement_from_package_index(req)
  File "/lib/python3.12/site-packages/micropip/transaction.py", line 190, in _add_requirement_from_package_index
    wheel = find_wheel(metadata, req)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.12/site-packages/micropip/transaction.py", line 281, in find_wheel
    raise ValueError(
ValueError: Can't find a pure Python 3 wheel for 'polars'.
See: https://pyodide.org/en/stable/usage/faq.html#why-can-t-micropip-find-a-pure-python-wheel-for-a-package
You can use `await micropip.install(..., keep_going=True)` to get a list of all packages with missing wheels.

Shiny uses shinylive to display its examples in the browser (via pyodide) without a central compute server. It would be nice to have polars in these examples. However, polars currently does not compile for pyodide due to threading.

Talking with @georgestagg , he believes we can follow pattern of huggingface/tokenizers's flag where they turn off threads given an envvar value (or if we could determine if the target is wasm).

If a fix is found, this could be a possible technical blog post?


Made issue for tracking. Will pick back up after posit::conf(2024). The fix will most likely need to be in the pola-rs/polars repo.

cc @gadenbuie @wch

@schloerke schloerke added enhancement New feature or request shinylive Related to hosting app with shinylive labels Jul 26, 2024
@schloerke schloerke added this to the v1.2.0 milestone Jul 26, 2024
@georgestagg
Copy link

Sneak preview:

Screenshot 2024-09-26 at 11 26 03

This currently requires patches to LLVM's wasm-ld & Rust's rustc, so that the inventory crate can be made to work with Wasm. With those patches, plus a bunch of stubbing out of currently problematic features (e.g. cloud, aws, a bunch more...), the core of polars can be built for Pyodide.

I will attempt to re-enable as many features as I can, then write things up in a document/blog post.

Later, we can start thinking about merging PRs to LLVM and inventory. If the required patches turn out to be no good, we could still create a Docker image with a custom compiler suite to build the polars wheel, and distribute the resulting binary with shinylive (I do this for webR system libraries and it works mostly OK).

@georgestagg
Copy link

georgestagg commented Dec 24, 2024

Pyodide wheels are now being built for Polars and v1.18.0 is available at https://github.com/pola-rs/polars/releases/tag/py-1.18.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request shinylive Related to hosting app with shinylive
Projects
None yet
Development

No branches or pull requests

2 participants