-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: Make _libs.lib.no_default a singleton #40397
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
Comments
Exposing it sounds good to me. From the existing public namespaces, |
Another alternative would be to adopt |
Turns out it's already exposed, I just didn't look carefully enough: Line 2415 in 63bfdf5
So you can probably close this. |
@gjoseph92 "exposed" in this context does not include pandas._libs.lib. There is no guarantee that functions/objects in that file won't move between releases. |
I was referring to the comment on the line I linked: it is actually exposed in the public API as |
I think this would be beneficial to dask at least, since as a plain object, >>> import pandas as pd
>>> import pickle
>>> pickle.loads(pickle.dumps(pd.api.extensions.no_default)) is pd.api.extensions.no_default
False
>>> import numpy as np
>>> pickle.loads(pickle.dumps(np._NoValue)) is np._NoValue
True |
Thanks for finding that. Let's repurpose this issue for the pickle issue then. Since this is a singleton it should define pandas/pandas/_libs/missing.pyx Lines 443 to 444 in 0203f8d
|
giving it a type other than object would be helpful for mypy (which doesnt handle singletons nicely) |
Dask's approach of just using the string * as long as we checked |
For reference, numpy's implementation is here: https://github.com/numpy/numpy/blob/2832caab3bea702bdabe944ec21487bc93e94d59/numpy/_globals.py#L57-L91 and basically is
My preference would be to keep |
@jbrockmendel can you customize the repr of an Enum field? I don't know directly (maybe it's easy to do), but otherwise I am slightly -1 on using an enum for this. The repr now is "<NoDefault.no_default: 'NO_DEFAULT'>" (3x is a bit too much of "no default"). Would a custom class (as discussed above) not satisfy the needs of mypy? |
Yes. What would you like it to say? For the curious: I made this an enum bc it seemed like the dominant solution in this thread. |
A single time "<no_default>" instead of 3 times? |
Is this closable? |
did #40684 address the issue? I'll close this since it's on the 1.3 milestone. any subsequent changes should be a new issue |
See #40397 (comment)
This makes it easier for users and other libraries to inspect pandas' behavior without importing private modules (xref dask/dask#7375).
I'm not sure what public namespace is best.
The text was updated successfully, but these errors were encountered: