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

Uses Collection in transformers.image_transforms.normalize #36301

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

CalOmnie
Copy link
Contributor

What does this PR do?

Followup to this PR
Which introduced a bug, preventing numpy arrays to be used as std and mean parameters.
This PR uses instead the Collection type, which correctly check for the prence of both __len__ and __getitem__ attributes but not __reversed__, succesfully accepting numpy arrays

This PR also updates one of the tests to pass in numpy arrays to confirm this new type does indeed function as intended.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@Rocketknight1
@tomasruizt

@Rocketknight1
Copy link
Member

Hi @CalOmnie, yes, this seems like a good typing update! There's one issue, though: typing.Collection is marked as a deprecated alias - can we use collections.abc.Collection instead?

@CalOmnie
Copy link
Contributor Author

Hey @Rocketknight1 fair enough, made the change.

Copy link
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yes, LGTM!

cc @ArthurZucker @Cyrilvallez for core maintainer review, and note this comment in the previous PR. isinstance(mean, Sequence) actually introduced a bug because np.ndarray is not a subclass of Sequence, so this is a bugfix and not just a type hint update!

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!! 🤗

@Cyrilvallez Cyrilvallez merged commit 547911e into huggingface:main Feb 21, 2025
21 checks passed
@tomasruizt
Copy link

Thanks for the quick fix @CalOmnie

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.

5 participants