Skip to content

API: Update lib.histograms namespace #24513

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

Merged
merged 1 commit into from
Aug 24, 2023

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Aug 23, 2023

Relevant issue #24507

Hi @rgommers @ngoldbaum,

This is the first PR within "lib namespace cleanup" milestone. This PR moves lib.histograms module to a private file and ensures that its public methods are only available through the main namespace (e.g. np.histogram()). There are no additional functions that only live in np.lib.histograms, so I don't expect any influence on other libraries (although I will check it).

Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

This looks good to me. Github search finds a few existing usages of private things with leading-underscore names or things are already public in numpy, so I think this is good to do without any deprecations.

@rgommers rgommers added this to the 2.0.0 release milestone Aug 24, 2023
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

LGTM too. Just one question: the _impl suffix to the filename was suggested by @ngoldbaum for names where we'd otherwise have both a public and a private file (e.g. stride_tricks.py and _stride_tricks.py). In this case though, there's only a single private name. Wouldn't a regular _histograms.py look better here? (I'm not sure, it really is a question - naming is hard)

@mtsokol
Copy link
Member Author

mtsokol commented Aug 24, 2023

LGTM too. Just one question: the _impl suffix to the filename was suggested by @ngoldbaum for names where we'd otherwise have both a public and a private file (e.g. stride_tricks.py and _stride_tricks.py). In this case though, there's only a single private name. Wouldn't a regular _histograms.py look better here? (I'm not sure, it really is a question - naming is hard)

@rgommers I would argue that keeping all implementations in _<submodule>_impl.py would be more consistent. I think mixing names depending on the fact of exporting to top or/and local namespace could be a bit confusing.

# Let's assume "stuff" submodule exists

numpy/__init__.py  # imports top namespace items

# 1. variant - only top namespace items
numpy/lib/_stuff_impl.py  # hosts implementation, no doubt
or .../_stuff.py  #  alternative name in this case

# 2. variant - top namespace and local items
numpy/lib/_stuff_impl.py  # hosts implementation
numpy/lib/stuff.py  # defines local namespace, imports from impl

@rgommers
Copy link
Member

Okay, fair enough, that's a good argument. I'm happy to go with this. Nathan also approved, so let's roll with this. It's the kind of thing we can easily revisit and make consistent later if we change our minds.

In it goes, thanks again!

@rgommers rgommers merged commit 89a6f3e into numpy:main Aug 24, 2023
@mtsokol mtsokol deleted the lib-histograms-namespace branch August 24, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants