TYP: use __all__ to signal public API to type checkers#43695
TYP: use __all__ to signal public API to type checkers#43695jreback merged 10 commits intopandas-dev:masterfrom twoertwein:import
Conversation
No, but once we add a py.typed file we could use pyright to make sure that a list of intended to be public functions/attributes are picked up as public by type checkers. |
| import pandas.testing | ||
| import pandas.arrays | ||
| from pandas import testing | ||
| from pandas import arrays |
There was a problem hiding this comment.
Is there a reason why api, testing, and arrays was not imported with "from pandas import"? I changed it to from pandas import to include them in __all__.
There was a problem hiding this comment.
these should be equivalent (ex the name space visiblity).
note that we may not be fully testing this (see in pandas/tests/api/test_api.py)
There was a problem hiding this comment.
I added a test for __all__ and found in that process a few un-exported modules.
| assert not extraneous | ||
|
|
||
| missing = expected - actual | ||
| assert not missing |
There was a problem hiding this comment.
assert actual == expected would work, but it doesn't create a nice log in pytest.
|
I think the modules I added in the last commit are not meant to be public (compat, core, io, ...)? @simonjayhawkins If the above modules are not meant to be public, there probably needs to be a discussion which additional classes should be exported in def mean(grouper: pd.core.groupby.DataFrameGroupBy) -> pd.DataFrame:
return group.mean()without using "private" APIs (pd.core.groupby.DataFrameGroupBy). |
|
none of those are documented as public we have an issue about deprecating and making these private but hasn't gotten done don't add them explicitly to any exports |
|
some of these apis should be exported in pd.api as well (eg DataframeGroupby for example) |
|
So the only public "top-level sub-packages" are: "api", "arrays", "options", "test", "testing"? They are all imported in |
|
Reading through the documentation, the following should be listed as public in |
|
I was trying to expose only meant-to-be-public sub-modules (public = listed in the documentation) in Here is an example how I would # import modules that have public classes/functions
from pandas.io import (
formats,
json,
stata,
)
# and mark only those modules as public
__all__ = ["formats", "json", "stata"]I think many people assume that everything that doesn't start with an underscore is public. |
|
can you rebase |
…all__ (everything else is technically private)
|
https://github.com/pandas-dev/pandas/pull/43695/checks?check_run_id=3734385197 hmm maybe need to be more explict in the docs |
I think there are two options:
Which one is preferred? |
|
i don't think we should add the deprecated modules to all |
|
thanks @twoertwein very nice! |
Uh oh!
There was an error while loading. Please reload this page.