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

polars.DataFrame.plot support tracking #3514

Closed
dangotbanned opened this issue Aug 3, 2024 · 0 comments · Fixed by #3515
Closed

polars.DataFrame.plot support tracking #3514

dangotbanned opened this issue Aug 3, 2024 · 0 comments · Fixed by #3515

Comments

@dangotbanned
Copy link
Member

dangotbanned commented Aug 3, 2024

What is your suggestion?

Related polars PR w/ @binste comment

Thought it would make sense to track in an issue here, not only in a polars PR.

If you haven't read though that thread, please check it first as there are many related issues/repos that have been linked.
Including pandas, pd_vega, altair_pandas

Example end-goal

Providing a limited API via a plot accessor, that shortens paths like below:

from datetime import date

from packaging.version import Version
import polars as pl
import altair as alt

df = pl.DataFrame(
        {
            "date": [date(2020, 1, 2), date(2020, 1, 3), date(2020, 1, 4)] * 2,
            "price": [1, 4, 6, 1, 5, 2],
            "stock": ["a", "a", "a", "b", "b", "b"]
        }
    )

if Version(pl.__version__) >= Version("1.5.0"): # Currently 1.4.0
    df.plot.line(x="date", y="price", color="stock")
else:
    alt.Chart(df).mark_line().encode(x="date", y="price", color="stock")

This should provide:

  • Access to common marks
  • Arguments passed to .encode()
  • Some level of typing on those parameters

@MarcoGorelli has already done some great work in the original PR, and the simplest approach would be exposing some types for them to import

As mentioned here and here an alt.Chart is returned - which can be used for further customisation using the full altair API.

dangotbanned added a commit to dangotbanned/altair that referenced this issue Aug 3, 2024
binste added a commit that referenced this issue Aug 8, 2024
* feat(typing): Create `altair.typing`

#3514

* chore: Add comment on `tooltip` annotation

Trying to trigger some places to add github comments - for actual threads

* feat(typing): Add reference impl `EncodeKwds` from comment

* feat(typing): Use `OneOrSeq[tps]` instead of `Union[*tps, list]` in `.encode()`

* build: run `generate-schema-wrapper`

* wip: generate `typed_dict_args`

* refactor: Simplify `tools`, remove redundant code

Pushing this mid-refactor of `_create_encode_signature`.
Currently 0 changes to generated code

* refactor: finish removing `altair_classes_prefix`

* feat: `_create_encode_signature()` -> `EncodingArtifacts`

Refactored, moved comments into docs, parameterised globals

* build: run `generate-schema-wrapper`

* feat(typing): Provide a public export for `_EncodeKwds`

* Add docstring to _EncodeKwds

* Rewrite EncodeArtifacts dataclass as a function

* Fix ruff issue due to old local ruff version

* Change generate_encoding_artifacts to an iterator

* docs: run `generate-schema-wrapper` with `indent_level=4`

I prefer the original, but this is to clarify #3515 (comment)

* feat(typing): Move `ChartType`, `is_chart_type` to `alt.typing`

These aren't introduced until `5.4.0`, so this is keeps the top-level from growing +2

#3515 (comment)

* revert(ruff): Restore original ('RUF001`) line

1eb466d

* Add type aliases for each channel

* Format

* Use Union instead of | for compatibility with Py <3.10

* Add channel type aliases to typing module. Add 'Type hints' section to API references in docs. Remove is_chart_type from 'API' docs section as it's now in typing. Rename '_EncodeKwds' to 'EncodeKwds'

* chore(ruff): Remove unused `F401` ignore

Would have only been needed before adding an `__all__`

* feat(typing): Move `Optional` export to `typing`

Updates all references, docs, `ruff` rule

* refactor: Move blank line append to `indent_docstring`

If this is needed for every call, it belongs in the function itself

* docs(typing): Remove empty type list from `EncodeKwds`

* refactor: Renaming, grouping, reducing repetition

* refactor: More tidying up, annotating, reformat

* docs: Reference aliases in `generate_encoding_artifacts`

* Use full type hints instead of type alias in signatures for typeddict and encode method

* Rename 'Type hints' to 'Typing'

* Ruff fix

---------

Co-authored-by: Stefan Binder <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant