-
Notifications
You must be signed in to change notification settings - Fork 89
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: rename util functions #2316
Conversation
Improves free-symbol usage
refactor: move regularisation routines to `_regularize`
@jpivarski to review this, I would benefit from the following considerations:
Footnotes
|
@henryiii could I get a second opinion on the use of Are there any significant downsides to this? Ruff and other linters already can't see |
@jpivarski with this PR, I'm introducing a new rule:
Under this rule, I plan to move the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To summarize, the biggest thing that happened here is that _util.py has exploded into new, well-named, hidden modules, and functions that are only used in one module are defined in that module.
That's great!
I'm also happy that _util.py still exists. When we need to add a new helper function quickly (and know that it's not used in only one module), we'll need to find a place to put it and it's likely that it won't quite fit one of these names. _util.py can be a staging area for new helper functions, which may find another home later. Very general functions that are needed in ~all modules should continue to live in _util.py, because it's at one of the roots of the dependency DAG.
- are you happy with the new filenames?
Yes, they're very clear.
- are you OK with the move towards imports?
Yes, for any L3/L4, we can do that. It will make the dependencies between modules more clear.
- would you prefer any additional organisational structure?
- Right now, I've added a flat hierarchy of files. We could nest them if needed.
Flatness is usually easier to deal with when searching for a particular file. It only gets to be a problem when the list is very long.
- Are you OK with the fact that L2 operations modules contain some L3 symbols in the global namespace? Users can only see these if they do evaluate e.g. ak.operations.ak_fill_none.cpu
, i.e. not from
ak.cpuor
ak.operations.cpu`. If you're against this (which already happens), we could hide these inside the function definitions.
It would be better to hide them, but maybe we should do so by hiding the operations module instead:
src/awkward/__init__.py
src/awkward/_operations/
src/awkward/_operations/ak_fill_none.py
and then the __init__.py
does
from awkward._operations.ak_fill_none import *
with
__all__ = ("fill_none",)
in ak_fill_none.py.
This can be behind a deprecation cycle by adding
src/awkward/operations/
src/awkward/operations/__init__.py
that does
warn(deprecation_warning("this breaks in 2.3!"))
from awkward._operations import *
Then (unless someone uses hidden modules), there would be one place to get a function like ak.fill_none
from—no ambiguity. Some tests don't respect that rule because they were written early, but that would be easy to find-and-replace.
I like this idea.
Agreed!! |
Codecov Report
Additional details and impacted files
|
My long-term plan (as discussed with Jim) is to move towards free symbols for function usage over
ak._
imports.The benefits of this are:
The concrete motivations for this PR are that
ak._util
couples a lot of modules right now, making refactoring more fiddly than it needs to be.Although the L1/L2 APIs will remain "REPL-friendly" (don't require many imports), the L3 API can be import-only. Gradually we are moving towards this approach, with this PR making a big jump. Eventually I'd like all of awkward to use imports internally.
I've also renamed functions to better reflect their purpose.