217
217
FormattersType ,
218
218
Frequency ,
219
219
FromDictOrient ,
220
+ HashableT ,
221
+ HashableT2 ,
220
222
IgnoreRaise ,
221
223
IndexKeyFunc ,
222
224
IndexLabel ,
239
241
SortKind ,
240
242
StorageOptions ,
241
243
Suffixes ,
244
+ T ,
242
245
ToStataByteorder ,
243
246
ToTimestampHow ,
244
247
UpdateJoin ,
@@ -643,10 +646,10 @@ class DataFrame(NDFrame, OpsMixin):
643
646
__pandas_priority__ = 4000
644
647
645
648
@property
646
- def _constructor (self ) -> Callable [..., DataFrame ]:
649
+ def _constructor (self ) -> type [ DataFrame ]:
647
650
return DataFrame
648
651
649
- def _constructor_from_mgr (self , mgr , axes ):
652
+ def _constructor_from_mgr (self , mgr , axes ) -> DataFrame :
650
653
if self ._constructor is DataFrame :
651
654
# we are pandas.DataFrame (or a subclass that doesn't override _constructor)
652
655
return DataFrame ._from_mgr (mgr , axes = axes )
@@ -659,7 +662,7 @@ def _constructor_from_mgr(self, mgr, axes):
659
662
def _sliced_from_mgr (self , mgr , axes ) -> Series :
660
663
return Series ._from_mgr (mgr , axes )
661
664
662
- def _constructor_sliced_from_mgr (self , mgr , axes ):
665
+ def _constructor_sliced_from_mgr (self , mgr , axes ) -> Series :
663
666
if self ._constructor_sliced is Series :
664
667
ser = self ._sliced_from_mgr (mgr , axes )
665
668
ser ._name = None # caller is responsible for setting real name
@@ -1353,7 +1356,7 @@ def _get_values_for_csv(
1353
1356
decimal : str ,
1354
1357
na_rep : str ,
1355
1358
quoting , # int csv.QUOTE_FOO from stdlib
1356
- ) -> Self :
1359
+ ) -> DataFrame :
1357
1360
# helper used by to_csv
1358
1361
mgr = self ._mgr .get_values_for_csv (
1359
1362
float_format = float_format ,
@@ -1831,7 +1834,7 @@ def from_dict(
1831
1834
a b 1 3
1832
1835
c 2 4
1833
1836
"""
1834
- index = None
1837
+ index : list | Index | None = None
1835
1838
orient = orient .lower () # type: ignore[assignment]
1836
1839
if orient == "index" :
1837
1840
if len (data ) > 0 :
@@ -1857,7 +1860,7 @@ def from_dict(
1857
1860
else :
1858
1861
realdata = data ["data" ]
1859
1862
1860
- def create_index (indexlist , namelist ):
1863
+ def create_index (indexlist , namelist ) -> Index :
1861
1864
index : Index
1862
1865
if len (namelist ) > 1 :
1863
1866
index = MultiIndex .from_tuples (indexlist , names = namelist )
@@ -2700,6 +2703,42 @@ def to_feather(self, path: FilePath | WriteBuffer[bytes], **kwargs) -> None:
2700
2703
2701
2704
to_feather (self , path , ** kwargs )
2702
2705
2706
+ @overload
2707
+ def to_markdown (
2708
+ self ,
2709
+ buf : None = ...,
2710
+ * ,
2711
+ mode : str = ...,
2712
+ index : bool = ...,
2713
+ storage_options : StorageOptions | None = ...,
2714
+ ** kwargs ,
2715
+ ) -> str :
2716
+ ...
2717
+
2718
+ @overload
2719
+ def to_markdown (
2720
+ self ,
2721
+ buf : FilePath | WriteBuffer [str ],
2722
+ * ,
2723
+ mode : str = ...,
2724
+ index : bool = ...,
2725
+ storage_options : StorageOptions | None = ...,
2726
+ ** kwargs ,
2727
+ ) -> None :
2728
+ ...
2729
+
2730
+ @overload
2731
+ def to_markdown (
2732
+ self ,
2733
+ buf : FilePath | WriteBuffer [str ] | None ,
2734
+ * ,
2735
+ mode : str = ...,
2736
+ index : bool = ...,
2737
+ storage_options : StorageOptions | None = ...,
2738
+ ** kwargs ,
2739
+ ) -> str | None :
2740
+ ...
2741
+
2703
2742
@doc (
2704
2743
Series .to_markdown ,
2705
2744
klass = _shared_doc_kwargs ["klass" ],
@@ -2881,6 +2920,39 @@ def to_parquet(
2881
2920
** kwargs ,
2882
2921
)
2883
2922
2923
+ @overload
2924
+ def to_orc (
2925
+ self ,
2926
+ path : None = ...,
2927
+ * ,
2928
+ engine : Literal ["pyarrow" ] = ...,
2929
+ index : bool | None = ...,
2930
+ engine_kwargs : dict [str , Any ] | None = ...,
2931
+ ) -> bytes :
2932
+ ...
2933
+
2934
+ @overload
2935
+ def to_orc (
2936
+ self ,
2937
+ path : FilePath | WriteBuffer [bytes ],
2938
+ * ,
2939
+ engine : Literal ["pyarrow" ] = ...,
2940
+ index : bool | None = ...,
2941
+ engine_kwargs : dict [str , Any ] | None = ...,
2942
+ ) -> None :
2943
+ ...
2944
+
2945
+ @overload
2946
+ def to_orc (
2947
+ self ,
2948
+ path : FilePath | WriteBuffer [bytes ] | None ,
2949
+ * ,
2950
+ engine : Literal ["pyarrow" ] = ...,
2951
+ index : bool | None = ...,
2952
+ engine_kwargs : dict [str , Any ] | None = ...,
2953
+ ) -> bytes | None :
2954
+ ...
2955
+
2884
2956
def to_orc (
2885
2957
self ,
2886
2958
path : FilePath | WriteBuffer [bytes ] | None = None ,
@@ -4027,7 +4099,7 @@ def _setitem_slice(self, key: slice, value) -> None:
4027
4099
# backwards-compat, xref GH#31469
4028
4100
self .iloc [key ] = value
4029
4101
4030
- def _setitem_array (self , key , value ):
4102
+ def _setitem_array (self , key , value ) -> None :
4031
4103
# also raises Exception if object array with NA values
4032
4104
if com .is_bool_indexer (key ):
4033
4105
# bool indexer is indexing along rows
@@ -4061,7 +4133,7 @@ def _setitem_array(self, key, value):
4061
4133
elif np .ndim (value ) > 1 :
4062
4134
# list of lists
4063
4135
value = DataFrame (value ).values
4064
- return self ._setitem_array (key , value )
4136
+ self ._setitem_array (key , value )
4065
4137
4066
4138
else :
4067
4139
self ._iset_not_inplace (key , value )
@@ -4595,7 +4667,7 @@ def eval(self, expr: str, *, inplace: bool = False, **kwargs) -> Any | None:
4595
4667
4596
4668
return _eval (expr , inplace = inplace , ** kwargs )
4597
4669
4598
- def select_dtypes (self , include = None , exclude = None ) -> Self :
4670
+ def select_dtypes (self , include = None , exclude = None ) -> DataFrame :
4599
4671
"""
4600
4672
Return a subset of the DataFrame's columns based on the column dtypes.
4601
4673
@@ -5474,9 +5546,21 @@ def pop(self, item: Hashable) -> Series:
5474
5546
"""
5475
5547
return super ().pop (item = item )
5476
5548
5549
+ @overload
5550
+ def _replace_columnwise (
5551
+ self , mapping : dict [Hashable , tuple [Any , Any ]], inplace : Literal [True ], regex
5552
+ ) -> None :
5553
+ ...
5554
+
5555
+ @overload
5556
+ def _replace_columnwise (
5557
+ self , mapping : dict [Hashable , tuple [Any , Any ]], inplace : Literal [False ], regex
5558
+ ) -> Self :
5559
+ ...
5560
+
5477
5561
def _replace_columnwise (
5478
5562
self , mapping : dict [Hashable , tuple [Any , Any ]], inplace : bool , regex
5479
- ):
5563
+ ) -> Self | None :
5480
5564
"""
5481
5565
Dispatch to Series.replace column-wise.
5482
5566
@@ -5505,7 +5589,7 @@ def _replace_columnwise(
5505
5589
res ._iset_item (i , newobj , inplace = inplace )
5506
5590
5507
5591
if inplace :
5508
- return
5592
+ return None
5509
5593
return res .__finalize__ (self )
5510
5594
5511
5595
@doc (NDFrame .shift , klass = _shared_doc_kwargs ["klass" ])
@@ -11815,19 +11899,19 @@ def kurt(
11815
11899
product = prod
11816
11900
11817
11901
@doc (make_doc ("cummin" , ndim = 2 ))
11818
- def cummin (self , axis : Axis | None = None , skipna : bool = True , * args , ** kwargs ):
11902
+ def cummin (self , axis : Axis = 0 , skipna : bool = True , * args , ** kwargs ) -> Self :
11819
11903
return NDFrame .cummin (self , axis , skipna , * args , ** kwargs )
11820
11904
11821
11905
@doc (make_doc ("cummax" , ndim = 2 ))
11822
- def cummax (self , axis : Axis | None = None , skipna : bool = True , * args , ** kwargs ):
11906
+ def cummax (self , axis : Axis = 0 , skipna : bool = True , * args , ** kwargs ) -> Self :
11823
11907
return NDFrame .cummax (self , axis , skipna , * args , ** kwargs )
11824
11908
11825
11909
@doc (make_doc ("cumsum" , ndim = 2 ))
11826
- def cumsum (self , axis : Axis | None = None , skipna : bool = True , * args , ** kwargs ):
11910
+ def cumsum (self , axis : Axis = 0 , skipna : bool = True , * args , ** kwargs ) -> Self :
11827
11911
return NDFrame .cumsum (self , axis , skipna , * args , ** kwargs )
11828
11912
11829
11913
@doc (make_doc ("cumprod" , 2 ))
11830
- def cumprod (self , axis : Axis | None = None , skipna : bool = True , * args , ** kwargs ):
11914
+ def cumprod (self , axis : Axis = 0 , skipna : bool = True , * args , ** kwargs ) -> Self :
11831
11915
return NDFrame .cumprod (self , axis , skipna , * args , ** kwargs )
11832
11916
11833
11917
def nunique (self , axis : Axis = 0 , dropna : bool = True ) -> Series :
@@ -12710,8 +12794,12 @@ def values(self) -> np.ndarray:
12710
12794
return self ._mgr .as_array ()
12711
12795
12712
12796
12713
- def _from_nested_dict (data ) -> collections .defaultdict :
12714
- new_data : collections .defaultdict = collections .defaultdict (dict )
12797
+ def _from_nested_dict (
12798
+ data : Mapping [HashableT , Mapping [HashableT2 , T ]],
12799
+ ) -> collections .defaultdict [HashableT2 , dict [HashableT , T ]]:
12800
+ new_data : collections .defaultdict [
12801
+ HashableT2 , dict [HashableT , T ]
12802
+ ] = collections .defaultdict (dict )
12715
12803
for index , s in data .items ():
12716
12804
for col , v in s .items ():
12717
12805
new_data [col ][index ] = v
0 commit comments