Skip to content

Commit e6fb15b

Browse files
committed
adding pandas.api.typing.aliases and docs
1 parent 35b0d1d commit e6fb15b

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

doc/source/development/contributing_codebase.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ With custom types and inference this is not always possible so exceptions are ma
214214
pandas-specific types
215215
~~~~~~~~~~~~~~~~~~~~~
216216

217-
Commonly used types specific to pandas will appear in `pandas._typing <https://github.com/pandas-dev/pandas/blob/main/pandas/_typing.py>`_ and you should use these where applicable. This module is private for now but ultimately this should be exposed to third party libraries who want to implement type checking against pandas.
217+
Commonly used types specific to pandas will appear in `pandas._typing <https://github.com/pandas-dev/pandas/blob/main/pandas/_typing.py>`__ and you should use these where applicable. This module is private and is meant for pandas development.
218+
Types that are meant for user consumption should be exposed in `pandas.api.typing.aliases <https://github.com/pandas-dev/pandas/blob/main/pandas/api/typing/aliases.py>`__ and ideally added to the `pandas-stubs <https://github.com/pandas-dev/pandas-stubs>`__ project.
218219

219220
For example, quite a few functions in pandas accept a ``dtype`` argument. This can be expressed as a string like ``"object"``, a ``numpy.dtype`` like ``np.int64`` or even a pandas ``ExtensionDtype`` like ``pd.CategoricalDtype``. Rather than burden the user with having to constantly annotate all of those options, this can simply be imported and reused from the pandas._typing module
220221

doc/source/reference/aliases.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{{ header }}
2+
3+
.. _api.typing.aliases:
4+
5+
======================================
6+
pandas typing aliases
7+
======================================
8+
9+
**************
10+
Typing aliases
11+
**************
12+
13+
.. currentmodule:: pandas.api.atyping.aliases
14+
15+
The typing declarations in ``pandas/_typing.py`` are considered private, and used
16+
by pandasdevelopers for type checking of the pandascode base. For users, it is
17+
highly recommended to use the ``pandas-stubs`` package that represents the officially
18+
supported type declarations for users of pandas.
19+
Note that the definitions and use cases of these aliases are subject to change.
20+
They are documented here for users who wish to use these declarations in their
21+
own python code that calls pandasor expects certain results.
22+
23+
Each of these aliases listed in the table below can be found by importing them from :py:mod:`pandas.api.typing.aliases`.
24+
25+
==================================== ================================================================
26+
Alias Meaning
27+
==================================== ================================================================
28+
:py:type:`AggFuncType` Type of functions that can be passed to :meth:`agg` methods
29+
:py:type:`AlignJoin` Argument type for ``join`` in :meth:`DataFrame.join`
30+
:py:type:`AnyAll` Argument type for ``how`` in :meth:`dropna`
31+
:py:type:`AnyArrayLike` Used to represent :class:`ExtensionArray`, ``numpy`` arrays, :class:`Index` and :class:`Series`
32+
:py:type:`ArrayLike` Used to represent :class:`ExtensionArray`, ``numpy`` arrays
33+
:py:type:`AstypeArg` Argument type in :meth:`astype`
34+
:py:type:`Axes` :py:type:`AnyArrayLike` plus sequences (not strings) and ``range``
35+
:py:type:`Axis` Argument type for ``axis`` in many methods
36+
:py:type:`CSVEngine` Argument type for ``engine`` in :meth:`DataFrame.read_csv`
37+
:py:type:`ColspaceArgType` Argument type for ``colspace`` in :meth:`DataFrame.to_html`
38+
:py:type:`CompressionOptions` Argument type for ``compression`` in many I/O output methods
39+
:py:type:`CorrelationMethod` Argument type for ``correlation`` in :meth:`corr`
40+
:py:type:`DropKeep` Argument type for ``keep`` in :meth:`drop_duplicates`
41+
:py:type:`Dtype` Types as objects that can be used to specify dtypes
42+
:py:type:`DtypeArg` Argument type for ``dtype`` in various methods
43+
:py:type:`DtypeBackend` Argument type for ``dtype_backend`` in various methods
44+
:py:type:`DtypeObj` Numpy dtypes and Extension dtypes
45+
:py:type:`ExcelWriterIfSheetExists` Argument type for ``if_sheet_exists`` in :class:`ExcelWriter`
46+
:py:type:`ExcelWriterMergeCells` Argument type for ``merge_cells`` in :meth:`to_excel`
47+
:py:type:`FilePath` Type of paths for files for I/O methods
48+
:py:type:`FillnaOptions` Argument type for ``method`` in various methods where NA values are filled
49+
:py:type:`FloatFormatType` Argument type for ``float_format`` in :meth:`to_string`
50+
:py:type:`FormattersType` Argument type for ``formatters`` in :meth:`to_string`
51+
:py:type:`FromDictOrient` Argument type for ``orient`` in :meth:`DataFrame.from_dict`
52+
:py:type:`HTMLFlavors` Argument type for ``flavor`` in :meth:`pandas.read_html`
53+
:py:type:`IgnoreRaise` Argument type for ``errors`` in multiple methods
54+
:py:type:`IndexLabel` Argument type for ``level`` in multiple methods
55+
:py:type:`InterpolateOptions` Argument type for ``interpolate`` in :meth:`interpolate`
56+
:py:type:`JSONEngine` Argument type for ``engine`` in :meth:`read_json`
57+
:py:type:`JSONSerializable` Argument type for the return type of a callable for argument ``default_handler`` in :meth:`to_json`
58+
:py:type:`JoinHow` Argument type for ``how`` in :meth:`pandas.merge_ordered` and for ``join`` in :meth:`Series.align`
59+
:py:type:`JoinValidate` Argument type for ``validate`` in :meth:`DataFrame.join`
60+
:py:type:`MergeHow` Argument type for ``how`` in :meth:`merge`
61+
:py:type:`MergeValidate` Argument type for ``validate`` in :meth:`merge`
62+
:py:type:`NaPosition` Argument type for ``na_position`` in :meth:`sort_index` and :meth:`sort_values`
63+
:py:type:`NsmallestNlargestKeep` Argument type for ``keep`` in :meth:`nlargest` and :meth:`nsmallest`
64+
:py:type:`OpenFileErrors` Argument type for ``errors`` in :meth:`to_hdf` and :meth:`to_csv`
65+
:py:type:`Ordered` Return type for :py:attr:`ordered`` in :class:`CategoricalDtype` and :class:`Categorical`
66+
:py:type:`QuantileInterpolation` Argument type for ``interpolation`` in :meth:`quantile`
67+
:py:type:`ReadBuffer` Additional argument type corresponding to buffers for various file reading methods
68+
:py:type:`ReadCsvBuffer` Additional argument type corresponding to buffers for :meth:`pandas.read_csv`
69+
:py:type:`ReadPickleBuffer` Additional argument type corresponding to buffers for :meth:`pandas.read_pickle`
70+
:py:type:`ReindexMethod` Argument type for ``reindex`` in :meth:`reindex`
71+
:py:type:`Scalar` Basic type that can be stored in :class:`Series`
72+
:py:type:`SequenceNotStr` Used for arguments that require sequences, but not plain strings
73+
:py:type:`SortKind` Argument type for ``kind`` in :meth:`sort_index` and :meth:`sort_values`
74+
:py:type:`StorageOptions` Argument type for ``storage_options`` in various file output methods
75+
:py:type:`Suffixes` Argument type for ``suffixes`` in :meth:`merge`, :meth:`compare` and :meth:`merge_ordered`
76+
:py:type:`TakeIndexer` Argument type for ``indexer`` and ``indices`` in :meth:`take`
77+
:py:type:`TimeAmbiguous` Argument type for ``ambiguous`` in time operations
78+
:py:type:`TimeGrouperOrigin` Argument type for ``origin`` in :meth:`resample` and :class:`TimeGrouper`
79+
:py:type:`TimeNonexistent` Argument type for ``nonexistent`` in time operations
80+
:py:type:`TimeUnit` Time unit argument and return type for :py:attr:`unit`, arguments ``unit`` and ``date_unit``
81+
:py:type:`TimedeltaConvertibleTypes` Argument type for ``offset`` in :meth:`resample`, ``halflife`` in :meth:`ewm` and ``start`` and ``end`` in :meth:`pandas.timedelta_range`
82+
:py:type:`TimestampConvertibleTypes` Argument type for ``origin`` in :meth:`resample` and :meth:`pandas.to_datetime`
83+
:py:type:`ToStataByteorder` Argument type for ``byteorder`` in :meth:`DataFrame.to_stata`
84+
:py:type:`ToTimestampHow` Argument type for ``how`` in :meth:`to_timestamp` and ``convention`` in :meth:`resample`
85+
:py:type:`UpdateJoin` Argument type for ``join`` in :meth:`DataFrame.update`
86+
:py:type:`UsecolsArgType` Argument type for ``usecols`` in :meth:`pandas.read_clipboard`, :meth:`pandas.read_csv` and :meth:`pandas.read_excel`
87+
:py:type:`WindowingRankType` Argument type for ``method`` in :meth:`rank`` in rolling and expanding window operations
88+
:py:type:`WriteBuffer` Additional argument type corresponding to buffers for various file output methods
89+
:py:type:`WriteExcelBuffer` Additional argument type corresponding to buffers for :meth:`to_excel`
90+
:py:type:`XMLParsers` Argument type for ``parser`` in :meth:`DataFrame.to_xml` and :meth:`pandas.read_xml`
91+
==================================== ================================================================

