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

Improve object handling & testing of ensure_unicode #9059

Merged
merged 8 commits into from May 11, 2022

Conversation

jakirkham
Copy link
Member

@jakirkham jakirkham commented May 9, 2022

Make sure that ensure_unicode (like ensure_bytes) can handle any Python Buffer Protocol object (like bytearray and memoryview objects). Also include various tests to ensure different objects can be decoded to str.

xref: #9050

  • Closes #xxxx
  • Tests added / passed
  • Passes pre-commit run --all-files

Any other arbitrary object (like `bytearray` or `memoryview` based
objects) can be decoded to `unicode` via `codecs.decode`. This is
analogous to what is done in `ensure_bytes`. So handle this case here.
If this also fails, then raise as usual.
@jakirkham jakirkham changed the title Improve object handling & testing in ensure_unicode Improve object handling & testing of ensure_unicode May 9, 2022
@jakirkham jakirkham added needs review Needs review from a contributor. hygiene Improve code quality and reduce maintenance overhead labels May 9, 2022
@jakirkham
Copy link
Member Author

jakirkham commented May 10, 2022

Test failures are due to issue ( #9060 ). So unrelated to these changes

Edit: Restarting CI now that PR ( #8993 ) is merged, which should fix those failures.

Edit 2: Restarting showed the same failures. Trying merging with main. This fixed it.

@jakirkham
Copy link
Member Author

cc @jrbourbeau

@jakirkham
Copy link
Member Author

CI now passes! 🎉

Please let me know if anything else is needed here 🙂

Copy link
Member

@jrbourbeau jrbourbeau left a comment

Choose a reason for hiding this comment

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

Thanks @jakirkham! I'm curious, did you run into a use case where this was needed?

dask/tests/test_utils.py Outdated Show resolved Hide resolved
dask/utils.py Show resolved Hide resolved
@jakirkham
Copy link
Member Author

I'm curious, did you run into a use case where this was needed?

Was updating ensure_bytes in PR ( #9050 ) and noticed that similar improvements could be made here as were there

@jakirkham jakirkham requested a review from jrbourbeau May 10, 2022 22:40
This is more consistent with the other tests, which also use this type.
Though `int8` also works.
Appears this already gets interpreted correctly by `array`. Should also
make the code easier to read for other maintainers.
Avoids the `array.array` bit which is a tad verbose.
@jcrist jcrist merged commit 5f74a6c into dask:main May 11, 2022
@jakirkham jakirkham deleted the ens_uni_pb branch May 11, 2022 16:42
@jakirkham
Copy link
Member Author

Thanks all! 🙏

erayaslan pushed a commit to erayaslan/dask that referenced this pull request May 12, 2022
* Use `elif` for `decode` in `ensure_unicode`

* Handle Python Buffer Protocol in `ensure_unicode`

Any other arbitrary object (like `bytearray` or `memoryview` based
objects) can be decoded to `unicode` via `codecs.decode`. This is
analogous to what is done in `ensure_bytes`. So handle this case here.
If this also fails, then raise as usual.

* Include `ensure_unicode` tests for various objects

* Clarify error messages

* Use `uint8` in `array` tests

This is more consistent with the other tests, which also use this type.
Though `int8` also works.

* Pass `bytes` directly to `array`

Appears this already gets interpreted correctly by `array`. Should also
make the code easier to read for other maintainers.

* Use `from array import array`

Avoids the `array.array` bit which is a tad verbose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hygiene Improve code quality and reduce maintenance overhead needs review Needs review from a contributor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants