@@ -151,106 +151,176 @@ def test_to_records_with_categorical(self):
151
151
{},
152
152
np .rec .array (
153
153
[(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
+ ],
155
160
),
156
161
),
157
162
# Should have no effect in this case.
158
163
(
159
164
{"index" : True },
160
165
np .rec .array (
161
166
[(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
+ ],
163
173
),
164
174
),
165
175
# Column dtype applied across the board. Index unaffected.
166
176
(
167
- {"column_dtypes" : "< U4" },
177
+ {"column_dtypes" : f" { tm . ENDIAN } U4" },
168
178
np .rec .array (
169
179
[("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
+ ],
171
186
),
172
187
),
173
188
# Index dtype applied across the board. Columns unaffected.
174
189
(
175
- {"index_dtypes" : "< U1" },
190
+ {"index_dtypes" : f" { tm . ENDIAN } U1" },
176
191
np .rec .array (
177
192
[("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
+ ],
179
199
),
180
200
),
181
201
# Pass in a type instance.
182
202
(
183
203
{"column_dtypes" : str },
184
204
np .rec .array (
185
205
[("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
+ ],
187
212
),
188
213
),
189
214
# Pass in a dtype instance.
190
215
(
191
216
{"column_dtypes" : np .dtype ("unicode" )},
192
217
np .rec .array (
193
218
[("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
+ ],
195
225
),
196
226
),
197
227
# Pass in a dictionary (name-only).
198
228
(
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
+ },
200
236
np .rec .array (
201
237
[("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
+ ],
203
244
),
204
245
),
205
246
# Pass in a dictionary (indices-only).
206
247
(
207
248
{"index_dtypes" : {0 : "int16" }},
208
249
np .rec .array (
209
250
[(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
+ ],
211
257
),
212
258
),
213
259
# Ignore index mappings if index is not True.
214
260
(
215
- {"index" : False , "index_dtypes" : "< U2" },
261
+ {"index" : False , "index_dtypes" : f" { tm . ENDIAN } U2" },
216
262
np .rec .array (
217
263
[(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
+ ],
219
269
),
220
270
),
221
271
# Non-existent names / indices in mapping should not error.
222
272
(
223
273
{"index_dtypes" : {0 : "int16" , "not-there" : "float32" }},
224
274
np .rec .array (
225
275
[(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
+ ],
227
282
),
228
283
),
229
284
# Names / indices not in mapping default to array dtype.
230
285
(
231
286
{"column_dtypes" : {"A" : np .int8 , "B" : np .float32 }},
232
287
np .rec .array (
233
288
[("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
+ ],
235
295
),
236
296
),
237
297
# Names / indices not in dtype mapping default to array dtype.
238
298
(
239
299
{"column_dtypes" : {"A" : np .dtype ("int8" ), "B" : np .dtype ("float32" )}},
240
300
np .rec .array (
241
301
[("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
+ ],
243
308
),
244
309
),
245
310
# Mixture of everything.
246
311
(
247
312
{
248
313
"column_dtypes" : {"A" : np .int8 , "B" : np .float32 },
249
- "index_dtypes" : "< U2" ,
314
+ "index_dtypes" : f" { tm . ENDIAN } U2" ,
250
315
},
251
316
np .rec .array (
252
317
[("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
+ ],
254
324
),
255
325
),
256
326
# Invalid dype values.
@@ -299,7 +369,11 @@ def test_to_records_dtype(self, kwargs, expected):
299
369
{"column_dtypes" : "float64" , "index_dtypes" : {0 : "int32" , 1 : "int8" }},
300
370
np .rec .array (
301
371
[(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
+ ],
303
377
),
304
378
),
305
379
# MultiIndex in the columns.
@@ -310,14 +384,17 @@ def test_to_records_dtype(self, kwargs, expected):
310
384
[("a" , "d" ), ("b" , "e" ), ("c" , "f" )]
311
385
),
312
386
),
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
+ },
314
391
np .rec .array (
315
392
[(0.0 , "1" , 2 , 3.0 ), (1.0 , "4" , 5 , 6.0 ), (2.0 , "7" , 8 , 9.0 )],
316
393
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" ),
321
398
],
322
399
),
323
400
),
@@ -332,19 +409,22 @@ def test_to_records_dtype(self, kwargs, expected):
332
409
[("d" , - 4 ), ("d" , - 5 ), ("f" , - 6 )], names = list ("cd" )
333
410
),
334
411
),
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
+ },
336
416
np .rec .array (
337
417
[
338
418
("d" , - 4 , 1.0 , 2.0 , 3.0 ),
339
419
("d" , - 5 , 4.0 , 5.0 , 6.0 ),
340
420
("f" , - 6 , 7 , 8 , 9.0 ),
341
421
],
342
422
dtype = [
343
- ("c" , "< U2" ),
423
+ ("c" , f" { tm . ENDIAN } U2" ),
344
424
("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" ),
348
428
],
349
429
),
350
430
),
@@ -374,13 +454,18 @@ def keys(self):
374
454
375
455
dtype_mappings = {
376
456
"column_dtypes" : DictLike (** {"A" : np .int8 , "B" : np .float32 }),
377
- "index_dtypes" : "< U2" ,
457
+ "index_dtypes" : f" { tm . ENDIAN } U2" ,
378
458
}
379
459
380
460
result = df .to_records (** dtype_mappings )
381
461
expected = np .rec .array (
382
462
[("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
+ ],
384
469
)
385
470
tm .assert_almost_equal (result , expected )
386
471
0 commit comments