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: Support a wider range of iterables in SchemaBase.to_dict #3501

Merged
merged 27 commits into from
Aug 9, 2024

Conversation

dangotbanned
Copy link
Member

@dangotbanned dangotbanned commented Jul 24, 2024

Fixes: #2808 and #2877

Supersedes #3237

CI Failures

See #3501 (comment)

Notes

Huge thanks to @MarcoGorelli as narwhals made this feature super simple to implement.

In addition to handling Sequence like types, an Iterator can safely be passed to narwhals.from_native without being consumed.

Code block
import narwhals.stable.v1 as nw

elements = [1,2,3]
it = iter(elements)
some_obj = nw.from_native(it,strict=False)

>>> list(it) == elements
True

#2808 Cases

Large screenshots

image
image

#2877 Case

Large screenshot

image

Tasks

  • Update User Guide

@dangotbanned dangotbanned marked this pull request as ready for review July 24, 2024 18:08
Copy link
Contributor

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

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

Looking great overall @dangotbanned , thank you again! A few comments / questions.

tools/schemapi/schemapi.py Show resolved Hide resolved
altair/utils/schemapi.py Show resolved Hide resolved
altair/utils/schemapi.py Show resolved Hide resolved
tests/utils/test_schemapi.py Outdated Show resolved Hide resolved
tests/utils/test_schemapi.py Show resolved Hide resolved
@dangotbanned
Copy link
Member Author

Looking great overall @dangotbanned , thank you again! A few comments / questions.

Thanks for taking the time to review @joelostblom

Will wait for your response before making any changes

@joelostblom
Copy link
Contributor

Thanks for responding to the comment @dangotbanned ! At a cursory glance it all looks good but I will review more in detail and try it out when I'm back from vacation in about a week

Copy link
Contributor

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

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

Looking great! I found a day to review this more in depth and left a few comments. I should be able to take another look in ~4 days.

altair/utils/schemapi.py Show resolved Hide resolved
tests/utils/test_schemapi.py Outdated Show resolved Hide resolved
tests/utils/test_schemapi.py Show resolved Hide resolved
tools/schemapi/schemapi.py Show resolved Hide resolved
@joelostblom
Copy link
Contributor

As part of this PR, could you also update the docs here https://altair-viz.github.io/user_guide/encodings/index.html#sort-option to not only mention that lists can be passed but any ordered sequence would work?

The original test obscured the fact that this change applies anywhere a `Sequence` is annotated.
@dangotbanned
Copy link
Member Author

dangotbanned commented Aug 5, 2024

Looking great! I found a day to review this more in depth and left a few comments. I should be able to take another look in ~4 days.

Thanks for the second look @joelostblom

I'm going to work through your comments after this, but thought I'd give a heads-up on #3501 (commits)

After reading your comments this morning, I got the feeling that the focus on ordering/sets had overlooked the much broader scope of this change.

I think this was my mistake by writing tests that only covered alt.X(sort=).
I've updated these to show that this applies anywhere that previously could only accept a (list|tuple) - provided the value type matches the schema.

Great point, maybe we should strictly adhere to passing only ordered sequences/arrays and disallow passing unordered sets?

The ordering requirement makes a lot of sense for sort, but wouldn't be applicable in every case - especially when someone may be using a set to get unique values.

@dangotbanned
Copy link
Member Author

dangotbanned commented Aug 5, 2024

As part of this PR, could you also update the docs here altair-viz.github.io/user_guide/encodings/index.html#sort-option to not only mention that lists can be passed but any ordered sequence would work?

Yeah that sounds like a good idea, thanks @joelostblom I will work on that for the next commit

Copy link
Contributor

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

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

Thanks again for this contribution and your patience with the review process @dangotbanned. I only have a few minor comments/clarifications left and then we should be ready to merge.

doc/user_guide/encodings/index.rst Outdated Show resolved Hide resolved
tests/utils/test_schemapi.py Outdated Show resolved Hide resolved
tests/utils/test_schemapi.py Show resolved Hide resolved
tests/utils/test_schemapi.py Show resolved Hide resolved
tests/utils/test_schemapi.py Outdated Show resolved Hide resolved
tests/utils/test_schemapi.py Show resolved Hide resolved
Copy link
Contributor

@joelostblom joelostblom left a comment

Choose a reason for hiding this comment

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

Super, thanks for the quick turn around! I'm excited to merge this PR and no longer have to convert series etc to lists explicitly =) Thanks again!

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

Successfully merging this pull request may close these issues.

Allow passing pandas indexes in addition to lists and arrays
3 participants