Fix ArrayXD cast
State: closed | Author: mariosasko (COLLABORATOR)

Fix #6291 

Comments: <details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006920 / 0.011353 (-0.004433) | 0.004306 / 0.011008 (-0.006703) | 0.085961 / 0.038508 (0.047453) | 0.087008 / 0.023109 (0.063899) | 0.308953 / 0.275898 (0.033055) | 0.349919 / 0.323480 (0.026440) | 0.005705 / 0.007986 (-0.002281) | 0.003565 / 0.004328 (-0.000763) | 0.066272 / 0.004250 (0.062022) | 0.056438 / 0.037052 (0.019385) | 0.312927 / 0.258489 (0.054437) | 0.363081 / 0.293841 (0.069240) | 0.031947 / 0.128546 (-0.096600) | 0.008801 / 0.075646 (-0.066845) | 0.288657 / 0.419271 (-0.130615) | 0.053746 / 0.043533 (0.010213) | 0.305815 / 0.255139 (0.050676) | 0.327174 / 0.283200 (0.043975) | 0.024863 / 0.141683 (-0.116820) | 1.489718 / 1.452155 (0.037563) | 1.566726 / 1.492716 (0.074009) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.289273 / 0.018006 (0.271266) | 0.555519 / 0.000490 (0.555029) | 0.006522 / 0.000200 (0.006322) | 0.000105 / 0.000054 (0.000051) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.031968 / 0.037411 (-0.005443) | 0.085113 / 0.014526 (0.070587) | 0.103931 / 0.176557 (-0.072625) | 0.158471 / 0.737135 (-0.578665) | 0.102633 / 0.296338 (-0.193705) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.399592 / 0.215209 (0.184383) | 4.004453 / 2.077655 (1.926798) | 2.047224 / 1.504120 (0.543104) | 1.896203 / 1.541195 (0.355008) | 1.974056 / 1.468490 (0.505566) | 0.485964 / 4.584777 (-4.098813) | 3.650648 / 3.745712 (-0.095064) | 3.475953 / 5.269862 (-1.793908) | 2.168105 / 4.565676 (-2.397571) | 0.058167 / 0.424275 (-0.366108) | 0.007517 / 0.007607 (-0.000090) | 0.475386 / 0.226044 (0.249342) | 4.758300 / 2.268929 (2.489372) | 2.527540 / 55.444624 (-52.917085) | 2.180544 / 6.876477 (-4.695933) | 2.460148 / 2.142072 (0.318076) | 0.589944 / 4.805227 (-4.215284) | 0.136474 / 6.500664 (-6.364190) | 0.061462 / 0.075469 (-0.014007) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.245816 / 1.841788 (-0.595972) | 20.376958 / 8.074308 (12.302650) | 14.764579 / 10.191392 (4.573187) | 0.152436 / 0.680424 (-0.527988) | 0.018580 / 0.534201 (-0.515621) | 0.394680 / 0.579283 (-0.184603) | 0.424162 / 0.434364 (-0.010202) | 0.465604 / 0.540337 (-0.074733) | 0.658531 / 1.386936 (-0.728405) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.007105 / 0.011353 (-0.004248) | 0.004441 / 0.011008 (-0.006567) | 0.068792 / 0.038508 (0.030284) | 0.080371 / 0.023109 (0.057262) | 0.430263 / 0.275898 (0.154365) | 0.451743 / 0.323480 (0.128263) | 0.005987 / 0.007986 (-0.001999) | 0.003639 / 0.004328 (-0.000690) | 0.065462 / 0.004250 (0.061212) | 0.059852 / 0.037052 (0.022800) | 0.438390 / 0.258489 (0.179901) | 0.458679 / 0.293841 (0.164838) | 0.033044 / 0.128546 (-0.095502) | 0.008845 / 0.075646 (-0.066802) | 0.071772 / 0.419271 (-0.347500) | 0.048840 / 0.043533 (0.005307) | 0.415707 / 0.255139 (0.160568) | 0.431216 / 0.283200 (0.148017) | 0.024422 / 0.141683 (-0.117260) | 1.502249 / 1.452155 (0.050094) | 1.566767 / 1.492716 (0.074050) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.311352 / 0.018006 (0.293346) | 0.550395 / 0.000490 (0.549906) | 0.005190 / 0.000200 (0.004990) | 0.000116 / 0.000054 (0.000062) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.034264 / 0.037411 (-0.003147) | 0.098712 / 0.014526 (0.084186) | 0.110906 / 0.176557 (-0.065651) | 0.161670 / 0.737135 (-0.575465) | 0.111023 / 0.296338 (-0.185316) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.435296 / 0.215209 (0.220087) | 4.331231 / 2.077655 (2.253576) | 2.305009 / 1.504120 (0.800889) | 2.154492 / 1.541195 (0.613297) | 2.344017 / 1.468490 (0.875527) | 0.496924 / 4.584777 (-4.087853) | 3.750782 / 3.745712 (0.005070) | 3.380193 / 5.269862 (-1.889669) | 2.161239 / 4.565676 (-2.404438) | 0.058456 / 0.424275 (-0.365819) | 0.007395 / 0.007607 (-0.000212) | 0.507824 / 0.226044 (0.281780) | 5.081564 / 2.268929 (2.812635) | 2.824080 / 55.444624 (-52.620544) | 2.458835 / 6.876477 (-4.417642) | 2.747897 / 2.142072 (0.605824) | 0.600727 / 4.805227 (-4.204500) | 0.135085 / 6.500664 (-6.365579) | 0.060506 / 0.075469 (-0.014963) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.376873 / 1.841788 (-0.464915) | 21.211922 / 8.074308 (13.137614) | 15.022845 / 10.191392 (4.831453) | 0.195388 / 0.680424 (-0.485036) | 0.020268 / 0.534201 (-0.513933) | 0.398971 / 0.579283 (-0.180312) | 0.427588 / 0.434364 (-0.006776) | 0.478044 / 0.540337 (-0.062293) | 0.687904 / 1.386936 (-0.699033) |

