Expanduser in save_to_disk()
_The documentation is not available anymore as the PR was closed or merged._ > I am not sure why the case distinction between local and remote filesystems is even necessary for DatasetDict when saving to disk. Imo this could be removed (leaving only fs.makedirs(dataset_dict_path, exist_ok=True)).

Indeed. But it's better to address this in a separate PR. <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.007696 / 0.011353 (-0.003656) | 0.004497 / 0.011008 (-0.006511) | 0.099302 / 0.038508 (0.060794) | 0.083360 / 0.023109 (0.060251) | 0.393483 / 0.275898 (0.117585) | 0.450505 / 0.323480 (0.127025) | 0.004610 / 0.007986 (-0.003376) | 0.003637 / 0.004328 (-0.000692) | 0.075752 / 0.004250 (0.071501) | 0.064034 / 0.037052 (0.026982) | 0.397785 / 0.258489 (0.139296) | 0.462948 / 0.293841 (0.169107) | 0.035902 / 0.128546 (-0.092644) | 0.009640 / 0.075646 (-0.066007) | 0.342299 / 0.419271 (-0.076973) | 0.059586 / 0.043533 (0.016053) | 0.404918 / 0.255139 (0.149779) | 0.440889 / 0.283200 (0.157690) | 0.028981 / 0.141683 (-0.112702) | 1.775380 / 1.452155 (0.323226) | 1.866663 / 1.492716 (0.373946) |

### 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.249080 / 0.018006 (0.231074) | 0.456460 / 0.000490 (0.455970) | 0.028145 / 0.000200 (0.027945) | 0.000402 / 0.000054 (0.000347) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.030373 / 0.037411 (-0.007038) | 0.088562 / 0.014526 (0.074036) | 0.122837 / 0.176557 (-0.053720) | 0.167122 / 0.737135 (-0.570014) | 0.103953 / 0.296338 (-0.192385) |

### 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.431714 / 0.215209 (0.216505) | 4.182224 / 2.077655 (2.104570) | 2.025650 / 1.504120 (0.521530) | 1.838905 / 1.541195 (0.297710) | 1.868710 / 1.468490 (0.400219) | 0.538422 / 4.584777 (-4.046355) | 4.038941 / 3.745712 (0.293228) | 3.717695 / 5.269862 (-1.552166) | 2.313197 / 4.565676 (-2.252479) | 0.061060 / 0.424275 (-0.363215) | 0.008248 / 0.007607 (0.000641) | 0.497438 / 0.226044 (0.271394) | 4.946663 / 2.268929 (2.677734) | 2.571841 / 55.444624 (-52.872784) | 2.155894 / 6.876477 (-4.720583) | 2.183180 / 2.142072 (0.041107) | 0.639810 / 4.805227 (-4.165417) | 0.153273 / 6.500664 (-6.347391) | 0.068606 / 0.075469 (-0.006863) |

### 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.376152 / 1.841788 (-0.465635) | 20.747088 / 8.074308 (12.672780) | 15.200311 / 10.191392 (5.008919) | 0.166380 / 0.680424 (-0.514043) | 0.021417 / 0.534201 (-0.512784) | 0.435677 / 0.579283 (-0.143606) | 0.460412 / 0.434364 (0.026048) | 0.509978 / 0.540337 (-0.030359) | 0.702506 / 1.386936 (-0.684430) |

</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.007378 / 0.011353 (-0.003975) | 0.003938 / 0.011008 (-0.007070) | 0.067095 / 0.038508 (0.028587) | 0.082252 / 0.023109 (0.059143) | 0.420317 / 0.275898 (0.144419) | 0.477496 / 0.323480 (0.154017) | 0.006259 / 0.007986 (-0.001727) | 0.003513 / 0.004328 (-0.000816) | 0.072107 / 0.004250 (0.067856) | 0.061737 / 0.037052 (0.024684) | 0.444142 / 0.258489 (0.185653) | 0.488926 / 0.293841 (0.195085) | 0.033623 / 0.128546 (-0.094923) | 0.008091 / 0.075646 (-0.067555) | 0.073997 / 0.419271 (-0.345274) | 0.051295 / 0.043533 (0.007762) | 0.442551 / 0.255139 (0.187412) | 0.462713 / 0.283200 (0.179513) | 0.023115 / 0.141683 (-0.118568) | 1.645759 / 1.452155 (0.193604) | 1.758121 / 1.492716 (0.265405) |

### 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.233450 / 0.018006 (0.215444) | 0.445384 / 0.000490 (0.444894) | 0.006412 / 0.000200 (0.006212) | 0.000111 / 0.000054 (0.000056) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.032446 / 0.037411 (-0.004965) | 0.098515 / 0.014526 (0.083989) | 0.109095 / 0.176557 (-0.067462) | 0.167645 / 0.737135 (-0.569490) | 0.110403 / 0.296338 (-0.185936) |

### 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.470189 / 0.215209 (0.254980) | 4.663224 / 2.077655 (2.585569) | 2.504474 / 1.504120 (1.000354) | 2.282867 / 1.541195 (0.741673) | 2.331598 / 1.468490 (0.863108) | 0.554421 / 4.584777 (-4.030356) | 4.078657 / 3.745712 (0.332945) | 3.516339 / 5.269862 (-1.753523) | 2.239134 / 4.565676 (-2.326542) | 0.062690 / 0.424275 (-0.361585) | 0.008406 / 0.007607 (0.000799) | 0.533827 / 0.226044 (0.307782) | 5.423984 / 2.268929 (3.155055) | 2.972784 / 55.444624 (-52.471840) | 2.699056 / 6.876477 (-4.177421) | 2.844403 / 2.142072 (0.702331) | 0.639194 / 4.805227 (-4.166033) | 0.142097 / 6.500664 (-6.358567) | 0.064646 / 0.075469 (-0.010823) |

### 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.544640 / 1.841788 (-0.297148) | 21.453429 / 8.074308 (13.379121) | 15.610723 / 10.191392 (5.419331) | 0.207796 / 0.680424 (-0.472628) | 0.021912 / 0.534201 (-0.512289) | 0.430472 / 0.579283 (-0.148811) | 0.467530 / 0.434364 (0.033166) | 0.541339 / 0.540337 (0.001002) | 0.721976 / 1.386936 (-0.664960) |

</details>
</details>

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

Fixes #5651. The same problem occurs when loading from disk so I fixed it there too.

I am not sure why the case distinction between local and remote filesystems is even necessary for `DatasetDict` when saving to disk. Imo this could be removed (leaving only `fs.makedirs(dataset_dict_path, exist_ok=True)`).