@@ -656,6 +656,12 @@ def isna(self) -> np.ndarray | ExtensionArraySupportsAnyAll:
656
656
* ``na_values._is_boolean`` should be True
657
657
* `na_values` should implement :func:`ExtensionArray._reduce`
658
658
* ``na_values.any`` and ``na_values.all`` should be implemented
659
+
660
+ Examples
661
+ --------
662
+ >>> arr = pd.array([1, 2, np.nan, np.nan])
663
+ >>> arr.isna()
664
+ array([False, False, True, True])
659
665
"""
660
666
raise AbstractMethodError (self )
661
667
@@ -882,6 +888,14 @@ def fillna(
882
888
-------
883
889
ExtensionArray
884
890
With NA/NaN filled.
891
+
892
+ Examples
893
+ --------
894
+ >>> arr = pd.array([np.nan, np.nan, 2, 3, np.nan, np.nan])
895
+ >>> arr.fillna(0)
896
+ <IntegerArray>
897
+ [0, 0, 2, 3, 0, 0]
898
+ Length: 6, dtype: Int64
885
899
"""
886
900
value , method = validate_fillna_kwargs (value , method )
887
901
@@ -918,7 +932,13 @@ def dropna(self) -> Self:
918
932
919
933
Returns
920
934
-------
921
- pandas.api.extensions.ExtensionArray
935
+
936
+ Examples
937
+ --------
938
+ >>> pd.array([1, 2, np.nan]).dropna()
939
+ <IntegerArray>
940
+ [1, 2]
941
+ Length: 2, dtype: Int64
922
942
"""
923
943
# error: Unsupported operand type for ~ ("ExtensionArray")
924
944
return self [~ self .isna ()] # type: ignore[operator]
@@ -955,6 +975,14 @@ def shift(self, periods: int = 1, fill_value: object = None) -> ExtensionArray:
955
975
``self.dtype.na_value``.
956
976
957
977
For 2-dimensional ExtensionArrays, we are always shifting along axis=0.
978
+
979
+ Examples
980
+ --------
981
+ >>> arr = pd.array([1, 2, 3])
982
+ >>> arr.shift(2)
983
+ <IntegerArray>
984
+ [<NA>, <NA>, 1]
985
+ Length: 3, dtype: Int64
958
986
"""
959
987
# Note: this implementation assumes that `self.dtype.na_value` can be
960
988
# stored in an instance of your ExtensionArray with `self.dtype`.
@@ -982,6 +1010,14 @@ def unique(self) -> Self:
982
1010
Returns
983
1011
-------
984
1012
pandas.api.extensions.ExtensionArray
1013
+
1014
+ Examples
1015
+ --------
1016
+ >>> arr = pd.array([1, 2, 3, 1, 2, 3])
1017
+ >>> arr.unique()
1018
+ <IntegerArray>
1019
+ [1, 2, 3]
1020
+ Length: 3, dtype: Int64
985
1021
"""
986
1022
uniques = unique (self .astype (object ))
987
1023
return self ._from_sequence (uniques , dtype = self .dtype )
@@ -1029,6 +1065,12 @@ def searchsorted(
1029
1065
See Also
1030
1066
--------
1031
1067
numpy.searchsorted : Similar method from NumPy.
1068
+
1069
+ Examples
1070
+ --------
1071
+ >>> arr = pd.array([1, 2, 3, 5])
1072
+ >>> arr.searchsorted([4])
1073
+ array([3])
1032
1074
"""
1033
1075
# Note: the base tests provided by pandas only test the basics.
1034
1076
# We do not test
@@ -1057,6 +1099,13 @@ def equals(self, other: object) -> bool:
1057
1099
-------
1058
1100
boolean
1059
1101
Whether the arrays are equivalent.
1102
+
1103
+ Examples
1104
+ --------
1105
+ >>> arr1 = pd.array([1, 2, np.nan])
1106
+ >>> arr2 = pd.array([1, 2, np.nan])
1107
+ >>> arr1.equals(arr2)
1108
+ True
1060
1109
"""
1061
1110
if type (self ) != type (other ):
1062
1111
return False
@@ -1087,6 +1136,14 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
1087
1136
Returns
1088
1137
-------
1089
1138
np.ndarray[bool]
1139
+
1140
+ Examples
1141
+ --------
1142
+ >>> arr = pd.array([1, 2, 3])
1143
+ >>> arr.isin([1])
1144
+ <BooleanArray>
1145
+ [True, False, False]
1146
+ Length: 3, dtype: boolean
1090
1147
"""
1091
1148
return isin (np .asarray (self ), values )
1092
1149
@@ -1151,6 +1208,16 @@ def factorize(
1151
1208
Notes
1152
1209
-----
1153
1210
:meth:`pandas.factorize` offers a `sort` keyword as well.
1211
+
1212
+ Examples
1213
+ --------
1214
+ >>> idx1 = pd.PeriodIndex(["2014-01", "2014-01", "2014-02", "2014-02",
1215
+ ... "2014-03", "2014-03"], freq="M")
1216
+ >>> arr, idx = idx1.factorize()
1217
+ >>> arr
1218
+ array([0, 0, 1, 1, 2, 2])
1219
+ >>> idx
1220
+ PeriodIndex(['2014-01', '2014-02', '2014-03'], dtype='period[M]')
1154
1221
"""
1155
1222
# Implementer note: There are two ways to override the behavior of
1156
1223
# pandas.factorize
@@ -1657,6 +1724,14 @@ def insert(self, loc: int, item) -> Self:
1657
1724
1658
1725
The default implementation relies on _from_sequence to raise on invalid
1659
1726
items.
1727
+
1728
+ Examples
1729
+ --------
1730
+ >>> arr = pd.array([1, 2, 3])
1731
+ >>> arr.insert(2, -1)
1732
+ <IntegerArray>
1733
+ [1, 2, -1, 3]
1734
+ Length: 4, dtype: Int64
1660
1735
"""
1661
1736
loc = validate_insert_loc (loc , len (self ))
1662
1737
0 commit comments