@@ -87,15 +87,18 @@ def to_records(self, df):
87
87
arrays = map (_to_primitive , arrays )
88
88
dtype = np .dtype ([(str (x ), v .dtype ) if len (v .shape ) == 1 else (str (x ), v .dtype , v .shape [1 ]) for x , v in zip (names , arrays )],
89
89
metadata = metadata )
90
+
90
91
rtn = np .rec .fromarrays (arrays , dtype = dtype , names = names )
91
- #For some reason the dtype metadata is lost in the line above.
92
- rtn .dtype = dtype
93
- return rtn
92
+ # For some reason the dtype metadata is lost in the line above
93
+ # and setting rtn.dtype to dtype does not preserve the metadata
94
+ # see https://github.com/numpy/numpy/issues/6771
95
+
96
+ return (rtn , dtype )
94
97
95
98
def can_convert_to_records_without_objects (self , df , symbol ):
96
99
# We can't easily distinguish string columns from objects
97
100
try :
98
- arr = self .to_records (df )
101
+ arr , _ = self .to_records (df )
99
102
except Exception as e :
100
103
# This exception will also occur when we try to write the object so we fall-back to saving using Pickle
101
104
log .info ('Pandas dataframe %s caused exception "%s" when attempting to convert to records. Saving as Blob.'
@@ -249,12 +252,12 @@ def can_write(self, version, symbol, data):
249
252
return False
250
253
251
254
def write (self , arctic_lib , version , symbol , item , previous_version ):
252
- item = self .to_records (item )
253
- super (PandasSeriesStore , self ).write (arctic_lib , version , symbol , item , previous_version )
255
+ item , md = self .to_records (item )
256
+ super (PandasSeriesStore , self ).write (arctic_lib , version , symbol , item , previous_version , dtype = md )
254
257
255
258
def append (self , arctic_lib , version , symbol , item , previous_version ):
256
- item = self .to_records (item )
257
- super (PandasSeriesStore , self ).append (arctic_lib , version , symbol , item , previous_version )
259
+ item , md = self .to_records (item )
260
+ super (PandasSeriesStore , self ).append (arctic_lib , version , symbol , item , previous_version , dtype = md )
258
261
259
262
def read (self , arctic_lib , version , symbol , ** kwargs ):
260
263
item = super (PandasSeriesStore , self ).read (arctic_lib , version , symbol , ** kwargs )
@@ -287,12 +290,12 @@ def can_write(self, version, symbol, data):
287
290
return False
288
291
289
292
def write (self , arctic_lib , version , symbol , item , previous_version ):
290
- item = self .to_records (item )
291
- super (PandasDataFrameStore , self ).write (arctic_lib , version , symbol , item , previous_version )
293
+ item , md = self .to_records (item )
294
+ super (PandasDataFrameStore , self ).write (arctic_lib , version , symbol , item , previous_version , dtype = md )
292
295
293
296
def append (self , arctic_lib , version , symbol , item , previous_version ):
294
- item = self .to_records (item )
295
- super (PandasDataFrameStore , self ).append (arctic_lib , version , symbol , item , previous_version )
297
+ item , md = self .to_records (item )
298
+ super (PandasDataFrameStore , self ).append (arctic_lib , version , symbol , item , previous_version , dtype = md )
296
299
297
300
def read (self , arctic_lib , version , symbol , ** kwargs ):
298
301
item = super (PandasDataFrameStore , self ).read (arctic_lib , version , symbol , ** kwargs )
0 commit comments