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

refactor: reduce qualified names of Content, Form, Type subclasses #1757

Merged
merged 4 commits into from
Sep 29, 2022

Conversation

jpivarski
Copy link
Member

Specifically,

find src/awkward -type f -name '*.py' -exec sed -i.bak 's/ak.contents.[a-z]*array.\([A-Za-z]*Array\)/ak.contents.\1/g' {} \;
rm -f **/*.py.bak
black src/awkward
find src/awkward -type f -name '*.py' -exec sed -i.bak 's/ak.forms.[a-z]*form.\([A-Za-z]*Form\)/ak.forms.\1/g' {} \;
rm -f **/*.py.bak
black src/awkward

and

find src/awkward -type f -name '*.py' -exec sed -i.bak 's/ak.types.[a-z]*type.\([A-Za-z]*Type\)/ak.types.\1/g' {} \;
rm -f **/*.py.bak
black src/awkward

When pip-installed, ak.types doesn't seem to have listtype, etc., but it does have ListType. Wait—could it be because MacOS is case-sensitive? No, if that's it, then this would have failed before.

Regardless of whether this fixes the issue I see in using Uproot with Awkward's main, it's a name change we've been wanting to do.

@codecov
Copy link

codecov bot commented Sep 29, 2022

Codecov Report

Merging #1757 (91da25f) into main (084fa4b) will increase coverage by 0.53%.
The diff coverage is 56.48%.

❗ Current head 91da25f differs from pull request most recent head f437106. Consider uploading reports for the commit f437106 to get more accurate results

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/_connect/avro.py 87.17% <0.00%> (ø)
src/awkward/_connect/cuda/__init__.py 0.00% <0.00%> (ø)
src/awkward/_connect/numexpr.py 89.85% <0.00%> (ø)
src/awkward/_connect/rdataframe/from_rdataframe.py 0.00% <0.00%> (ø)
src/awkward/_connect/rdataframe/to_rdataframe.py 0.00% <0.00%> (ø)
src/awkward/behaviors/mixins.py 97.50% <0.00%> (ø)
src/awkward/operations/ak_from_cupy.py 50.00% <0.00%> (ø)
src/awkward/operations/ak_from_rdataframe.py 42.85% <0.00%> (ø)
src/awkward/operations/ak_to_cupy.py 33.33% <0.00%> (ø)
src/awkward/operations/ak_to_rdataframe.py 18.18% <0.00%> (ø)
... and 151 more

@jpivarski jpivarski marked this pull request as draft September 29, 2022 17:55
@agoose77
Copy link
Collaborator

This looks good to me. I've been earmarking this for a while.

When pip-installed, ak.types doesn't seem to have listtype, etc., but it does have ListType. Wait—could it be because MacOS is case-sensitive? No, if that's it, then this would have failed before.

Were you definitely getting v2 there? The fact that we have listtype in ak.types should follow from the import statements, so I would be very surprised if we had a platform-dependence there.

In any case, this PR looks good; I tested tests and tests-cuda, and scanned through the unified diff.

@agoose77
Copy link
Collaborator

@jpivarski what do you want to do w.r.t the tests? I think we can also change those too.

@jpivarski
Copy link
Member Author

I don't understand the reason why it was not finding the name. I verified the versions.

I got another error for not finding awkward.types.type.Type, something not covered above. At least it's solving the issue, despite not knowing why there was an issue.

@jpivarski
Copy link
Member Author

"Cleanup" type things are not very important in tests. We'll likely have to look at the main codebase frequently, making changes frequently, but a test should ideally just sit there, unchanged. Occasionally, they'll get changed, but it's a lot less than the main codebase.

@jpivarski jpivarski marked this pull request as ready for review September 29, 2022 18:31
@jpivarski
Copy link
Member Author

I'll be merging this as-is because we want to do the name change anyway. It got past some Uproot errors, but not all, and we shouldn't extend it to handle cases like

        elif not (
>           ak.forms.form._parameters_equal(
                self._parameters, other._parameters, only_array_record=True
            )
        ):
E       AttributeError: module 'awkward._v2.forms' has no attribute 'form'

I don't understand (1) why it doesn't see the submodule form in forms, because it's really in there, and (2) why it's naming the module awkward._v2.forms.

@jpivarski jpivarski merged commit 4cb5304 into main Sep 29, 2022
@jpivarski jpivarski deleted the jpivarski/reduce-qualified-names-of-Content-Form-Type branch September 29, 2022 18:55
@agoose77
Copy link
Collaborator

I'll just mirror my comment here for posterity;

The reason that our awkward.XXX modules are renamed to awkward._v2.XXX when importing from v2 is that Python's import machinery sets __package__ on the module object, even if it retrieves an existing module from sys.modules. Off the top of my head, I can't think of any way to prevent this, as all of this happens in C AFAICR. We could wrap the importer that Python creates, and implement logic to restore the __package__ and __name__ attributes, but this feels very heavy-handed for what is ultimately a cosmetic detail affecting only importers of v2 AFAICT.

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