14
14
class JSONDtype (ExtensionDtype ):
15
15
type = collections .Mapping
16
16
name = 'json'
17
+ na_value = {}
17
18
18
19
@classmethod
19
20
def construct_from_string (cls , string ):
@@ -91,15 +92,30 @@ def nbytes(self):
91
92
return sys .getsizeof (self .data )
92
93
93
94
def isna (self ):
94
- return np .array ([x == self ._na_value for x in self .data ])
95
-
96
- def take (self , indexer , allow_fill = True , fill_value = None ):
97
- try :
98
- output = [self .data [loc ] if loc != - 1 else self ._na_value
99
- for loc in indexer ]
100
- except IndexError :
101
- raise IndexError ("Index is out of bounds or cannot do a "
102
- "non-empty take from an empty array." )
95
+ return np .array ([x == self .dtype .na_value for x in self .data ])
96
+
97
+ def take (self , indexer , fill_value = None ):
98
+ # re-implement here, since NumPy has trouble setting
99
+ # sized objects like UserDicts into scalar slots of
100
+ # an ndarary.
101
+ indexer = np .asarray (indexer )
102
+ msg = ("Index is out of bounds or cannot do a "
103
+ "non-empty take from an empty array." )
104
+
105
+ if fill_value is None :
106
+ try :
107
+ output = [self .data [loc ] for loc in indexer ]
108
+ except IndexError :
109
+ raise IndexError (msg )
110
+ else :
111
+ # bounds check
112
+ if (indexer < - 1 ).any ():
113
+ raise ValueError
114
+ try :
115
+ output = [self .data [loc ] if loc != - 1 else fill_value
116
+ for loc in indexer ]
117
+ except IndexError :
118
+ raise msg
103
119
return self ._from_sequence (output )
104
120
105
121
def copy (self , deep = False ):
@@ -112,10 +128,6 @@ def unique(self):
112
128
dict (x ) for x in list (set (tuple (d .items ()) for d in self .data ))
113
129
])
114
130
115
- @property
116
- def _na_value (self ):
117
- return {}
118
-
119
131
@classmethod
120
132
def _concat_same_type (cls , to_concat ):
121
133
data = list (itertools .chain .from_iterable ([x .data for x in to_concat ]))
0 commit comments