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

Ambigiuous column names in join_where require post-join names #18752

Open
2 tasks done
ion-elgreco opened this issue Sep 15, 2024 · 2 comments
Open
2 tasks done

Ambigiuous column names in join_where require post-join names #18752

ion-elgreco opened this issue Sep 15, 2024 · 2 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@ion-elgreco
Copy link
Contributor

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import datetime
import random
import polars as pl

def random_date(start, end):
    """Generate a random datetime between `start` and `end`"""
    return start + datetime.timedelta(
        # Get a random amount of seconds between `start` and `end`
        seconds=random.randint(0, int((end - start).total_seconds())),
    )

df = pl.DataFrame({
    "id":list(range(0,1000))*1500,
    "start_date": [random_date(datetime.datetime(2015,1,1), datetime.datetime(2020,1,1),) for i in range(1500000)]
}).with_columns(end_date = pl.col('start_date') + pl.duration(hours=random.randint(24,240)))

parts = df.sample(1700).select(
    'id',
    pl.concat_list(pl.col('start_date','end_date')).list.mean().alias('date').cast(pl.Datetime)
)

df.lazy().join_where(parts.lazy(), pl.col('id') == pl.col('id'),
    pl.col('start_date') <= pl.col('date'),
    pl.col('end_date') >= pl.col('date'))

Log output

No response

Issue description

This one tripped me for a sec, we need to refer within the col name to which side it is. Can't we have an expr for this?

Expected behavior

Just a thought but perhaps, pl.col('id').lhs() or pl.col('id').rhs()

Installed versions

--------Version info---------
Polars:              1.7.1
Index type:          UInt32
Platform:            Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.39
Python:              3.10.14 (main, Aug 14 2024, 05:11:29) [Clang 18.1.8 ]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            0.19.1
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         1.6.0
numpy                1.22.2
openpyxl             <not installed>
pandas               <not installed>
pyarrow              17.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@ion-elgreco ion-elgreco added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 15, 2024
@cmdlineluser
Copy link
Contributor

Ritchie did mention this on Discord:

We could add a pl.col_left,pl.col_right ... 🤔

@AlexeyDmitriev
Copy link

AlexeyDmitriev commented Sep 15, 2024

Note, semantics were changed here: #18640 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

3 participants