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

patch: Improving typing of stable from_native when 'strict=False' #875

Merged

Conversation

luke396
Copy link
Member

@luke396 luke396 commented Aug 28, 2024

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

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

Related issues

Checklist

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

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

@EdAbati helps a lot in discord! Thanks again!

@luke396 luke396 changed the title patch: Improving typing of stable from_native when 'srict=False' patch: Improving typing of stable from_native when 'strict=False' Aug 28, 2024
@MarcoGorelli
Copy link
Member

thanks @luke396 ! do we need to make these changes in narwhals/translate.py too?

@luke396
Copy link
Member Author

luke396 commented Aug 28, 2024

thanks @luke396 ! do we need to make these changes in narwhals/translate.py too?

Thanks for the reminder! I will handle it and push it later.

Comment on lines 112 to 116
def test_from_native_strict_false_typing() -> None:
df = pl.DataFrame()
nw_v1.from_native(df, strict=False)
nw_v1.from_native(df, strict=False, eager_only=True)
nw_v1.from_native(df, strict=False, eager_or_interchange_only=True)
Copy link
Member

Choose a reason for hiding this comment

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

in tests/translate/from_native_test.py we're already doing import narwhals.stable.v1 as nw

how about, in tests/translate/from_native_test.py, to add a test which duplicates test_from_native_strict_false_typing but which uses unstable_nw instead of nw?

@luke396 luke396 requested a review from MarcoGorelli August 29, 2024 07:44
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

thanks @luke396 !

@MarcoGorelli MarcoGorelli merged commit ba56147 into narwhals-dev:main Aug 29, 2024
21 checks passed
@luke396 luke396 deleted the improve-typing-stable-from-native branch August 29, 2024 12:03
Comment on lines +204 to +212
def test_from_native_strict_false_typing() -> None:
df = pl.DataFrame()
nw.from_native(df, strict=False)
nw.from_native(df, strict=False, eager_only=True)
nw.from_native(df, strict=False, eager_or_interchange_only=True)

unstable_nw.from_native(df, strict=False)
unstable_nw.from_native(df, strict=False, eager_only=True)
unstable_nw.from_native(df, strict=False, eager_or_interchange_only=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

question out of curiosity: it's not super clear to me what we are testing here. wouldn't mypy be able to catch errors for typing? πŸ‘€

Copy link
Member

Choose a reason for hiding this comment

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

yeah it's just to check that mypy doesn't complain on these lines

Copy link
Member Author

Choose a reason for hiding this comment

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

In our previous codebase, there was no such combination of parameters present, neither in 'narwhals' nor in 'tests'.

Thus, I believe this is the reason why the typing issue is resolved now, rather than before.

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.

improve typing for from_native when strict=False
3 participants