File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 4
4
5
5
from pandas .compat .numpy import function as nv
6
6
from pandas .errors import AbstractMethodError
7
+ from pandas .util ._decorators import cache_readonly
7
8
8
9
from pandas .core .algorithms import take , unique
9
10
from pandas .core .arrays .base import ExtensionArray
@@ -64,22 +65,24 @@ def _validate_fill_value(self, fill_value):
64
65
65
66
# ------------------------------------------------------------------------
66
67
68
+ # TODO: make this a cache_readonly; for that to work we need to remove
69
+ # the _index_data kludge in libreduction
67
70
@property
68
71
def shape (self ) -> Tuple [int , ...]:
69
72
return self ._ndarray .shape
70
73
71
74
def __len__ (self ) -> int :
72
75
return self .shape [0 ]
73
76
74
- @property
77
+ @cache_readonly
75
78
def ndim (self ) -> int :
76
79
return len (self .shape )
77
80
78
- @property
81
+ @cache_readonly
79
82
def size (self ) -> int :
80
83
return np .prod (self .shape )
81
84
82
- @property
85
+ @cache_readonly
83
86
def nbytes (self ) -> int :
84
87
return self ._ndarray .nbytes
85
88
Original file line number Diff line number Diff line change @@ -454,6 +454,8 @@ class DatetimeLikeArrayMixin(
454
454
# ------------------------------------------------------------------
455
455
# NDArrayBackedExtensionArray compat
456
456
457
+ # TODO: make this a cache_readonly; need to get around _index_data
458
+ # kludge in libreduction
457
459
@property
458
460
def _ndarray (self ) -> np .ndarray :
459
461
# NB: A bunch of Interval tests fail if we use ._data
@@ -526,6 +528,13 @@ def __getitem__(self, key):
526
528
only handle list-likes, slices, and integer scalars
527
529
"""
528
530
531
+ if lib .is_integer (key ):
532
+ # fast-path
533
+ result = self ._data [key ]
534
+ if self .ndim == 1 :
535
+ return self ._box_func (result )
536
+ return self ._simple_new (result , dtype = self .dtype )
537
+
529
538
if com .is_bool_indexer (key ):
530
539
# first convert to boolean, because check_array_indexer doesn't
531
540
# allow object dtype
You can’t perform that action at this time.
0 commit comments