Fix regression for pandas < 2.0.0 in JSON loader
NONE
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/datasets/pr_6978). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.
2024-06-18T10:29:19Z
https://github.com/huggingface/datasets/pull/6978#issuecomment-2175763566
https://api.github.com/repos/huggingface/datasets/issues/6978
IC_kwDODunzps6Br4Ru
https://api.github.com/repos/huggingface/datasets/issues/comments/2175763566/reactions
2024-06-18T10:29:19Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2175763566
https://avatars.githubusercontent.com/u/99929124?v=4
https://api.github.com/users/HuggingFaceDocBuilderDev/events{/privacy}
https://api.github.com/users/HuggingFaceDocBuilderDev/followers
https://api.github.com/users/HuggingFaceDocBuilderDev/following{/other_user}
https://api.github.com/users/HuggingFaceDocBuilderDev/gists{/gist_id}
https://github.com/HuggingFaceDocBuilderDev
HuggingFaceDocBuilderDev
U_kgDOBfTMJA
https://api.github.com/users/HuggingFaceDocBuilderDev/orgs
https://api.github.com/users/HuggingFaceDocBuilderDev/received_events
https://api.github.com/users/HuggingFaceDocBuilderDev/repos
https://api.github.com/users/HuggingFaceDocBuilderDev/starred{/owner}{/repo}
https://api.github.com/users/HuggingFaceDocBuilderDev/subscriptions
User
https://api.github.com/users/HuggingFaceDocBuilderDev
public
NONE
<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.005144 / 0.011353 (-0.006209) | 0.003500 / 0.011008 (-0.007509) | 0.063670 / 0.038508 (0.025162) | 0.031793 / 0.023109 (0.008683) | 0.239611 / 0.275898 (-0.036287) | 0.276681 / 0.323480 (-0.046799) | 0.004148 / 0.007986 (-0.003838) | 0.002713 / 0.004328 (-0.001615) | 0.048832 / 0.004250 (0.044582) | 0.043066 / 0.037052 (0.006014) | 0.256835 / 0.258489 (-0.001655) | 0.292224 / 0.293841 (-0.001617) | 0.027530 / 0.128546 (-0.101017) | 0.010509 / 0.075646 (-0.065137) | 0.203370 / 0.419271 (-0.215901) | 0.035643 / 0.043533 (-0.007890) | 0.252161 / 0.255139 (-0.002978) | 0.271883 / 0.283200 (-0.011316) | 0.018658 / 0.141683 (-0.123024) | 1.081676 / 1.452155 (-0.370479) | 1.142146 / 1.492716 (-0.350571) |

### 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.093484 / 0.018006 (0.075477) | 0.298607 / 0.000490 (0.298117) | 0.000220 / 0.000200 (0.000020) | 0.000044 / 0.000054 (-0.000010) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.019021 / 0.037411 (-0.018390) | 0.062471 / 0.014526 (0.047946) | 0.075393 / 0.176557 (-0.101163) | 0.121040 / 0.737135 (-0.616095) | 0.077613 / 0.296338 (-0.218726) |

### 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.294857 / 0.215209 (0.079648) | 2.931143 / 2.077655 (0.853489) | 1.510866 / 1.504120 (0.006746) | 1.379574 / 1.541195 (-0.161621) | 1.352358 / 1.468490 (-0.116133) | 0.561670 / 4.584777 (-4.023107) | 2.378434 / 3.745712 (-1.367278) | 2.713203 / 5.269862 (-2.556658) | 1.706416 / 4.565676 (-2.859260) | 0.062355 / 0.424275 (-0.361920) | 0.004971 / 0.007607 (-0.002636) | 0.336498 / 0.226044 (0.110453) | 3.316464 / 2.268929 (1.047535) | 1.833035 / 55.444624 (-53.611589) | 1.532808 / 6.876477 (-5.343668) | 1.537323 / 2.142072 (-0.604749) | 0.639430 / 4.805227 (-4.165798) | 0.115808 / 6.500664 (-6.384856) | 0.043545 / 0.075469 (-0.031924) |

### 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) | 0.974428 / 1.841788 (-0.867360) | 11.368914 / 8.074308 (3.294606) | 9.754488 / 10.191392 (-0.436904) | 0.146277 / 0.680424 (-0.534146) | 0.013917 / 0.534201 (-0.520284) | 0.286809 / 0.579283 (-0.292474) | 0.267144 / 0.434364 (-0.167219) | 0.326161 / 0.540337 (-0.214177) | 0.418059 / 1.386936 (-0.968877) |

</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.005341 / 0.011353 (-0.006012) | 0.003460 / 0.011008 (-0.007548) | 0.050135 / 0.038508 (0.011627) | 0.032014 / 0.023109 (0.008905) | 0.259835 / 0.275898 (-0.016063) | 0.286275 / 0.323480 (-0.037205) | 0.004350 / 0.007986 (-0.003636) | 0.002800 / 0.004328 (-0.001529) | 0.049358 / 0.004250 (0.045107) | 0.040182 / 0.037052 (0.003130) | 0.278352 / 0.258489 (0.019863) | 0.307869 / 0.293841 (0.014028) | 0.029151 / 0.128546 (-0.099395) | 0.010091 / 0.075646 (-0.065555) | 0.058814 / 0.419271 (-0.360458) | 0.033150 / 0.043533 (-0.010383) | 0.263594 / 0.255139 (0.008455) | 0.284065 / 0.283200 (0.000866) | 0.017968 / 0.141683 (-0.123714) | 1.145605 / 1.452155 (-0.306550) | 1.196884 / 1.492716 (-0.295832) |