</details>
</details>

![](https://cml.dev/watermark.png#7fb5fae8f79b3db4a94013aa2af7c63796ef2d64 "CML watermark")


<details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006134 / 0.011353 (-0.005219) | 0.003655 / 0.011008 (-0.007354) | 0.081295 / 0.038508 (0.042787) | 0.060202 / 0.023109 (0.037093) | 0.330005 / 0.275898 (0.054107) | 0.361219 / 0.323480 (0.037739) | 0.004766 / 0.007986 (-0.003220) | 0.002942 / 0.004328 (-0.001386) | 0.063322 / 0.004250 (0.059072) | 0.047844 / 0.037052 (0.010791) | 0.340375 / 0.258489 (0.081886) | 0.406301 / 0.293841 (0.112460) | 0.027474 / 0.128546 (-0.101072) | 0.007991 / 0.075646 (-0.067655) | 0.262746 / 0.419271 (-0.156526) | 0.045575 / 0.043533 (0.002042) | 0.324123 / 0.255139 (0.068984) | 0.344399 / 0.283200 (0.061199) | 0.021806 / 0.141683 (-0.119877) | 1.425390 / 1.452155 (-0.026765) | 1.487920 / 1.492716 (-0.004796) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.217504 / 0.018006 (0.199498) | 0.420878 / 0.000490 (0.420388) | 0.007312 / 0.000200 (0.007112) | 0.000218 / 0.000054 (0.000163) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.023507 / 0.037411 (-0.013905) | 0.073493 / 0.014526 (0.058967) | 0.084857 / 0.176557 (-0.091700) | 0.145130 / 0.737135 (-0.592005) | 0.085204 / 0.296338 (-0.211135) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.388767 / 0.215209 (0.173557) | 3.877998 / 2.077655 (1.800344) | 1.881447 / 1.504120 (0.377327) | 1.714555 / 1.541195 (0.173360) | 1.772551 / 1.468490 (0.304061) | 0.505146 / 4.584777 (-4.079631) | 3.045471 / 3.745712 (-0.700241) | 2.834436 / 5.269862 (-2.435426) | 1.859896 / 4.565676 (-2.705780) | 0.057806 / 0.424275 (-0.366469) | 0.006378 / 0.007607 (-0.001229) | 0.458339 / 0.226044 (0.232294) | 4.588125 / 2.268929 (2.319196) | 2.302215 / 55.444624 (-53.142409) | 1.981297 / 6.876477 (-4.895180) | 2.152967 / 2.142072 (0.010895) | 0.590166 / 4.805227 (-4.215061) | 0.125753 / 6.500664 (-6.374911) | 0.061583 / 0.075469 (-0.013887) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.232195 / 1.841788 (-0.609593) | 17.761159 / 8.074308 (9.686851) | 13.829498 / 10.191392 (3.638106) | 0.131936 / 0.680424 (-0.548488) | 0.016909 / 0.534201 (-0.517292) | 0.332615 / 0.579283 (-0.246668) | 0.358149 / 0.434364 (-0.076215) | 0.384251 / 0.540337 (-0.156087) | 0.536453 / 1.386936 (-0.850483) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006253 / 0.011353 (-0.005100) | 0.003639 / 0.011008 (-0.007370) | 0.062810 / 0.038508 (0.024302) | 0.063761 / 0.023109 (0.040652) | 0.450538 / 0.275898 (0.174640) | 0.483793 / 0.323480 (0.160313) | 0.004973 / 0.007986 (-0.003013) | 0.002918 / 0.004328 (-0.001411) | 0.062140 / 0.004250 (0.057889) | 0.050328 / 0.037052 (0.013275) | 0.455860 / 0.258489 (0.197371) | 0.492399 / 0.293841 (0.198558) | 0.028928 / 0.128546 (-0.099618) | 0.008166 / 0.075646 (-0.067481) | 0.067860 / 0.419271 (-0.351411) | 0.040990 / 0.043533 (-0.002542) | 0.451343 / 0.255139 (0.196204) | 0.473769 / 0.283200 (0.190569) | 0.021585 / 0.141683 (-0.120097) | 1.451040 / 1.452155 (-0.001115) | 1.516065 / 1.492716 (0.023349) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.230994 / 0.018006 (0.212988) | 0.428404 / 0.000490 (0.427915) | 0.003777 / 0.000200 (0.003577) | 0.000074 / 0.000054 (0.000020) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.027394 / 0.037411 (-0.010018) | 0.081692 / 0.014526 (0.067166) | 0.091568 / 0.176557 (-0.084988) | 0.146149 / 0.737135 (-0.590987) | 0.092200 / 0.296338 (-0.204139) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.467086 / 0.215209 (0.251877) | 4.664862 / 2.077655 (2.587207) | 2.575703 / 1.504120 (1.071583) | 2.396587 / 1.541195 (0.855392) | 2.506064 / 1.468490 (1.037574) | 0.511942 / 4.584777 (-4.072834) | 3.196320 / 3.745712 (-0.549392) | 2.916627 / 5.269862 (-2.353235) | 1.919372 / 4.565676 (-2.646305) | 0.058769 / 0.424275 (-0.365506) | 0.006487 / 0.007607 (-0.001120) | 0.539095 / 0.226044 (0.313051) | 5.404675 / 2.268929 (3.135746) | 2.988962 / 55.444624 (-52.455662) | 2.670134 / 6.876477 (-4.206343) | 2.837414 / 2.142072 (0.695342) | 0.614776 / 4.805227 (-4.190451) | 0.125806 / 6.500664 (-6.374858) | 0.061593 / 0.075469 (-0.013876) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.346171 / 1.841788 (-0.495617) | 18.374626 / 8.074308 (10.300318) | 14.508723 / 10.191392 (4.317331) | 0.146771 / 0.680424 (-0.533652) | 0.018438 / 0.534201 (-0.515763) | 0.336944 / 0.579283 (-0.242339) | 0.385631 / 0.434364 (-0.048733) | 0.391922 / 0.540337 (-0.148416) | 0.568904 / 1.386936 (-0.818032) |

</details>
</details>

![](https://cml.dev/watermark.png#3e8d420808718c9a1453a2e7ee3484ca12c9c70d "CML watermark")