Skip to content

Commit 3a3f2a2

Browse files
author
Kei
committed
Merge branch 'main' into fix/group_by_agg_pyarrow_bool_numpy_same_type
2 parents bb6343b + 4afc277 commit 3a3f2a2

File tree

11 files changed

+96
-27
lines changed

11 files changed

+96
-27
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ repos:
108108
types: [python]
109109
stages: [manual]
110110
additional_dependencies: &pyright_dependencies
111-
111+
112112
- id: pyright
113113
# note: assumes python env is setup and activated
114114
name: pyright reportGeneralTypeIssues

ci/code_checks.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9999
-i "pandas.DataFrame.reorder_levels SA01" \
100100
-i "pandas.DataFrame.sem PR01,RT03,SA01" \
101101
-i "pandas.DataFrame.skew RT03,SA01" \
102-
-i "pandas.DataFrame.sparse PR01,SA01" \
103-
-i "pandas.DataFrame.sparse.density SA01" \
104-
-i "pandas.DataFrame.sparse.from_spmatrix SA01" \
105-
-i "pandas.DataFrame.sparse.to_coo SA01" \
106-
-i "pandas.DataFrame.sparse.to_dense SA01" \
102+
-i "pandas.DataFrame.sparse PR01" \
107103
-i "pandas.DataFrame.std PR01,RT03,SA01" \
108104
-i "pandas.DataFrame.sum RT03" \
109105
-i "pandas.DataFrame.swaplevel SA01" \
@@ -138,8 +134,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
138134
-i "pandas.DatetimeTZDtype.tz SA01" \
139135
-i "pandas.DatetimeTZDtype.unit SA01" \
140136
-i "pandas.Grouper PR02" \
141-
-i "pandas.HDFStore.append PR01,SA01" \
142-
-i "pandas.HDFStore.get SA01" \
143137
-i "pandas.HDFStore.groups SA01" \
144138
-i "pandas.HDFStore.info RT03,SA01" \
145139
-i "pandas.HDFStore.keys SA01" \
@@ -178,13 +172,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
178172
-i "pandas.Index.name SA01" \
179173
-i "pandas.Index.names GL08" \
180174
-i "pandas.Index.nbytes SA01" \
181-
-i "pandas.Index.ndim SA01" \
182175
-i "pandas.Index.nunique RT03" \
183176
-i "pandas.Index.putmask PR01,RT03" \
184177
-i "pandas.Index.ravel PR01,RT03" \
185178
-i "pandas.Index.reindex PR07" \
186-
-i "pandas.Index.shape SA01" \
187-
-i "pandas.Index.size SA01" \
188179
-i "pandas.Index.slice_indexer PR07,RT03,SA01" \
189180
-i "pandas.Index.slice_locs RT03" \
190181
-i "pandas.Index.str PR01,SA01" \
@@ -361,7 +352,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
361352
-i "pandas.Series.mode SA01" \
362353
-i "pandas.Series.mul PR07" \
363354
-i "pandas.Series.nbytes SA01" \
364-
-i "pandas.Series.ndim SA01" \
365355
-i "pandas.Series.ne PR07,SA01" \
366356
-i "pandas.Series.nunique RT03" \
367357
-i "pandas.Series.pad PR01,SA01" \
@@ -381,7 +371,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
381371
-i "pandas.Series.rtruediv PR07" \
382372
-i "pandas.Series.sem PR01,RT03,SA01" \
383373
-i "pandas.Series.shape SA01" \
384-
-i "pandas.Series.size SA01" \
385374
-i "pandas.Series.skew RT03,SA01" \
386375
-i "pandas.Series.sparse PR01,SA01" \
387376
-i "pandas.Series.sparse.density SA01" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ Optional libraries below the lowest tested version may still work, but are not c
142142
+------------------------+---------------------+
143143
| adbc-driver-postgresql | 0.10.0 |
144144
+------------------------+---------------------+
145+
| mypy (dev) | 1.9.0 |
146+
+------------------------+---------------------+
145147

146148
See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for more.
147149

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dependencies:
7777

7878
# code checks
7979
- flake8=6.1.0 # run in subprocess over docstring examples
80-
- mypy=1.8.0 # pre-commit uses locally installed mypy
80+
- mypy=1.9.0 # pre-commit uses locally installed mypy
8181
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
8282
- pre-commit>=3.6.0
8383

pandas/_typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def __reversed__(self) -> Iterator[_T_co]: ...
239239
# see https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
240240
FuncType = Callable[..., Any]
241241
F = TypeVar("F", bound=FuncType)
242+
TypeT = TypeVar("TypeT", bound=type)
242243

