33
33
34
34
35
35
def try_cast_to_ea (cls_or_instance , obj , dtype = None ):
36
- """
37
- Call to `_from_sequence` that returns the object unchanged on Exception.
36
+ """Call to `_from_sequence` that returns the object unchanged on Exception.
38
37
39
38
Parameters
40
- ----------
39
+ ---------
41
40
cls_or_instance : ExtensionArray subclass or instance
42
41
obj : arraylike
43
42
Values to pass to cls._from_sequence
44
43
dtype : ExtensionDtype, optional
45
44
46
45
Returns
47
46
-------
48
- ExtensionArray or obj
49
47
"""
50
48
try :
51
49
result = cls_or_instance ._from_sequence (obj , dtype = dtype )
@@ -181,7 +179,6 @@ class ExtensionArray:
181
179
By default, ExtensionArrays are not hashable. Immutable subclasses may
182
180
override this behavior.
183
181
"""
184
-
185
182
# '_typ' is for pandas.core.dtypes.generic.ABCExtensionArray.
186
183
# Don't override this.
187
184
_typ = "extension"
@@ -238,6 +235,7 @@ def _from_sequence_of_strings(cls, strings, dtype=None, copy=False):
238
235
239
236
@classmethod
240
237
def _from_factorized (cls , values , original ):
238
+
241
239
"""
242
240
Reconstruct an ExtensionArray after factorization.
243
241
@@ -253,6 +251,7 @@ def _from_factorized(cls, values, original):
253
251
factorize
254
252
ExtensionArray.factorize
255
253
"""
254
+
256
255
raise AbstractMethodError (cls )
257
256
258
257
# ------------------------------------------------------------------------
@@ -287,13 +286,13 @@ def __getitem__(self, item):
287
286
if the slice is length 0 or 1.
288
287
289
288
For a boolean mask, return an instance of ``ExtensionArray``, filtered
290
- to the values where ``item`` is True.
289
+ to the values where ``item`` is True.
291
290
"""
292
291
raise AbstractMethodError (self )
293
292
294
293
def __setitem__ (self , key : Union [int , np .ndarray ], value : Any ) -> None :
295
294
"""
296
- Set one or more values inplace.
295
+ Set one or more values inplace.
297
296
298
297
This method is not required to satisfy the pandas extension array
299
298
interface.
@@ -348,8 +347,7 @@ def __len__(self) -> int:
348
347
349
348
def __iter__ (self ):
350
349
"""
351
- Iterate over elements of the array.
352
- """
350
+ Iterate over elements of the array."""
353
351
# This needs to be implemented so that pandas recognizes extension
354
352
# arrays as list-like. The default implementation makes successive
355
353
# calls to ``__getitem__``, which may be slower than necessary.
@@ -395,9 +393,7 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default):
395
393
396
394
@property
397
395
def dtype (self ) -> ExtensionDtype :
398
- """
399
- An instance of 'ExtensionDtype'.
400
- """
396
+ "An instance of 'ExtensionDtype'."
401
397
raise AbstractMethodError (self )
402
398
403
399
@property
@@ -430,9 +426,9 @@ def nbytes(self) -> int:
430
426
def astype (self , dtype , copy = True ):
431
427
"""
432
428
Cast to a NumPy array with 'dtype'.
433
-
434
429
Parameters
435
430
----------
431
+
436
432
dtype : str or dtype
437
433
Typecode or data-type to which the array is cast.
438
434
copy : bool, default True
@@ -475,9 +471,6 @@ def _values_for_argsort(self) -> np.ndarray:
475
471
476
472
Returns
477
473
-------
478
- ndarray
479
- The transformed values should maintain the ordering between values
480
- within the array.
481
474
482
475
See Also
483
476
--------
@@ -510,8 +503,7 @@ def argsort(
510
503
511
504
See Also
512
505
--------
513
- numpy.argsort : Sorting implementation used internally.
514
- """
506
+ numpy.argsort : Sorting implementation used internally."""
515
507
# Implementor note: You have two places to override the behavior of
516
508
# argsort.
517
509
# 1. _values_for_argsort : construct the values passed to np.argsort
@@ -585,39 +577,39 @@ def dropna(self):
585
577
586
578
def shift (self , periods : int = 1 , fill_value : object = None ) -> ABCExtensionArray :
587
579
"""
588
- Shift values by desired number.
580
+ Shift values by desired number.
589
581
590
- Newly introduced missing values are filled with
591
- ``self.dtype.na_value``.
582
+ Newly introduced missing values are filled with
583
+ ``self.dtype.na_value``.
592
584
593
- .. versionadded:: 0.24.0
585
+ .. versionadded:: 0.24.0
594
586
595
- Parameters
596
- ----------
597
- periods : int, default 1
598
- The number of periods to shift. Negative values are allowed
599
- for shifting backwards.
587
+ Parameters
588
+ ----------
589
+ periods : int, default 1
590
+ The number of periods to shift. Negative values are allowed
591
+ for shifting backwards.
600
592
601
- fill_value : object, optional
602
- The scalar value to use for newly introduced missing values.
603
- The default is ``self.dtype.na_value``.
593
+ fill_value : object, optional
594
+ The scalar value to use for newly introduced missing values.
595
+ The default is ``self.dtype.na_value``.
604
596
605
- .. versionadded:: 0.24.0
597
+ .. versionadded:: 0.24.0
606
598
607
- Returns
608
- -------
609
- ExtensionArray
610
- Shifted.
599
+ Returns
600
+ -------
601
+ ExtensionArray
602
+ Shifted.
611
603
612
- Notes
613
- -----
614
- If ``self`` is empty or ``periods`` is 0, a copy of ``self`` is
615
- returned.
604
+ Notes
605
+ -----
606
+ If ``self`` is empty or ``periods`` is 0, a copy of ``self`` is
607
+ returned.
616
608
617
- If ``periods > len(self)``, then an array of size
618
- len(self) is returned, with all values filled with
619
- ``self.dtype.na_value``.
620
- """
609
+ If ``periods > len(self)``, then an array of size
610
+ len(self) is returned, with all values filled with
611
+ ``self.dtype.na_value``.
612
+ """
621
613
# Note: this implementation assumes that `self.dtype.na_value` can be
622
614
# stored in an instance of your ExtensionArray with `self.dtype`.
623
615
if not len (self ) or periods == 0 :
@@ -638,8 +630,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> ABCExtensionArra
638
630
return self ._concat_same_type ([a , b ])
639
631
640
632
def unique (self ):
641
- """
642
- Compute the ExtensionArray of unique values.
633
+ """Compute the ExtensionArray of unique values.
643
634
644
635
Returns
645
636
-------
0 commit comments