19
19
Optional ,
20
20
Sequence ,
21
21
Set ,
22
+ Tuple ,
22
23
Union ,
23
24
)
24
25
import warnings
90
91
from pandas .io .formats .printing import pprint_thing
91
92
from pandas .tseries .frequencies import to_offset
92
93
94
+
93
95
# goal is to be able to define the docs close to function, while still being
94
96
# able to share
95
97
_shared_docs = dict () # type: Dict[str, str]
@@ -552,7 +554,7 @@ def _stat_axis(self):
552
554
return getattr (self , self ._stat_axis_name )
553
555
554
556
@property
555
- def shape (self ):
557
+ def shape (self ) -> Tuple [ int ] :
556
558
"""
557
559
Return a tuple of axis dimensions
558
560
"""
@@ -568,7 +570,7 @@ def axes(self):
568
570
return [self ._get_axis (a ) for a in self ._AXIS_ORDERS ]
569
571
570
572
@property
571
- def ndim (self ):
573
+ def ndim (self ) -> int :
572
574
"""
573
575
Return an int representing the number of axes / array dimensions.
574
576
@@ -591,7 +593,7 @@ def ndim(self):
591
593
return self ._data .ndim
592
594
593
595
@property
594
- def size (self ):
596
+ def size (self ) -> int :
595
597
"""
596
598
Return an int representing the number of elements in this object.
597
599
@@ -624,7 +626,10 @@ def _obj_with_exclusions(self):
624
626
""" internal compat with SelectionMixin """
625
627
return self
626
628
627
- def set_axis (self , labels , axis = 0 , inplace = False ):
629
+ def set_axis (self ,
630
+ labels : Sequence [Any ],
631
+ axis = 0 ,
632
+ inplace = False ) -> "NDFrame" :
628
633
"""
629
634
Assign desired index to given axis.
630
635
@@ -727,7 +732,7 @@ def _set_axis(self, axis, labels):
727
732
self ._data .set_axis (axis , labels )
728
733
self ._clear_item_cache ()
729
734
730
- def transpose (self , * args , ** kwargs ):
735
+ def transpose (self , * args , ** kwargs ) -> "NDFrame" :
731
736
"""
732
737
Permute the dimensions of the %(klass)s
733
738
@@ -771,7 +776,10 @@ def transpose(self, *args, **kwargs):
771
776
nv .validate_transpose (tuple (), kwargs )
772
777
return self ._constructor (new_values , ** new_axes ).__finalize__ (self )
773
778
774
- def swapaxes (self , axis1 , axis2 , copy = True ):
779
+ def swapaxes (self ,
780
+ axis1 : int ,
781
+ axis2 : int ,
782
+ copy = True ) -> "NDFrame" :
775
783
"""
776
784
Interchange axes and swap values axes appropriately.
777
785
@@ -796,7 +804,9 @@ def swapaxes(self, axis1, axis2, copy=True):
796
804
797
805
return self ._constructor (new_values , * new_axes ).__finalize__ (self )
798
806
799
- def droplevel (self , level , axis = 0 ):
807
+ def droplevel (self ,
808
+ level : Union [int , str , Sequence [Union [int , str ]]],
809
+ axis = 0 ) -> "NDFrame" :
800
810
"""
801
811
Return DataFrame with requested index / column level(s) removed.
802
812
@@ -855,7 +865,8 @@ def droplevel(self, level, axis=0):
855
865
result = self .set_axis (new_labels , axis = axis , inplace = False )
856
866
return result
857
867
858
- def pop (self , item ):
868
+ def pop (self ,
869
+ item : str ) -> "pd.Series" :
859
870
"""
860
871
Return item and drop from frame. Raise KeyError if not found.
861
872
@@ -905,7 +916,7 @@ def pop(self, item):
905
916
906
917
return result
907
918
908
- def squeeze (self , axis = None ):
919
+ def squeeze (self , axis = None ) -> "NDFrame" :
909
920
"""
910
921
Squeeze 1 dimensional axis objects into scalars.
911
922
@@ -1016,7 +1027,7 @@ def squeeze(self, axis=None):
1016
1027
)
1017
1028
]
1018
1029
1019
- def swaplevel (self , i = - 2 , j = - 1 , axis = 0 ):
1030
+ def swaplevel (self , i = - 2 , j = - 1 , axis = 0 ) -> "NDFrame" :
1020
1031
"""
1021
1032
Swap levels i and j in a MultiIndex on a particular axis
1022
1033
@@ -1038,7 +1049,7 @@ def swaplevel(self, i=-2, j=-1, axis=0):
1038
1049
# ----------------------------------------------------------------------
1039
1050
# Rename
1040
1051
1041
- def rename (self , * args , ** kwargs ):
1052
+ def rename (self , * args , ** kwargs ) -> "NDFrame" :
1042
1053
"""
1043
1054
Alter axes input function or functions. Function / dict values must be
1044
1055
unique (1-to-1). Labels not contained in a dict / Series will be left
@@ -1203,7 +1214,7 @@ def rename(self, *args, **kwargs):
1203
1214
return result .__finalize__ (self )
1204
1215
1205
1216
@rewrite_axis_style_signature ("mapper" , [("copy" , True ), ("inplace" , False )])
1206
- def rename_axis (self , mapper = sentinel , ** kwargs ):
1217
+ def rename_axis (self , mapper = sentinel , ** kwargs ) -> "NDFrame" :
1207
1218
"""
1208
1219
Set the name of the axis for the index or columns.
1209
1220
@@ -1373,7 +1384,10 @@ class name
1373
1384
if not inplace :
1374
1385
return result
1375
1386
1376
- def _set_axis_name (self , name , axis = 0 , inplace = False ):
1387
+ def _set_axis_name (self ,
1388
+ name : Union [str , List [str ]],
1389
+ axis = 0 ,
1390
+ inplace = False ) -> "NDFrame" :
1377
1391
"""
1378
1392
Set the name(s) of the axis.
1379
1393
@@ -1442,7 +1456,8 @@ def _indexed_same(self, other):
1442
1456
self ._get_axis (a ).equals (other ._get_axis (a )) for a in self ._AXIS_ORDERS
1443
1457
)
1444
1458
1445
- def equals (self , other ):
1459
+ def equals (self ,
1460
+ other : "NDFrame" ) -> bool :
1446
1461
"""
1447
1462
Test whether two objects contain the same elements.
1448
1463
@@ -1581,7 +1596,7 @@ def __nonzero__(self):
1581
1596
1582
1597
__bool__ = __nonzero__
1583
1598
1584
- def bool (self ):
1599
+ def bool (self ) -> bool :
1585
1600
"""
1586
1601
Return the bool of a single element PandasObject.
1587
1602
@@ -1619,7 +1634,9 @@ def __round__(self, decimals=0):
1619
1634
# operations should utilize/extend these methods when possible so that we
1620
1635
# have consistent precedence and validation logic throughout the library.
1621
1636
1622
- def _is_level_reference (self , key , axis = 0 ):
1637
+ def _is_level_reference (self ,
1638
+ key : str ,
1639
+ axis = 0 ) -> bool :
1623
1640
"""
1624
1641
Test whether a key is a level reference for a given axis.
1625
1642
@@ -1649,7 +1666,9 @@ def _is_level_reference(self, key, axis=0):
1649
1666
and not self ._is_label_reference (key , axis = axis )
1650
1667
)
1651
1668
1652
- def _is_label_reference (self , key , axis = 0 ):
1669
+ def _is_label_reference (self ,
1670
+ key : str ,
1671
+ axis = 0 ) -> bool :
1653
1672
"""
1654
1673
Test whether a key is a label reference for a given axis.
1655
1674
@@ -1678,7 +1697,9 @@ def _is_label_reference(self, key, axis=0):
1678
1697
and any (key in self .axes [ax ] for ax in other_axes )
1679
1698
)
1680
1699
1681
- def _is_label_or_level_reference (self , key , axis = 0 ):
1700
+ def _is_label_or_level_reference (self ,
1701
+ key : str ,
1702
+ axis = 0 ) -> bool :
1682
1703
"""
1683
1704
Test whether a key is a label or level reference for a given axis.
1684
1705
@@ -1702,7 +1723,9 @@ def _is_label_or_level_reference(self, key, axis=0):
1702
1723
key , axis = axis
1703
1724
)
1704
1725
1705
- def _check_label_or_level_ambiguity (self , key , axis = 0 ):
1726
+ def _check_label_or_level_ambiguity (self ,
1727
+ key : str ,
1728
+ axis = 0 ) -> None :
1706
1729
"""
1707
1730
Check whether `key` is ambiguous.
1708
1731
@@ -1751,7 +1774,9 @@ def _check_label_or_level_ambiguity(self, key, axis=0):
1751
1774
)
1752
1775
raise ValueError (msg )
1753
1776
1754
- def _get_label_or_level_values (self , key , axis = 0 ):
1777
+ def _get_label_or_level_values (self ,
1778
+ key : str ,
1779
+ axis = 0 ) -> np .ndarray :
1755
1780
"""
1756
1781
Return a 1-D array of values associated with `key`, a label or level
1757
1782
from the given `axis`.
@@ -1823,7 +1848,9 @@ def _get_label_or_level_values(self, key, axis=0):
1823
1848
1824
1849
return values
1825
1850
1826
- def _drop_labels_or_levels (self , keys , axis = 0 ):
1851
+ def _drop_labels_or_levels (self ,
1852
+ keys : Union [str , List [str ]],
1853
+ axis = 0 ) -> "NDFrame" :
1827
1854
"""
1828
1855
Drop labels and/or levels for the given `axis`.
1829
1856
@@ -1959,7 +1986,7 @@ def __contains__(self, key):
1959
1986
return key in self ._info_axis
1960
1987
1961
1988
@property
1962
- def empty (self ):
1989
+ def empty (self ) -> bool :
1963
1990
"""
1964
1991
Indicator whether DataFrame is empty.
1965
1992
@@ -2474,7 +2501,10 @@ def to_json(
2474
2501
indent = indent ,
2475
2502
)
2476
2503
2477
- def to_hdf (self , path_or_buf , key , ** kwargs ):
2504
+ def to_hdf (self ,
2505
+ path_or_buf : Union [str , FilePathOrBuffer ],
2506
+ key : str ,
2507
+ ** kwargs ) -> None :
2478
2508
"""
2479
2509
Write the contained data to an HDF5 file using HDFStore.
2480
2510
@@ -2579,7 +2609,10 @@ def to_hdf(self, path_or_buf, key, **kwargs):
2579
2609
2580
2610
pytables .to_hdf (path_or_buf , key , self , ** kwargs )
2581
2611
2582
- def to_msgpack (self , path_or_buf = None , encoding = "utf-8" , ** kwargs ):
2612
+ def to_msgpack (self ,
2613
+ path_or_buf : Optional [FilePathOrBuffer ] = None ,
2614
+ encoding = "utf-8" ,
2615
+ ** kwargs ) -> None :
2583
2616
"""
2584
2617
Serialize object to input file path using msgpack format.
2585
2618
@@ -2775,7 +2808,10 @@ def to_sql(
2775
2808
method = method ,
2776
2809
)
2777
2810
2778
- def to_pickle (self , path , compression = "infer" , protocol = pickle .HIGHEST_PROTOCOL ):
2811
+ def to_pickle (self ,
2812
+ path : str ,
2813
+ compression = "infer" ,
2814
+ protocol = pickle .HIGHEST_PROTOCOL ) -> None :
2779
2815
"""
2780
2816
Pickle (serialize) object to file.
2781
2817
@@ -2831,7 +2867,7 @@ def to_pickle(self, path, compression="infer", protocol=pickle.HIGHEST_PROTOCOL)
2831
2867
2832
2868
to_pickle (self , path , compression = compression , protocol = protocol )
2833
2869
2834
- def to_clipboard (self , excel = True , sep = None , ** kwargs ):
2870
+ def to_clipboard (self , excel = True , sep = None , ** kwargs ) -> None :
2835
2871
r"""
2836
2872
Copy object to the system clipboard.
2837
2873
0 commit comments