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

fix: EmptyArray.is_numpy should be False. #1971

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

jpivarski
Copy link
Member

@jpivarski jpivarski commented Dec 7, 2022

EmptyArray.is_numpy is now False because it's surprising. (EmptyArrays are sometimes coerced to being NumpyArrays with dtype=np.float64 to match the NumPy behavior, but in general, EmptyArray represents an unknown type, not a NumPy-like type.)

There's already EmptyArray.is_unknown to identify them, and everywhere that we actually cared about it, we were already checking for it:

% fgrep -r '.is_numpy' --include \*.py src/awkward
src/awkward/contents/listarray.py:            if not content.is_numpy or not content.parameter("__array__") == "char":
src/awkward/contents/listarray.py:            if not content.is_numpy or not content.parameter("__array__") == "byte":
src/awkward/contents/listoffsetarray.py:            if not content.is_numpy or not content.parameter("__array__") == "char":
src/awkward/contents/listoffsetarray.py:            if not content.is_numpy or not content.parameter("__array__") == "byte":
src/awkward/contents/regulararray.py:            if not content.is_numpy or not content.parameter("__array__") == "char":
src/awkward/contents/regulararray.py:            if not content.is_numpy or not content.parameter("__array__") == "byte":
src/awkward/operations/ak_unflatten.py:        elif counts.is_numpy or counts.is_unknown:
src/awkward/operations/ak_is_none.py:        elif layout.is_numpy or layout.is_unknown or layout.is_list or layout.is_record:
src/awkward/operations/ak_transform.py:        ...     if layout.is_numpy:
src/awkward/operations/ak_transform.py:        ...     if layouts[0].is_numpy and layouts[1].is_numpy:

The first section really wants only NumpyArray because it's checking for arrays of char or byte, which EmptyArray is not. The last two, in ak_transform.py, are examples in docstrings. Everything else already checks for is_numpy or is_unknown.

Demonstrably, it does not affect any tests.


📚 The documentation for this PR will be available at https://awkward-array.readthedocs.io/en/jpivarski-emptyarray.is_numpy-should-be-false/ once Read the Docs has finished building 🔨

@jpivarski jpivarski requested a review from agoose77 December 7, 2022 19:03
@jpivarski jpivarski self-assigned this Dec 7, 2022
@jpivarski jpivarski added the pr-next-release Required for the next release label Dec 7, 2022
@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Merging #1971 (b05cf7a) into main (e5836e9) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/contents/emptyarray.py 72.43% <ø> (-0.15%) ⬇️
src/awkward/operations/ak_is_none.py 96.55% <100.00%> (ø)

@jpivarski jpivarski merged commit f85bfdf into main Dec 7, 2022
@jpivarski jpivarski deleted the jpivarski/EmptyArray.is_numpy-should-be-False branch December 7, 2022 22:59
@jpivarski jpivarski removed the pr-next-release Required for the next release label Feb 15, 2023
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.

2 participants