doc/source/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ to be stable.
5555
extensions
5656
testing
5757
missing_value
58+
aliases
5859

5960
.. This is to prevent warnings in the doc build. We don't want to encourage
6061
.. these methods.

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Other enhancements
8383
- Add ``"delete_rows"`` option to ``if_exists`` argument in :meth:`DataFrame.to_sql` deleting all records of the table before inserting data (:issue:`37210`).
8484
- Added half-year offset classes :class:`HalfYearBegin`, :class:`HalfYearEnd`, :class:`BHalfYearBegin` and :class:`BHalfYearEnd` (:issue:`60928`)
8585
- 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`)
86+
- Certain aliases from :py:mode:`pandas._typing` are now exposed in :py:mod:`pandas.api.typing.aliases` (:issue:`55231`)
8687
- Errors occurring during SQL I/O will now throw a generic :class:`.DatabaseError` instead of the raw Exception type from the underlying driver manager library (:issue:`60748`)
8788
- Implemented :meth:`Series.str.isascii` and :meth:`Series.str.isascii` (:issue:`59091`)
8889
- Improved deprecation message for offset aliases (:issue:`60820`)

pandas/api/typing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pandas._libs.lib import NoDefault
77
from pandas._libs.missing import NAType
88

9+
from pandas.api.typing import aliases
910
from pandas.core.groupby import (
1011
DataFrameGroupBy,
1112
SeriesGroupBy,
@@ -56,4 +57,5 @@
5657
"TimeGrouper",
5758
"TimedeltaIndexResamplerGroupby",
5859
"Window",
60+
"aliases",
5961
]

pandas/api/typing/aliases.py

Whitespace-only changes.

0 commit comments

Comments
 (0)