@@ -151,106 +151,176 @@ def test_to_records_with_categorical(self):
151151 {},
152152 np .rec .array (
153153 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
154- dtype = [("index" , "<i8" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
154+ dtype = [
155+ ("index" , f"{ tm .ENDIAN } i8" ),
156+ ("A" , f"{ tm .ENDIAN } i8" ),
157+ ("B" , f"{ tm .ENDIAN } f8" ),
158+ ("C" , "O" ),
159+ ],
155160 ),
156161 ),
157162 # Should have no effect in this case.
158163 (
159164 {"index" : True },
160165 np .rec .array (
161166 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
162- dtype = [("index" , "<i8" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
167+ dtype = [
168+ ("index" , f"{ tm .ENDIAN } i8" ),
169+ ("A" , f"{ tm .ENDIAN } i8" ),
170+ ("B" , f"{ tm .ENDIAN } f8" ),
171+ ("C" , "O" ),
172+ ],
163173 ),
164174 ),
165175 # Column dtype applied across the board. Index unaffected.
166176 (
167- {"column_dtypes" : "< U4" },
177+ {"column_dtypes" : f" { tm . ENDIAN } U4" },
168178 np .rec .array (
169179 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
170- dtype = [("index" , "<i8" ), ("A" , "<U4" ), ("B" , "<U4" ), ("C" , "<U4" )],
180+ dtype = [
181+ ("index" , f"{ tm .ENDIAN } i8" ),
182+ ("A" , f"{ tm .ENDIAN } U4" ),
183+ ("B" , f"{ tm .ENDIAN } U4" ),
184+ ("C" , f"{ tm .ENDIAN } U4" ),
185+ ],
171186 ),
172187 ),
173188 # Index dtype applied across the board. Columns unaffected.
174189 (
175- {"index_dtypes" : "< U1" },
190+ {"index_dtypes" : f" { tm . ENDIAN } U1" },
176191 np .rec .array (
177192 [("0" , 1 , 0.2 , "a" ), ("1" , 2 , 1.5 , "bc" )],
178- dtype = [("index" , "<U1" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
193+ dtype = [
194+ ("index" , f"{ tm .ENDIAN } U1" ),
195+ ("A" , f"{ tm .ENDIAN } i8" ),
196+ ("B" , f"{ tm .ENDIAN } f8" ),
197+ ("C" , "O" ),
198+ ],
179199 ),
180200 ),
181201 # Pass in a type instance.
182202 (
183203 {"column_dtypes" : str },
184204 np .rec .array (
185205 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
186- dtype = [("index" , "<i8" ), ("A" , "<U" ), ("B" , "<U" ), ("C" , "<U" )],
206+ dtype = [
207+ ("index" , f"{ tm .ENDIAN } i8" ),
208+ ("A" , f"{ tm .ENDIAN } U" ),
209+ ("B" , f"{ tm .ENDIAN } U" ),
210+ ("C" , f"{ tm .ENDIAN } U" ),
211+ ],
187212 ),
188213 ),
189214 # Pass in a dtype instance.
190215 (
191216 {"column_dtypes" : np .dtype ("unicode" )},
192217 np .rec .array (
193218 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
194- dtype = [("index" , "<i8" ), ("A" , "<U" ), ("B" , "<U" ), ("C" , "<U" )],
219+ dtype = [
220+ ("index" , f"{ tm .ENDIAN } i8" ),
221+ ("A" , f"{ tm .ENDIAN } U" ),
222+ ("B" , f"{ tm .ENDIAN } U" ),
223+ ("C" , f"{ tm .ENDIAN } U" ),
224+ ],
195225 ),
196226 ),
197227 # Pass in a dictionary (name-only).
198228 (
199- {"column_dtypes" : {"A" : np .int8 , "B" : np .float32 , "C" : "<U2" }},
229+ {
230+ "column_dtypes" : {
231+ "A" : np .int8 ,
232+ "B" : np .float32 ,
233+ "C" : f"{ tm .ENDIAN } U2" ,
234+ }
235+ },
200236 np .rec .array (
201237 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
202- dtype = [("index" , "<i8" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "<U2" )],
238+ dtype = [
239+ ("index" , f"{ tm .ENDIAN } i8" ),
240+ ("A" , "i1" ),
241+ ("B" , f"{ tm .ENDIAN } f4" ),
242+ ("C" , f"{ tm .ENDIAN } U2" ),
243+ ],
203244 ),
204245 ),
205246 # Pass in a dictionary (indices-only).
206247 (
207248 {"index_dtypes" : {0 : "int16" }},
208249 np .rec .array (
209250 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
210- dtype = [("index" , "i2" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
251+ dtype = [
252+ ("index" , "i2" ),
253+ ("A" , f"{ tm .ENDIAN } i8" ),
254+ ("B" , f"{ tm .ENDIAN } f8" ),
255+ ("C" , "O" ),
256+ ],
211257 ),
212258 ),
213259 # Ignore index mappings if index is not True.
214260 (
215- {"index" : False , "index_dtypes" : "< U2" },
261+ {"index" : False , "index_dtypes" : f" { tm . ENDIAN } U2" },
216262 np .rec .array (
217263 [(1 , 0.2 , "a" ), (2 , 1.5 , "bc" )],
218- dtype = [("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
264+ dtype = [
265+ ("A" , f"{ tm .ENDIAN } i8" ),
266+ ("B" , f"{ tm .ENDIAN } f8" ),
267+ ("C" , "O" ),
268+ ],
219269 ),
220270 ),
221271 # Non-existent names / indices in mapping should not error.
222272 (
223273 {"index_dtypes" : {0 : "int16" , "not-there" : "float32" }},
224274 np .rec .array (
225275 [(0 , 1 , 0.2 , "a" ), (1 , 2 , 1.5 , "bc" )],
226- dtype = [("index" , "i2" ), ("A" , "<i8" ), ("B" , "<f8" ), ("C" , "O" )],
276+ dtype = [
277+ ("index" , "i2" ),
278+ ("A" , f"{ tm .ENDIAN } i8" ),
279+ ("B" , f"{ tm .ENDIAN } f8" ),
280+ ("C" , "O" ),
281+ ],
227282 ),
228283 ),
229284 # Names / indices not in mapping default to array dtype.
230285 (
231286 {"column_dtypes" : {"A" : np .int8 , "B" : np .float32 }},
232287 np .rec .array (
233288 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
234- dtype = [("index" , "<i8" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
289+ dtype = [
290+ ("index" , f"{ tm .ENDIAN } i8" ),
291+ ("A" , "i1" ),
292+ ("B" , f"{ tm .ENDIAN } f4" ),
293+ ("C" , "O" ),
294+ ],
235295 ),
236296 ),
237297 # Names / indices not in dtype mapping default to array dtype.
238298 (
239299 {"column_dtypes" : {"A" : np .dtype ("int8" ), "B" : np .dtype ("float32" )}},
240300 np .rec .array (
241301 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
242- dtype = [("index" , "<i8" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
302+ dtype = [
303+ ("index" , f"{ tm .ENDIAN } i8" ),
304+ ("A" , "i1" ),
305+ ("B" , f"{ tm .ENDIAN } f4" ),
306+ ("C" , "O" ),
307+ ],
243308 ),
244309 ),
245310 # Mixture of everything.
246311 (
247312 {
248313 "column_dtypes" : {"A" : np .int8 , "B" : np .float32 },
249- "index_dtypes" : "< U2" ,
314+ "index_dtypes" : f" { tm . ENDIAN } U2" ,
250315 },
251316 np .rec .array (
252317 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
253- dtype = [("index" , "<U2" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
318+ dtype = [
319+ ("index" , f"{ tm .ENDIAN } U2" ),
320+ ("A" , "i1" ),
321+ ("B" , f"{ tm .ENDIAN } f4" ),
322+ ("C" , "O" ),
323+ ],
254324 ),
255325 ),
256326 # Invalid dype values.
@@ -299,7 +369,11 @@ def test_to_records_dtype(self, kwargs, expected):
299369 {"column_dtypes" : "float64" , "index_dtypes" : {0 : "int32" , 1 : "int8" }},
300370 np .rec .array (
301371 [(1 , 2 , 3.0 ), (4 , 5 , 6.0 ), (7 , 8 , 9.0 )],
302- dtype = [("a" , "<i4" ), ("b" , "i1" ), ("c" , "<f8" )],
372+ dtype = [
373+ ("a" , f"{ tm .ENDIAN } i4" ),
374+ ("b" , "i1" ),
375+ ("c" , f"{ tm .ENDIAN } f8" ),
376+ ],
303377 ),
304378 ),
305379 # MultiIndex in the columns.
@@ -310,14 +384,17 @@ def test_to_records_dtype(self, kwargs, expected):
310384 [("a" , "d" ), ("b" , "e" ), ("c" , "f" )]
311385 ),
312386 ),
313- {"column_dtypes" : {0 : "<U1" , 2 : "float32" }, "index_dtypes" : "float32" },
387+ {
388+ "column_dtypes" : {0 : f"{ tm .ENDIAN } U1" , 2 : "float32" },
389+ "index_dtypes" : "float32" ,
390+ },
314391 np .rec .array (
315392 [(0.0 , "1" , 2 , 3.0 ), (1.0 , "4" , 5 , 6.0 ), (2.0 , "7" , 8 , 9.0 )],
316393 dtype = [
317- ("index" , "< f4" ),
318- ("('a', 'd')" , "< U1" ),
319- ("('b', 'e')" , "< i8" ),
320- ("('c', 'f')" , "< f4" ),
394+ ("index" , f" { tm . ENDIAN } f4" ),
395+ ("('a', 'd')" , f" { tm . ENDIAN } U1" ),
396+ ("('b', 'e')" , f" { tm . ENDIAN } i8" ),
397+ ("('c', 'f')" , f" { tm . ENDIAN } f4" ),
321398 ],
322399 ),
323400 ),
@@ -332,19 +409,22 @@ def test_to_records_dtype(self, kwargs, expected):
332409 [("d" , - 4 ), ("d" , - 5 ), ("f" , - 6 )], names = list ("cd" )
333410 ),
334411 ),
335- {"column_dtypes" : "float64" , "index_dtypes" : {0 : "<U2" , 1 : "int8" }},
412+ {
413+ "column_dtypes" : "float64" ,
414+ "index_dtypes" : {0 : f"{ tm .ENDIAN } U2" , 1 : "int8" },
415+ },
336416 np .rec .array (
337417 [
338418 ("d" , - 4 , 1.0 , 2.0 , 3.0 ),
339419 ("d" , - 5 , 4.0 , 5.0 , 6.0 ),
340420 ("f" , - 6 , 7 , 8 , 9.0 ),
341421 ],
342422 dtype = [
343- ("c" , "< U2" ),
423+ ("c" , f" { tm . ENDIAN } U2" ),
344424 ("d" , "i1" ),
345- ("('a', 'd')" , "< f8" ),
346- ("('b', 'e')" , "< f8" ),
347- ("('c', 'f')" , "< f8" ),
425+ ("('a', 'd')" , f" { tm . ENDIAN } f8" ),
426+ ("('b', 'e')" , f" { tm . ENDIAN } f8" ),
427+ ("('c', 'f')" , f" { tm . ENDIAN } f8" ),
348428 ],
349429 ),
350430 ),
@@ -374,13 +454,18 @@ def keys(self):
374454
375455 dtype_mappings = {
376456 "column_dtypes" : DictLike (** {"A" : np .int8 , "B" : np .float32 }),
377- "index_dtypes" : "< U2" ,
457+ "index_dtypes" : f" { tm . ENDIAN } U2" ,
378458 }
379459
380460 result = df .to_records (** dtype_mappings )
381461 expected = np .rec .array (
382462 [("0" , "1" , "0.2" , "a" ), ("1" , "2" , "1.5" , "bc" )],
383- dtype = [("index" , "<U2" ), ("A" , "i1" ), ("B" , "<f4" ), ("C" , "O" )],
463+ dtype = [
464+ ("index" , f"{ tm .ENDIAN } U2" ),
465+ ("A" , "i1" ),
466+ ("B" , f"{ tm .ENDIAN } f4" ),
467+ ("C" , "O" ),
468+ ],
384469 )
385470 tm .assert_almost_equal (result , expected )
386471
0 commit comments