243244
# types of vectorized key functions for DataFrame::sort_values and
244245
# DataFrame::sort_index, among others

pandas/core/accessor.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import annotations
99

1010
from typing import (
11+
TYPE_CHECKING,
1112
Callable,
1213
final,
1314
)
@@ -16,6 +17,12 @@
1617
from pandas.util._decorators import doc
1718
from pandas.util._exceptions import find_stack_level
1819

20+
if TYPE_CHECKING:
21+
from pandas._typing import TypeT
22+
23+
from pandas import Index
24+
from pandas.core.generic import NDFrame
25+
1926

2027
class DirNamesMixin:
2128
_accessors: set[str] = set()
@@ -232,7 +239,9 @@ def __get__(self, obj, cls):
232239

233240

234241
@doc(klass="", examples="", others="")
235-
def _register_accessor(name: str, cls):
242+
def _register_accessor(
243+
name: str, cls: type[NDFrame | Index]
244+
) -> Callable[[TypeT], TypeT]:
236245
"""
237246
Register a custom accessor on {klass} objects.
238247
@@ -277,7 +286,7 @@ def _register_accessor(name: str, cls):
277286
{examples}
278287
"""
279288

280-
def decorator(accessor):
289+
def decorator(accessor: TypeT) -> TypeT:
281290
if hasattr(cls, name):
282291
warnings.warn(
283292
f"registration of accessor {accessor!r} under name "
@@ -320,7 +329,7 @@ def decorator(accessor):
320329

321330

322331
@doc(_register_accessor, klass="DataFrame", examples=_register_df_examples)
323-
def register_dataframe_accessor(name: str):
332+
def register_dataframe_accessor(name: str) -> Callable[[TypeT], TypeT]:
324333
from pandas import DataFrame
325334

326335
return _register_accessor(name, DataFrame)
@@ -351,7 +360,7 @@ def register_dataframe_accessor(name: str):
351360

352361

353362
@doc(_register_accessor, klass="Series", examples=_register_series_examples)
354-
def register_series_accessor(name: str):
363+
def register_series_accessor(name: str) -> Callable[[TypeT], TypeT]:
355364
from pandas import Series
356365

357366
return _register_accessor(name, Series)
@@ -385,7 +394,7 @@ def register_series_accessor(name: str):
385394

386395

387396
@doc(_register_accessor, klass="Index", examples=_register_index_examples)
388-
def register_index_accessor(name: str):
397+
def register_index_accessor(name: str) -> Callable[[TypeT], TypeT]:
389398
from pandas import Index
390399

391400
return _register_accessor(name, Index)

pandas/core/arrays/sparse/accessor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ class SparseFrameAccessor(BaseAccessor, PandasDelegate):
243243
"""
244244
DataFrame accessor for sparse data.
245245
246+
See Also
247+
--------
248+
DataFrame.sparse.density : Ratio of non-sparse points to total (dense) data points.
249+
246250
Examples
247251
--------
248252
>>> df = pd.DataFrame({"a": [1, 2, 0, 0], "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
@@ -274,6 +278,11 @@ def from_spmatrix(cls, data, index=None, columns=None) -> DataFrame:
274278
Each column of the DataFrame is stored as a
275279
:class:`arrays.SparseArray`.
276280
281+
See Also
282+
--------
283+
DataFrame.sparse.to_coo : Return the contents of the frame as a
284+
sparse SciPy COO matrix.
285+
277286
Examples
278287
--------
279288
>>> import scipy.sparse
@@ -319,6 +328,11 @@ def to_dense(self) -> DataFrame:
319328
DataFrame
320329
A DataFrame with the same values stored as dense arrays.
321330
331+
See Also
332+
--------
333+
DataFrame.sparse.density : Ratio of non-sparse points to total
334+
(dense) data points.
335+
322336
Examples
323337
--------
324338
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0])})
@@ -343,6 +357,10 @@ def to_coo(self) -> spmatrix:
343357
If the caller is heterogeneous and contains booleans or objects,
344358
the result will be of dtype=object. See Notes.
345359
360+
See Also
361+
--------
362+
DataFrame.sparse.to_dense : Convert a DataFrame with sparse values to dense.
363+
346364
Notes
347365
-----
348366
The dtype will be the lowest-common-denominator type (implicit
@@ -388,6 +406,11 @@ def density(self) -> float:
388406
"""
389407
Ratio of non-sparse points to total (dense) data points.
390408
409+
See Also
410+
--------
411+
DataFrame.sparse.from_spmatrix : Create a new DataFrame from a
412+
scipy sparse matrix.
413+
391414
Examples
392415
--------
393416
>>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})

