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

feat: prql namespace for polars.DataFrame and polars.LazyFrame #373

Merged
merged 7 commits into from
Apr 29, 2024

Conversation

eitsupi
Copy link
Member

@eitsupi eitsupi commented Apr 29, 2024

Close #371

import polars as pl
from datetime import date
from pyprql import polars_namespace

df = pl.DataFrame({
    "a": [1, 2, 3],
    "b": ["zz", "yy", "xx"],
    "c": [date(1999, 12, 31), date(2010, 10, 10), date(2077, 8, 8)],
})

df.prql.query("select {a, b, c_year = s'EXTRACT(year FROM c)'} | filter a > 1")
# shape: (2, 3)
# ┌─────┬─────┬────────┐
# │ a   ┆ b   ┆ c_year │
# │ --- ┆ --- ┆ ---    │
# │ i64 ┆ str ┆ i32    │
# ╞═════╪═════╪════════╡
# │ 2   ┆ yy  ┆ 2010   │
# │ 3   ┆ xx  ┆ 2077   │
# └─────┴─────┴────────┘

@eitsupi eitsupi requested a review from max-sixty April 29, 2024 02:46
@eitsupi eitsupi changed the title feat: prql sub name space for polars.DataFrame and polars.LazyFrame feat: prql sub namespace for polars.DataFrame and polars.LazyFrame Apr 29, 2024
@eitsupi eitsupi changed the title feat: prql sub namespace for polars.DataFrame and polars.LazyFrame feat: prql namespace for polars.DataFrame and polars.LazyFrame Apr 29, 2024
Copy link
Member

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

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

Looks cool!

No objection to starting this as an optional dependency. We can then promote it if it turns out to be used lots. (I had a bit more objection in #374 to making everything optional).

Another option is to detect whether polars is installed in pyprql.__init__ and add the namespace without having to import pyprql.polars_namespace — depends on the polars norms.

@eitsupi eitsupi marked this pull request as ready for review April 29, 2024 04:25
@eitsupi
Copy link
Member Author

eitsupi commented Apr 29, 2024

Another option is to detect whether polars is installed in pyprql.__init__ and add the namespace without having to import pyprql.polars_namespace — depends on the polars norms.

That seems like a good idea, but I don't know if it is good practice to do that here.
For now, I would like to merge and release it as is.

@eitsupi eitsupi merged commit 86a908e into PRQL:main Apr 29, 2024
7 checks passed
@eitsupi eitsupi deleted the polars-sub-ns branch April 29, 2024 04:35
@max-sixty
Copy link
Member

For now, I would like to merge and release it as is.

For sure

That seems like a good idea, but I don't know if it is good practice to do that here.

It would be something like this in the __init__.py:

try:
    import polars
except ImportError:
    pass
else:
    # Add to namespace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prql namespace for polars.DataFrame and polars.LazyFrame
2 participants