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

chore: parse strings as columns names at narwhals-level #1856

Merged
merged 28 commits into from
Jan 24, 2025

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Jan 23, 2025

closes #1390 (completely by accident 😳 πŸ˜„ )

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

  • Related issue #<issue number>
  • Closes #<issue number>

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

@MarcoGorelli MarcoGorelli changed the title Str as name earlier chore: parse strings as columns names at narwhals-level Jan 23, 2025
@MarcoGorelli MarcoGorelli marked this pull request as ready for review January 23, 2025 17:30
Copy link
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

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

Thanks @MarcoGorelli that's quite a refactor!

Not a real concern but maybe something to think about is:

  • The asymmetry in some method specs, between Narwhals and Compliant objects
  • The expected simple_select method (just needs documentation I guess)
  • Are we adding any extra overhead?

)
except Exception as e:
# Column not found is the only thing that can realistically be raised here.
available_columns = self.columns
Copy link
Member

Choose a reason for hiding this comment

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

Is calling .columns ok for the lazy case? doesn't polars raise a warning?

Copy link
Member Author

Choose a reason for hiding this comment

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

true, but it's crashing at this point anyway, might as well let it warn

narwhals/_interchange/dataframe.py Show resolved Hide resolved
narwhals/group_by.py Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Interesting change here, I am gladly surprised that everything plays out!

@MarcoGorelli
Copy link
Member Author

thanks for your review!

The asymmetry in some method specs, between Narwhals and Compliant objects. The expected simple_select method (just needs documentation I guess)

It's true that there's some asymmetry, but I think that's OK - in my head, the separation is:

  • compliant level: strict and minimal
  • narwhals (user-facing) level: more ergonomic

Are we adding any extra overhead?

From tests I've done locally it doesn't look like it. Theoretically i'd expect it to be slightly lower, if we're just doing a single isinstance(expr, str) check upfront as opposed to repeatedly when parsing expressions at the compliant level

Copy link
Member

@FBruzzesi FBruzzesi left a comment

Choose a reason for hiding this comment

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

Amazing stuff (as usual!)πŸš€

PartyDancingGIF

@MarcoGorelli
Copy link
Member Author

πŸ˜„ thanks for your review, much appreciated!

@MarcoGorelli MarcoGorelli merged commit aa8a501 into narwhals-dev:main Jan 24, 2025
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

df.select(0) treats 0 as literal for Polars, and raises for other backends
2 participants