pandas/core/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ def ndim(self) -> Literal[1]:
355355
"""
356356
Number of dimensions of the underlying data, by definition 1.
357357
358+
See Also
359+
--------
360+
Series.size: Return the number of elements in the underlying data.
361+
Series.shape: Return a tuple of the shape of the underlying data.
362+
Series.dtype: Return the dtype object of the underlying data.
363+
Series.values: Return Series as ndarray or ndarray-like depending on the dtype.
364+
358365
Examples
359366
--------
360367
>>> s = pd.Series(["Ant", "Bear", "Cow"])
@@ -440,6 +447,13 @@ def size(self) -> int:
440447
"""
441448
Return the number of elements in the underlying data.
442449
450+
See Also
451+
--------
452+
Series.ndim: Number of dimensions of the underlying data, by definition 1.
453+
Series.shape: Return a tuple of the shape of the underlying data.
454+
Series.dtype: Return the dtype object of the underlying data.
455+
Series.values: Return Series as ndarray or ndarray-like depending on the dtype.
456+
443457
Examples
444458
--------
445459
For Series:

pandas/core/indexes/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7104,6 +7104,13 @@ def shape(self) -> Shape:
71047104
"""
71057105
Return a tuple of the shape of the underlying data.
71067106
7107+
See Also
7108+
--------
7109+
Index.size: Return the number of elements in the underlying data.
7110+
Index.ndim: Number of dimensions of the underlying data, by definition 1.
7111+
Index.dtype: Return the dtype object of the underlying data.
7112+
Index.values: Return an array representing the data in the Index.
7113+
71077114
Examples
71087115
--------
71097116
>>> idx = pd.Index([1, 2, 3])

pandas/io/pytables.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,11 @@ def get(self, key: str):
786786
object
787787
Same type as object stored in file.
788788
789+
See Also
790+
--------
791+
HDFStore.get_node : Returns the node with the key.
792+
HDFStore.get_storer : Returns the storer object for a key.
793+
789794
Examples
790795
--------
791796
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"])
@@ -1261,15 +1266,19 @@ def append(
12611266
Table format. Write as a PyTables Table structure which may perform
12621267
worse but allow more flexible operations like searching / selecting
12631268
subsets of the data.
1269+
axes : default None
1270+
This parameter is currently not accepted.
12641271
index : bool, default True
12651272
Write DataFrame index as a column.
12661273
append : bool, default True
12671274
Append the input data to the existing.
1268-
data_columns : list of columns, or True, default None
1269-
List of columns to create as indexed data columns for on-disk
1270-
queries, or True to use all columns. By default only the axes
1271-
of the object are indexed. See `here
1272-
<https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#query-via-data-columns>`__.
1275+
complib : default None
1276+
This parameter is currently not accepted.
1277+
complevel : int, 0-9, default None
1278+
Specifies a compression level for data.
1279+
A value of 0 or None disables compression.
1280+
columns : default None
1281+
This parameter is currently not accepted, try data_columns.
12731282
min_itemsize : int, dict, or None
12741283
Dict of columns that specify minimum str sizes.
12751284
nan_rep : str
@@ -1278,11 +1287,26 @@ def append(
12781287
Size to chunk the writing.
12791288
expectedrows : int
12801289
Expected TOTAL row size of this table.
1281-
encoding : default None
1282-
Provide an encoding for str.
12831290
dropna : bool, default False, optional
12841291
Do not write an ALL nan row to the store settable
12851292
by the option 'io.hdf.dropna_table'.
1293+
data_columns : list of columns, or True, default None
1294+
List of columns to create as indexed data columns for on-disk
1295+
queries, or True to use all columns. By default only the axes
1296+
of the object are indexed. See `here
1297+
<https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#query-via-data-columns>`__.
1298+
encoding : default None
1299+
Provide an encoding for str.
1300+
errors : str, default 'strict'
1301+
The error handling scheme to use for encoding errors.
1302+
The default is 'strict' meaning that encoding errors raise a
1303+
UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
1304+
'xmlcharrefreplace' as well as any other name registered with
1305+
codecs.register_error that can handle UnicodeEncodeErrors.
1306+
1307+
See Also
1308+
--------
1309+
HDFStore.append_to_multiple : Append to multiple tables.
12861310
12871311
Notes
12881312
-----

0 commit comments

Comments
 (0)