1414class JSONDtype (ExtensionDtype ):
1515 type = collections .Mapping
1616 name = 'json'
17+ na_value = {}
1718
1819 @classmethod
1920 def construct_from_string (cls , string ):
@@ -91,15 +92,30 @@ def nbytes(self):
9192 return sys .getsizeof (self .data )
9293
9394 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
103119 return self ._from_sequence (output )
104120
105121 def copy (self , deep = False ):
@@ -112,10 +128,6 @@ def unique(self):
112128 dict (x ) for x in list (set (tuple (d .items ()) for d in self .data ))
113129 ])
114130
115- @property
116- def _na_value (self ):
117- return {}
118-
119131 @classmethod
120132 def _concat_same_type (cls , to_concat ):
121133 data = list (itertools .chain .from_iterable ([x .data for x in to_concat ]))
0 commit comments