22
22
23
23
24
24
class ExtensionArray (object ):
25
- """Abstract base class for custom 1-D array types.
25
+ """
26
+ Abstract base class for custom 1-D array types.
26
27
27
28
pandas will recognize instances of this class as proper arrays
28
29
with a custom type and will not attempt to coerce them to objects. They
@@ -100,7 +101,8 @@ class ExtensionArray(object):
100
101
# ------------------------------------------------------------------------
101
102
@classmethod
102
103
def _from_sequence (cls , scalars , dtype = None , copy = False ):
103
- """Construct a new ExtensionArray from a sequence of scalars.
104
+ """
105
+ Construct a new ExtensionArray from a sequence of scalars.
104
106
105
107
Parameters
106
108
----------
@@ -121,7 +123,8 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
121
123
122
124
@classmethod
123
125
def _from_factorized (cls , values , original ):
124
- """Reconstruct an ExtensionArray after factorization.
126
+ """
127
+ Reconstruct an ExtensionArray after factorization.
125
128
126
129
Parameters
127
130
----------
@@ -143,7 +146,8 @@ def _from_factorized(cls, values, original):
143
146
144
147
def __getitem__ (self , item ):
145
148
# type (Any) -> Any
146
- """Select a subset of self.
149
+ """
150
+ Select a subset of self.
147
151
148
152
Parameters
149
153
----------
@@ -174,7 +178,8 @@ def __getitem__(self, item):
174
178
175
179
def __setitem__ (self , key , value ):
176
180
# type: (Union[int, np.ndarray], Any) -> None
177
- """Set one or more values inplace.
181
+ """
182
+ Set one or more values inplace.
178
183
179
184
This method is not required to satisfy the pandas extension array
180
185
interface.
@@ -219,7 +224,8 @@ def __setitem__(self, key, value):
219
224
220
225
def __len__ (self ):
221
226
# type: () -> int
222
- """Length of this array
227
+ """
228
+ Length of this array
223
229
224
230
Returns
225
231
-------
@@ -228,8 +234,8 @@ def __len__(self):
228
234
raise AbstractMethodError (self )
229
235
230
236
def __iter__ (self ):
231
- """Iterate over elements of the array.
232
-
237
+ """
238
+ Iterate over elements of the array.
233
239
"""
234
240
# This needs to be implemented so that pandas recognizes extension
235
241
# arrays as list-like. The default implementation makes successive
@@ -243,26 +249,32 @@ def __iter__(self):
243
249
@property
244
250
def dtype (self ):
245
251
# type: () -> ExtensionDtype
246
- """An instance of 'ExtensionDtype'."""
252
+ """
253
+ An instance of 'ExtensionDtype'.
254
+ """
247
255
raise AbstractMethodError (self )
248
256
249
257
@property
250
258
def shape (self ):
251
259
# type: () -> Tuple[int, ...]
252
- """Return a tuple of the array dimensions."""
260
+ """
261
+ Return a tuple of the array dimensions.
262
+ """
253
263
return (len (self ),)
254
264
255
265
@property
256
266
def ndim (self ):
257
267
# type: () -> int
258
- """Extension Arrays are only allowed to be 1-dimensional."""
268
+ """
269
+ Extension Arrays are only allowed to be 1-dimensional.
270
+ """
259
271
return 1
260
272
261
273
@property
262
274
def nbytes (self ):
263
275
# type: () -> int
264
- """The number of bytes needed to store this object in memory.
265
-
276
+ """
277
+ The number of bytes needed to store this object in memory.
266
278
"""
267
279
# If this is expensive to compute, return an approximate lower bound
268
280
# on the number of bytes needed.
@@ -272,7 +284,8 @@ def nbytes(self):
272
284
# Additional Methods
273
285
# ------------------------------------------------------------------------
274
286
def astype (self , dtype , copy = True ):
275
- """Cast to a NumPy array with 'dtype'.
287
+ """
288
+ Cast to a NumPy array with 'dtype'.
276
289
277
290
Parameters
278
291
----------
@@ -315,7 +328,8 @@ def isna(self):
315
328
316
329
def _values_for_argsort (self ):
317
330
# type: () -> ndarray
318
- """Return values for sorting.
331
+ """
332
+ Return values for sorting.
319
333
320
334
Returns
321
335
-------
@@ -365,7 +379,8 @@ def argsort(self, ascending=True, kind='quicksort', *args, **kwargs):
365
379
return result
366
380
367
381
def fillna (self , value = None , method = None , limit = None ):
368
- """ Fill NA/NaN values using the specified method.
382
+ """
383
+ Fill NA/NaN values using the specified method.
369
384
370
385
Parameters
371
386
----------
@@ -418,7 +433,8 @@ def fillna(self, value=None, method=None, limit=None):
418
433
return new_values
419
434
420
435
def dropna (self ):
421
- """ Return ExtensionArray without NA values
436
+ """
437
+ Return ExtensionArray without NA values
422
438
423
439
Returns
424
440
-------
@@ -462,7 +478,8 @@ def shift(self, periods=1):
462
478
return self ._concat_same_type ([a , b ])
463
479
464
480
def unique (self ):
465
- """Compute the ExtensionArray of unique values.
481
+ """
482
+ Compute the ExtensionArray of unique values.
466
483
467
484
Returns
468
485
-------
@@ -475,7 +492,8 @@ def unique(self):
475
492
476
493
def _values_for_factorize (self ):
477
494
# type: () -> Tuple[ndarray, Any]
478
- """Return an array and missing value suitable for factorization.
495
+ """
496
+ Return an array and missing value suitable for factorization.
479
497
480
498
Returns
481
499
-------
@@ -499,7 +517,8 @@ def _values_for_factorize(self):
499
517
500
518
def factorize (self , na_sentinel = - 1 ):
501
519
# type: (int) -> Tuple[ndarray, ExtensionArray]
502
- """Encode the extension array as an enumerated type.
520
+ """
521
+ Encode the extension array as an enumerated type.
503
522
504
523
Parameters
505
524
----------
@@ -552,7 +571,8 @@ def factorize(self, na_sentinel=-1):
552
571
553
572
def take (self , indices , allow_fill = False , fill_value = None ):
554
573
# type: (Sequence[int], bool, Optional[Any]) -> ExtensionArray
555
- """Take elements from an array.
574
+ """
575
+ Take elements from an array.
556
576
557
577
Parameters
558
578
----------
@@ -641,7 +661,8 @@ def take(self, indices, allow_fill=False, fill_value=None):
641
661
642
662
def copy (self , deep = False ):
643
663
# type: (bool) -> ExtensionArray
644
- """Return a copy of the array.
664
+ """
665
+ Return a copy of the array.
645
666
646
667
Parameters
647
668
----------
@@ -661,13 +682,16 @@ def copy(self, deep=False):
661
682
def _formatting_values (self ):
662
683
# type: () -> np.ndarray
663
684
# At the moment, this has to be an array since we use result.dtype
664
- """An array of values to be printed in, e.g. the Series repr"""
685
+ """
686
+ An array of values to be printed in, e.g. the Series repr
687
+ """
665
688
return np .array (self )
666
689
667
690
@classmethod
668
691
def _concat_same_type (cls , to_concat ):
669
692
# type: (Sequence[ExtensionArray]) -> ExtensionArray
670
- """Concatenate multiple array
693
+ """
694
+ Concatenate multiple array
671
695
672
696
Parameters
673
697
----------
@@ -689,7 +713,8 @@ def _concat_same_type(cls, to_concat):
689
713
@property
690
714
def _ndarray_values (self ):
691
715
# type: () -> np.ndarray
692
- """Internal pandas method for lossy conversion to a NumPy ndarray.
716
+ """
717
+ Internal pandas method for lossy conversion to a NumPy ndarray.
693
718
694
719
This method is not part of the pandas interface.
695
720
0 commit comments