Skip to content

adding pandas.api.typing.aliases and docs #61735

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Dr-Irv
Copy link
Contributor

@Dr-Irv Dr-Irv commented Jun 29, 2025

This is my first proposal for adding the typing aliases that are "public" so that people do not import from pandas._typing.

@Dr-Irv Dr-Irv requested a review from rhshadrach June 29, 2025 03:38
@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Jun 30, 2025
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

If we are to make these public, what is the process of making changes to them?

.. currentmodule:: pandas.api.atyping.aliases

The typing declarations in ``pandas/_typing.py`` are considered private, and used
by pandasdevelopers for type checking of the pandascode base. For users, it is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
by pandasdevelopers for type checking of the pandascode base. For users, it is
by pandas developers for type checking of the pandas code base. For users, it is

This also occurs more times below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in next commit

@@ -83,6 +83,7 @@ Other enhancements
- Add ``"delete_rows"`` option to ``if_exists`` argument in :meth:`DataFrame.to_sql` deleting all records of the table before inserting data (:issue:`37210`).
- Added half-year offset classes :class:`HalfYearBegin`, :class:`HalfYearEnd`, :class:`BHalfYearBegin` and :class:`BHalfYearEnd` (:issue:`60928`)
- Added support to read and write from and to Apache Iceberg tables with the new :func:`read_iceberg` and :meth:`DataFrame.to_iceberg` functions (:issue:`61383`)
- Certain aliases from :py:mod:`pandas._typing` are now exposed in :py:mod:`pandas.api.typing.aliases` (:issue:`55231`)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest not advertising where they come from.

Suggested change
- Certain aliases from :py:mod:`pandas._typing` are now exposed in :py:mod:`pandas.api.typing.aliases` (:issue:`55231`)
- Many type aliases are now exposed in the new submodule :py:mod:`pandas.api.typing.aliases` (:issue:`55231`)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in next commit

Axes,
Axis,
ColspaceArgType,
CompressionOptions,
Copy link
Member

Choose a reason for hiding this comment

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

There are many type aliases here where it is not clear what method(s) they are appropriate for. E.g. it would be wrong to use this for DataFrame.to_parquet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to cover that in the docs, without getting too specific. I can make the docs more specific, although there are cases where the aliases are used in lots of methods, so the list can get quite long. E.g., for CompressionOptions, I said "Argument type for compression in many I/O output methods" .

Open to suggestions as to how to better document this.

@Dr-Irv
Copy link
Contributor Author

Dr-Irv commented Jul 1, 2025

If we are to make these public, what is the process of making changes to them?

My suggestion would be that if someone adds an alias to pandas._typing.py that is used as an argument or return type of a documented pandas method, then they should update the pandas/api/typing/aliases.py file and doc/source/reference/aliases.rst . Should I add something to the contributors guide about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Export (a subset of?) pandas._typing for type checking
3 participants