### 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.094045 / 0.018006 (0.076039) | 0.299031 / 0.000490 (0.298541) | 0.000210 / 0.000200 (0.000011) | 0.000044 / 0.000054 (-0.000010) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.022510 / 0.037411 (-0.014901) | 0.077478 / 0.014526 (0.062953) | 0.087746 / 0.176557 (-0.088811) | 0.129311 / 0.737135 (-0.607825) | 0.089921 / 0.296338 (-0.206418) |

### 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.290279 / 0.215209 (0.075070) | 2.880725 / 2.077655 (0.803070) | 1.541262 / 1.504120 (0.037142) | 1.424475 / 1.541195 (-0.116719) | 1.436397 / 1.468490 (-0.032093) | 0.578237 / 4.584777 (-4.006540) | 0.965249 / 3.745712 (-2.780463) | 2.682534 / 5.269862 (-2.587327) | 1.732859 / 4.565676 (-2.832817) | 0.065523 / 0.424275 (-0.358752) | 0.005466 / 0.007607 (-0.002141) | 0.343985 / 0.226044 (0.117940) | 3.397463 / 2.268929 (1.128534) | 1.929370 / 55.444624 (-53.515255) | 1.605135 / 6.876477 (-5.271342) | 1.753926 / 2.142072 (-0.388146) | 0.659929 / 4.805227 (-4.145298) | 0.118093 / 6.500664 (-6.382571) | 0.041252 / 0.075469 (-0.034217) |

### 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.009177 / 1.841788 (-0.832610) | 11.959624 / 8.074308 (3.885316) | 10.484672 / 10.191392 (0.293280) | 0.142085 / 0.680424 (-0.538339) | 0.015955 / 0.534201 (-0.518245) | 0.283649 / 0.579283 (-0.295634) | 0.125681 / 0.434364 (-0.308683) | 0.320490 / 0.540337 (-0.219847) | 0.440353 / 1.386936 (-0.946583) |

</details>
</details>

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

2024-06-19T05:56:16Z
https://github.com/huggingface/datasets/pull/6978#issuecomment-2177809499
https://api.github.com/repos/huggingface/datasets/issues/6978
IC_kwDODunzps6Bzrxb
Iv1.05c79e9ad1f6bdfa
2018-07-30T09:30:17Z
Automate your workflow from idea to production
branch_protection_rule check_run check_suite create delete deployment deployment_status discussion discussion_comment fork gollum issues issue_comment label merge_group milestone page_build project project_card project_column public pull_request pull_request_review pull_request_review_comment push registry_package release repository repository_dispatch status watch workflow_dispatch workflow_run
https://help.github.com/en/actions
https://github.com/apps/github-actions
GitHub Actions
MDM6QXBwMTUzNjg=
https://avatars.githubusercontent.com/u/9919?v=4
https://api.github.com/users/github/events{/privacy}
https://api.github.com/users/github/followers
https://api.github.com/users/github/following{/other_user}
https://api.github.com/users/github/gists{/gist_id}
https://github.com/github
github
MDEyOk9yZ2FuaXphdGlvbjk5MTk=
https://api.github.com/users/github/orgs
https://api.github.com/users/github/received_events
https://api.github.com/users/github/repos
https://api.github.com/users/github/starred{/owner}{/repo}
https://api.github.com/users/github/subscriptions
Organization
https://api.github.com/users/github
public
write
read
write
write
write
write
write
write
write
read
read
write
write
write
write
write
write
write
read
github-actions
2025-03-07T16:35:00Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2177809499/reactions
2024-06-19T05:56:16Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2177809499
https://avatars.githubusercontent.com/in/15368?v=4
https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}
https://api.github.com/users/github-actions%5Bbot%5D/followers
https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}
https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}
https://github.com/apps/github-actions
github-actions[bot]
MDM6Qm90NDE4OTgyODI=
https://api.github.com/users/github-actions%5Bbot%5D/orgs
https://api.github.com/users/github-actions%5Bbot%5D/received_events
https://api.github.com/users/github-actions%5Bbot%5D/repos
https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}
https://api.github.com/users/github-actions%5Bbot%5D/subscriptions
Bot
https://api.github.com/users/github-actions%5Bbot%5D
public
MEMBER
Maybe a patch release will be needed with this fix.
2024-06-19T06:23:24Z
https://github.com/huggingface/datasets/pull/6978#issuecomment-2177843249
https://api.github.com/repos/huggingface/datasets/issues/6978
IC_kwDODunzps6Bz0Ax
https://api.github.com/repos/huggingface/datasets/issues/comments/2177843249/reactions
2024-06-19T06:23:24Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2177843249
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
A regression was introduced for pandas < 2.0.0 in PR:
- #6914

As described in pandas docs, the `dtype_backend` parameter was first added in pandas 2.0.0: https://pandas.pydata.org/docs/reference/api/pandas.read_json.html

This PR fixes the regression by passing (or not) the `dtype_backend` parameter depending on pandas version.

Maybe, in a future 3.0 `datasets` release, we could just require pandas > 2.0.

Reported by:
- #6977