jasonfan commited on
Commit
be87187
·
verified ·
1 Parent(s): 8046359

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +35 -0
  2. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/INSTALLER +1 -0
  3. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/LICENSE +1250 -0
  4. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/METADATA +1574 -0
  5. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/RECORD +0 -0
  6. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/WHEEL +6 -0
  7. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/entry_points.txt +3 -0
  8. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_isin.py +252 -0
  9. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_isna.py +35 -0
  10. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_item.py +59 -0
  11. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_map.py +604 -0
  12. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_matmul.py +82 -0
  13. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_nlargest.py +248 -0
  14. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_nunique.py +24 -0
  15. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_pct_change.py +128 -0
  16. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_pop.py +13 -0
  17. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_quantile.py +247 -0
  18. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_rank.py +563 -0
  19. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_reindex.py +443 -0
  20. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_reindex_like.py +41 -0
  21. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_rename.py +184 -0
  22. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_rename_axis.py +47 -0
  23. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_repeat.py +40 -0
  24. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_replace.py +819 -0
  25. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_reset_index.py +225 -0
  26. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_round.py +81 -0
  27. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_searchsorted.py +77 -0
  28. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_set_name.py +21 -0
  29. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_size.py +22 -0
  30. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_sort_index.py +337 -0
  31. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_sort_values.py +246 -0
  32. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_csv.py +179 -0
  33. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_dict.py +38 -0
  34. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_frame.py +63 -0
  35. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_numpy.py +49 -0
  36. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_tolist.py +36 -0
  37. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_truncate.py +67 -0
  38. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_tz_localize.py +123 -0
  39. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_unique.py +76 -0
  40. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_unstack.py +169 -0
  41. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_update.py +143 -0
  42. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_value_counts.py +271 -0
  43. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_values.py +29 -0
  44. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_view.py +61 -0
  45. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/__init__.py +23 -0
  46. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/conftest.py +132 -0
  47. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_api.py +205 -0
  48. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_case_justify.py +423 -0
  49. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_cat.py +427 -0
  50. code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_extract.py +724 -0
.gitattributes CHANGED
@@ -249,3 +249,38 @@ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packag
249
  code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/_libs/tslibs/vectorized.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
250
  code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/_libs/window/aggregations.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
251
  code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/_libs/window/indexers.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/_libs/tslibs/vectorized.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
250
  code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/_libs/window/aggregations.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
251
  code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/_libs/window/indexers.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
252
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libavif-01e67780.so.16.3.0 filter=lfs diff=lfs merge=lfs -text
253
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libbrotlicommon-c55a5f7a.so.1.2.0 filter=lfs diff=lfs merge=lfs -text
254
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libfreetype-ee1c40c4.so.6.20.4 filter=lfs diff=lfs merge=lfs -text
255
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libharfbuzz-0692f733.so.0.61230.0 filter=lfs diff=lfs merge=lfs -text
256
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libjpeg-18a3f47f.so.62.4.0 filter=lfs diff=lfs merge=lfs -text
257
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/liblcms2-cc10e42f.so.2.0.17 filter=lfs diff=lfs merge=lfs -text
258
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/liblzma-61b1002e.so.5.8.2 filter=lfs diff=lfs merge=lfs -text
259
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libopenjp2-94e588ba.so.2.5.4 filter=lfs diff=lfs merge=lfs -text
260
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libpng16-4a38ea05.so.16.53.0 filter=lfs diff=lfs merge=lfs -text
261
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libtiff-295fd75c.so.6.2.0 filter=lfs diff=lfs merge=lfs -text
262
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libwebp-d8b9687f.so.7.2.0 filter=lfs diff=lfs merge=lfs -text
263
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libxcb-64009ff3.so.1.1.0 filter=lfs diff=lfs merge=lfs -text
264
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pillow.libs/libzstd-761a17b6.so.1.5.7 filter=lfs diff=lfs merge=lfs -text
265
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pip/_vendor/distlib/t64-arm.exe filter=lfs diff=lfs merge=lfs -text
266
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pip/_vendor/distlib/t64.exe filter=lfs diff=lfs merge=lfs -text
267
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pip/_vendor/distlib/w64-arm.exe filter=lfs diff=lfs merge=lfs -text
268
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pip/_vendor/distlib/w64.exe filter=lfs diff=lfs merge=lfs -text
269
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/propcache/_helpers_c.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
270
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/psutil/_psutil_linux.abi3.so filter=lfs diff=lfs merge=lfs -text
271
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_acero.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
272
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_azurefs.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
273
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_compute.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
274
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_csv.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
275
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_dataset.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
276
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_dataset_parquet.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
277
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_dataset_parquet_encryption.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
278
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_feather.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
279
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_flight.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
280
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/_fs.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
281
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/libarrow_flight.so.2300 filter=lfs diff=lfs merge=lfs -text
282
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/libarrow_python.so filter=lfs diff=lfs merge=lfs -text
283
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/libarrow_python.so.2300 filter=lfs diff=lfs merge=lfs -text
284
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/libarrow_python.so.2300.0.0 filter=lfs diff=lfs merge=lfs -text
285
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/libarrow_python_flight.so filter=lfs diff=lfs merge=lfs -text
286
+ code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pyarrow/libarrow_python_flight.so.2300 filter=lfs diff=lfs merge=lfs -text
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/LICENSE ADDED
@@ -0,0 +1,1250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
4
+ All rights reserved.
5
+
6
+ Copyright (c) 2011-2023, Open source contributors.
7
+
8
+ Redistribution and use in source and binary forms, with or without
9
+ modification, are permitted provided that the following conditions are met:
10
+
11
+ * Redistributions of source code must retain the above copyright notice, this
12
+ list of conditions and the following disclaimer.
13
+
14
+ * Redistributions in binary form must reproduce the above copyright notice,
15
+ this list of conditions and the following disclaimer in the documentation
16
+ and/or other materials provided with the distribution.
17
+
18
+ * Neither the name of the copyright holder nor the names of its
19
+ contributors may be used to endorse or promote products derived from
20
+ this software without specific prior written permission.
21
+
22
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ Copyright (c) 2010-2019 Keith Goodman
33
+ Copyright (c) 2019 Bottleneck Developers
34
+ All rights reserved.
35
+
36
+ Redistribution and use in source and binary forms, with or without
37
+ modification, are permitted provided that the following conditions are met:
38
+
39
+ * Redistributions of source code must retain the above copyright notice,
40
+ this list of conditions and the following disclaimer.
41
+
42
+ * Redistributions in binary form must reproduce the above copyright
43
+ notice, this list of conditions and the following disclaimer in the
44
+ documentation and/or other materials provided with the distribution.
45
+
46
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
50
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
56
+ POSSIBILITY OF SUCH DAMAGE.Copyright 2017- Paul Ganssle <paul@ganssle.io>
57
+ Copyright 2017- dateutil contributors (see AUTHORS file)
58
+
59
+ Licensed under the Apache License, Version 2.0 (the "License");
60
+ you may not use this file except in compliance with the License.
61
+ You may obtain a copy of the License at
62
+
63
+ http://www.apache.org/licenses/LICENSE-2.0
64
+
65
+ Unless required by applicable law or agreed to in writing, software
66
+ distributed under the License is distributed on an "AS IS" BASIS,
67
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
68
+ See the License for the specific language governing permissions and
69
+ limitations under the License.
70
+
71
+ The above license applies to all contributions after 2017-12-01, as well as
72
+ all contributions that have been re-licensed (see AUTHORS file for the list of
73
+ contributors who have re-licensed their code).
74
+ --------------------------------------------------------------------------------
75
+ dateutil - Extensions to the standard Python datetime module.
76
+
77
+ Copyright (c) 2003-2011 - Gustavo Niemeyer <gustavo@niemeyer.net>
78
+ Copyright (c) 2012-2014 - Tomi Pieviläinen <tomi.pievilainen@iki.fi>
79
+ Copyright (c) 2014-2016 - Yaron de Leeuw <me@jarondl.net>
80
+ Copyright (c) 2015- - Paul Ganssle <paul@ganssle.io>
81
+ Copyright (c) 2015- - dateutil contributors (see AUTHORS file)
82
+
83
+ All rights reserved.
84
+
85
+ Redistribution and use in source and binary forms, with or without
86
+ modification, are permitted provided that the following conditions are met:
87
+
88
+ * Redistributions of source code must retain the above copyright notice,
89
+ this list of conditions and the following disclaimer.
90
+ * Redistributions in binary form must reproduce the above copyright notice,
91
+ this list of conditions and the following disclaimer in the documentation
92
+ and/or other materials provided with the distribution.
93
+ * Neither the name of the copyright holder nor the names of its
94
+ contributors may be used to endorse or promote products derived from
95
+ this software without specific prior written permission.
96
+
97
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
98
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
99
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
100
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
101
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
102
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
103
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
104
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
105
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
106
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
107
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108
+
109
+ The above BSD License Applies to all code, even that also covered by Apache 2.0.# MIT License
110
+
111
+ Copyright (c) 2019 Hadley Wickham; RStudio; and Evan Miller
112
+
113
+ Permission is hereby granted, free of charge, to any person obtaining a copy
114
+ of this software and associated documentation files (the "Software"), to deal
115
+ in the Software without restriction, including without limitation the rights
116
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
117
+ copies of the Software, and to permit persons to whom the Software is
118
+ furnished to do so, subject to the following conditions:
119
+
120
+ The above copyright notice and this permission notice shall be included in all
121
+ copies or substantial portions of the Software.
122
+
123
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
124
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
125
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
126
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
127
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
128
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
129
+ SOFTWARE.
130
+ Based on http://opensource.org/licenses/MIT
131
+
132
+ This is a template. Complete and ship as file LICENSE the following 2
133
+ lines (only)
134
+
135
+ YEAR:
136
+ COPYRIGHT HOLDER:
137
+
138
+ and specify as
139
+
140
+ License: MIT + file LICENSE
141
+
142
+ Copyright (c) <YEAR>, <COPYRIGHT HOLDER>
143
+
144
+ Permission is hereby granted, free of charge, to any person obtaining
145
+ a copy of this software and associated documentation files (the
146
+ "Software"), to deal in the Software without restriction, including
147
+ without limitation the rights to use, copy, modify, merge, publish,
148
+ distribute, sublicense, and/or sell copies of the Software, and to
149
+ permit persons to whom the Software is furnished to do so, subject to
150
+ the following conditions:
151
+
152
+ The above copyright notice and this permission notice shall be
153
+ included in all copies or substantial portions of the Software.
154
+
155
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
156
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
157
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
158
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
159
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
160
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
161
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
162
+ The MIT License
163
+
164
+ Copyright (c) 2008- Attractive Chaos <attractor@live.co.uk>
165
+
166
+ Permission is hereby granted, free of charge, to any person obtaining
167
+ a copy of this software and associated documentation files (the
168
+ "Software"), to deal in the Software without restriction, including
169
+ without limitation the rights to use, copy, modify, merge, publish,
170
+ distribute, sublicense, and/or sell copies of the Software, and to
171
+ permit persons to whom the Software is furnished to do so, subject to
172
+ the following conditions:
173
+
174
+ The above copyright notice and this permission notice shall be
175
+ included in all copies or substantial portions of the Software.
176
+
177
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
178
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
179
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
180
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
181
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
182
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
183
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
184
+ SOFTWARE.musl as a whole is licensed under the following standard MIT license:
185
+
186
+ ----------------------------------------------------------------------
187
+ Copyright © 2005-2020 Rich Felker, et al.
188
+
189
+ Permission is hereby granted, free of charge, to any person obtaining
190
+ a copy of this software and associated documentation files (the
191
+ "Software"), to deal in the Software without restriction, including
192
+ without limitation the rights to use, copy, modify, merge, publish,
193
+ distribute, sublicense, and/or sell copies of the Software, and to
194
+ permit persons to whom the Software is furnished to do so, subject to
195
+ the following conditions:
196
+
197
+ The above copyright notice and this permission notice shall be
198
+ included in all copies or substantial portions of the Software.
199
+
200
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
201
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
202
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
203
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
204
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
205
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
206
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
207
+ ----------------------------------------------------------------------
208
+
209
+ Authors/contributors include:
210
+
211
+ A. Wilcox
212
+ Ada Worcester
213
+ Alex Dowad
214
+ Alex Suykov
215
+ Alexander Monakov
216
+ Andre McCurdy
217
+ Andrew Kelley
218
+ Anthony G. Basile
219
+ Aric Belsito
220
+ Arvid Picciani
221
+ Bartosz Brachaczek
222
+ Benjamin Peterson
223
+ Bobby Bingham
224
+ Boris Brezillon
225
+ Brent Cook
226
+ Chris Spiegel
227
+ Clément Vasseur
228
+ Daniel Micay
229
+ Daniel Sabogal
230
+ Daurnimator
231
+ David Carlier
232
+ David Edelsohn
233
+ Denys Vlasenko
234
+ Dmitry Ivanov
235
+ Dmitry V. Levin
236
+ Drew DeVault
237
+ Emil Renner Berthing
238
+ Fangrui Song
239
+ Felix Fietkau
240
+ Felix Janda
241
+ Gianluca Anzolin
242
+ Hauke Mehrtens
243
+ He X
244
+ Hiltjo Posthuma
245
+ Isaac Dunham
246
+ Jaydeep Patil
247
+ Jens Gustedt
248
+ Jeremy Huntwork
249
+ Jo-Philipp Wich
250
+ Joakim Sindholt
251
+ John Spencer
252
+ Julien Ramseier
253
+ Justin Cormack
254
+ Kaarle Ritvanen
255
+ Khem Raj
256
+ Kylie McClain
257
+ Leah Neukirchen
258
+ Luca Barbato
259
+ Luka Perkov
260
+ M Farkas-Dyck (Strake)
261
+ Mahesh Bodapati
262
+ Markus Wichmann
263
+ Masanori Ogino
264
+ Michael Clark
265
+ Michael Forney
266
+ Mikhail Kremnyov
267
+ Natanael Copa
268
+ Nicholas J. Kain
269
+ orc
270
+ Pascal Cuoq
271
+ Patrick Oppenlander
272
+ Petr Hosek
273
+ Petr Skocik
274
+ Pierre Carrier
275
+ Reini Urban
276
+ Rich Felker
277
+ Richard Pennington
278
+ Ryan Fairfax
279
+ Samuel Holland
280
+ Segev Finer
281
+ Shiz
282
+ sin
283
+ Solar Designer
284
+ Stefan Kristiansson
285
+ Stefan O'Rear
286
+ Szabolcs Nagy
287
+ Timo Teräs
288
+ Trutz Behn
289
+ Valentin Ochs
290
+ Will Dietz
291
+ William Haddon
292
+ William Pitcock
293
+
294
+ Portions of this software are derived from third-party works licensed
295
+ under terms compatible with the above MIT license:
296
+
297
+ The TRE regular expression implementation (src/regex/reg* and
298
+ src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
299
+ under a 2-clause BSD license (license text in the source files). The
300
+ included version has been heavily modified by Rich Felker in 2012, in
301
+ the interests of size, simplicity, and namespace cleanliness.
302
+
303
+ Much of the math library code (src/math/* and src/complex/*) is
304
+ Copyright © 1993,2004 Sun Microsystems or
305
+ Copyright © 2003-2011 David Schultz or
306
+ Copyright © 2003-2009 Steven G. Kargl or
307
+ Copyright © 2003-2009 Bruce D. Evans or
308
+ Copyright © 2008 Stephen L. Moshier or
309
+ Copyright © 2017-2018 Arm Limited
310
+ and labelled as such in comments in the individual source files. All
311
+ have been licensed under extremely permissive terms.
312
+
313
+ The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
314
+ The Android Open Source Project and is licensed under a two-clause BSD
315
+ license. It was taken from Bionic libc, used on Android.
316
+
317
+ The AArch64 memcpy and memset code (src/string/aarch64/*) are
318
+ Copyright © 1999-2019, Arm Limited.
319
+
320
+ The implementation of DES for crypt (src/crypt/crypt_des.c) is
321
+ Copyright © 1994 David Burren. It is licensed under a BSD license.
322
+
323
+ The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
324
+ originally written by Solar Designer and placed into the public
325
+ domain. The code also comes with a fallback permissive license for use
326
+ in jurisdictions that may not recognize the public domain.
327
+
328
+ The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
329
+ Valentin Ochs and is licensed under an MIT-style license.
330
+
331
+ The x86_64 port was written by Nicholas J. Kain and is licensed under
332
+ the standard MIT terms.
333
+
334
+ The mips and microblaze ports were originally written by Richard
335
+ Pennington for use in the ellcc project. The original code was adapted
336
+ by Rich Felker for build system and code conventions during upstream
337
+ integration. It is licensed under the standard MIT terms.
338
+
339
+ The mips64 port was contributed by Imagination Technologies and is
340
+ licensed under the standard MIT terms.
341
+
342
+ The powerpc port was also originally written by Richard Pennington,
343
+ and later supplemented and integrated by John Spencer. It is licensed
344
+ under the standard MIT terms.
345
+
346
+ All other files which have no copyright comments are original works
347
+ produced specifically for use as part of this library, written either
348
+ by Rich Felker, the main author of the library, or by one or more
349
+ contibutors listed above. Details on authorship of individual files
350
+ can be found in the git version control history of the project. The
351
+ omission of copyright and license comments in each file is in the
352
+ interest of source tree size.
353
+
354
+ In addition, permission is hereby granted for all public header files
355
+ (include/* and arch/*/bits/*) and crt files intended to be linked into
356
+ applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
357
+ the copyright notice and permission notice otherwise required by the
358
+ license, and to use these files without any requirement of
359
+ attribution. These files include substantial contributions from:
360
+
361
+ Bobby Bingham
362
+ John Spencer
363
+ Nicholas J. Kain
364
+ Rich Felker
365
+ Richard Pennington
366
+ Stefan Kristiansson
367
+ Szabolcs Nagy
368
+
369
+ all of whom have explicitly granted such permission.
370
+
371
+ This file previously contained text expressing a belief that most of
372
+ the files covered by the above exception were sufficiently trivial not
373
+ to be subject to copyright, resulting in confusion over whether it
374
+ negated the permissions granted in the license. In the spirit of
375
+ permissive licensing, and of not having licensing issues being an
376
+ obstacle to adoption, that text has been removed.Copyright (c) 2005-2023, NumPy Developers.
377
+ All rights reserved.
378
+
379
+ Redistribution and use in source and binary forms, with or without
380
+ modification, are permitted provided that the following conditions are
381
+ met:
382
+
383
+ * Redistributions of source code must retain the above copyright
384
+ notice, this list of conditions and the following disclaimer.
385
+
386
+ * Redistributions in binary form must reproduce the above
387
+ copyright notice, this list of conditions and the following
388
+ disclaimer in the documentation and/or other materials provided
389
+ with the distribution.
390
+
391
+ * Neither the name of the NumPy Developers nor the names of any
392
+ contributors may be used to endorse or promote products derived
393
+ from this software without specific prior written permission.
394
+
395
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
396
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
397
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
398
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
399
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
400
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
401
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
402
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
403
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
404
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
405
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406
+ Apache License
407
+ Version 2.0, January 2004
408
+ http://www.apache.org/licenses/
409
+
410
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
411
+
412
+ 1. Definitions.
413
+
414
+ "License" shall mean the terms and conditions for use, reproduction,
415
+ and distribution as defined by Sections 1 through 9 of this document.
416
+
417
+ "Licensor" shall mean the copyright owner or entity authorized by
418
+ the copyright owner that is granting the License.
419
+
420
+ "Legal Entity" shall mean the union of the acting entity and all
421
+ other entities that control, are controlled by, or are under common
422
+ control with that entity. For the purposes of this definition,
423
+ "control" means (i) the power, direct or indirect, to cause the
424
+ direction or management of such entity, whether by contract or
425
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
426
+ outstanding shares, or (iii) beneficial ownership of such entity.
427
+
428
+ "You" (or "Your") shall mean an individual or Legal Entity
429
+ exercising permissions granted by this License.
430
+
431
+ "Source" form shall mean the preferred form for making modifications,
432
+ including but not limited to software source code, documentation
433
+ source, and configuration files.
434
+
435
+ "Object" form shall mean any form resulting from mechanical
436
+ transformation or translation of a Source form, including but
437
+ not limited to compiled object code, generated documentation,
438
+ and conversions to other media types.
439
+
440
+ "Work" shall mean the work of authorship, whether in Source or
441
+ Object form, made available under the License, as indicated by a
442
+ copyright notice that is included in or attached to the work
443
+ (an example is provided in the Appendix below).
444
+
445
+ "Derivative Works" shall mean any work, whether in Source or Object
446
+ form, that is based on (or derived from) the Work and for which the
447
+ editorial revisions, annotations, elaborations, or other modifications
448
+ represent, as a whole, an original work of authorship. For the purposes
449
+ of this License, Derivative Works shall not include works that remain
450
+ separable from, or merely link (or bind by name) to the interfaces of,
451
+ the Work and Derivative Works thereof.
452
+
453
+ "Contribution" shall mean any work of authorship, including
454
+ the original version of the Work and any modifications or additions
455
+ to that Work or Derivative Works thereof, that is intentionally
456
+ submitted to Licensor for inclusion in the Work by the copyright owner
457
+ or by an individual or Legal Entity authorized to submit on behalf of
458
+ the copyright owner. For the purposes of this definition, "submitted"
459
+ means any form of electronic, verbal, or written communication sent
460
+ to the Licensor or its representatives, including but not limited to
461
+ communication on electronic mailing lists, source code control systems,
462
+ and issue tracking systems that are managed by, or on behalf of, the
463
+ Licensor for the purpose of discussing and improving the Work, but
464
+ excluding communication that is conspicuously marked or otherwise
465
+ designated in writing by the copyright owner as "Not a Contribution."
466
+
467
+ "Contributor" shall mean Licensor and any individual or Legal Entity
468
+ on behalf of whom a Contribution has been received by Licensor and
469
+ subsequently incorporated within the Work.
470
+
471
+ 2. Grant of Copyright License. Subject to the terms and conditions of
472
+ this License, each Contributor hereby grants to You a perpetual,
473
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
474
+ copyright license to reproduce, prepare Derivative Works of,
475
+ publicly display, publicly perform, sublicense, and distribute the
476
+ Work and such Derivative Works in Source or Object form.
477
+
478
+ 3. Grant of Patent License. Subject to the terms and conditions of
479
+ this License, each Contributor hereby grants to You a perpetual,
480
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
481
+ (except as stated in this section) patent license to make, have made,
482
+ use, offer to sell, sell, import, and otherwise transfer the Work,
483
+ where such license applies only to those patent claims licensable
484
+ by such Contributor that are necessarily infringed by their
485
+ Contribution(s) alone or by combination of their Contribution(s)
486
+ with the Work to which such Contribution(s) was submitted. If You
487
+ institute patent litigation against any entity (including a
488
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
489
+ or a Contribution incorporated within the Work constitutes direct
490
+ or contributory patent infringement, then any patent licenses
491
+ granted to You under this License for that Work shall terminate
492
+ as of the date such litigation is filed.
493
+
494
+ 4. Redistribution. You may reproduce and distribute copies of the
495
+ Work or Derivative Works thereof in any medium, with or without
496
+ modifications, and in Source or Object form, provided that You
497
+ meet the following conditions:
498
+
499
+ (a) You must give any other recipients of the Work or
500
+ Derivative Works a copy of this License; and
501
+
502
+ (b) You must cause any modified files to carry prominent notices
503
+ stating that You changed the files; and
504
+
505
+ (c) You must retain, in the Source form of any Derivative Works
506
+ that You distribute, all copyright, patent, trademark, and
507
+ attribution notices from the Source form of the Work,
508
+ excluding those notices that do not pertain to any part of
509
+ the Derivative Works; and
510
+
511
+ (d) If the Work includes a "NOTICE" text file as part of its
512
+ distribution, then any Derivative Works that You distribute must
513
+ include a readable copy of the attribution notices contained
514
+ within such NOTICE file, excluding those notices that do not
515
+ pertain to any part of the Derivative Works, in at least one
516
+ of the following places: within a NOTICE text file distributed
517
+ as part of the Derivative Works; within the Source form or
518
+ documentation, if provided along with the Derivative Works; or,
519
+ within a display generated by the Derivative Works, if and
520
+ wherever such third-party notices normally appear. The contents
521
+ of the NOTICE file are for informational purposes only and
522
+ do not modify the License. You may add Your own attribution
523
+ notices within Derivative Works that You distribute, alongside
524
+ or as an addendum to the NOTICE text from the Work, provided
525
+ that such additional attribution notices cannot be construed
526
+ as modifying the License.
527
+
528
+ You may add Your own copyright statement to Your modifications and
529
+ may provide additional or different license terms and conditions
530
+ for use, reproduction, or distribution of Your modifications, or
531
+ for any such Derivative Works as a whole, provided Your use,
532
+ reproduction, and distribution of the Work otherwise complies with
533
+ the conditions stated in this License.
534
+
535
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
536
+ any Contribution intentionally submitted for inclusion in the Work
537
+ by You to the Licensor shall be under the terms and conditions of
538
+ this License, without any additional terms or conditions.
539
+ Notwithstanding the above, nothing herein shall supersede or modify
540
+ the terms of any separate license agreement you may have executed
541
+ with Licensor regarding such Contributions.
542
+
543
+ 6. Trademarks. This License does not grant permission to use the trade
544
+ names, trademarks, service marks, or product names of the Licensor,
545
+ except as required for reasonable and customary use in describing the
546
+ origin of the Work and reproducing the content of the NOTICE file.
547
+
548
+ 7. Disclaimer of Warranty. Unless required by applicable law or
549
+ agreed to in writing, Licensor provides the Work (and each
550
+ Contributor provides its Contributions) on an "AS IS" BASIS,
551
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
552
+ implied, including, without limitation, any warranties or conditions
553
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
554
+ PARTICULAR PURPOSE. You are solely responsible for determining the
555
+ appropriateness of using or redistributing the Work and assume any
556
+ risks associated with Your exercise of permissions under this License.
557
+
558
+ 8. Limitation of Liability. In no event and under no legal theory,
559
+ whether in tort (including negligence), contract, or otherwise,
560
+ unless required by applicable law (such as deliberate and grossly
561
+ negligent acts) or agreed to in writing, shall any Contributor be
562
+ liable to You for damages, including any direct, indirect, special,
563
+ incidental, or consequential damages of any character arising as a
564
+ result of this License or out of the use or inability to use the
565
+ Work (including but not limited to damages for loss of goodwill,
566
+ work stoppage, computer failure or malfunction, or any and all
567
+ other commercial damages or losses), even if such Contributor
568
+ has been advised of the possibility of such damages.
569
+
570
+ 9. Accepting Warranty or Additional Liability. While redistributing
571
+ the Work or Derivative Works thereof, You may choose to offer,
572
+ and charge a fee for, acceptance of support, warranty, indemnity,
573
+ or other liability obligations and/or rights consistent with this
574
+ License. However, in accepting such obligations, You may act only
575
+ on Your own behalf and on Your sole responsibility, not on behalf
576
+ of any other Contributor, and only if You agree to indemnify,
577
+ defend, and hold each Contributor harmless for any liability
578
+ incurred by, or claims asserted against, such Contributor by reason
579
+ of your accepting any such warranty or additional liability.
580
+
581
+ END OF TERMS AND CONDITIONS
582
+
583
+
584
+ Copyright (c) Donald Stufft and individual contributors.
585
+ All rights reserved.
586
+
587
+ Redistribution and use in source and binary forms, with or without
588
+ modification, are permitted provided that the following conditions are met:
589
+
590
+ 1. Redistributions of source code must retain the above copyright notice,
591
+ this list of conditions and the following disclaimer.
592
+
593
+ 2. Redistributions in binary form must reproduce the above copyright
594
+ notice, this list of conditions and the following disclaimer in the
595
+ documentation and/or other materials provided with the distribution.
596
+
597
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
598
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
599
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
600
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
601
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
602
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
603
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
604
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
605
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
606
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.A. HISTORY OF THE SOFTWARE
607
+ ==========================
608
+
609
+ Python was created in the early 1990s by Guido van Rossum at Stichting
610
+ Mathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands
611
+ as a successor of a language called ABC. Guido remains Python's
612
+ principal author, although it includes many contributions from others.
613
+
614
+ In 1995, Guido continued his work on Python at the Corporation for
615
+ National Research Initiatives (CNRI, see https://www.cnri.reston.va.us)
616
+ in Reston, Virginia where he released several versions of the
617
+ software.
618
+
619
+ In May 2000, Guido and the Python core development team moved to
620
+ BeOpen.com to form the BeOpen PythonLabs team. In October of the same
621
+ year, the PythonLabs team moved to Digital Creations, which became
622
+ Zope Corporation. In 2001, the Python Software Foundation (PSF, see
623
+ https://www.python.org/psf/) was formed, a non-profit organization
624
+ created specifically to own Python-related Intellectual Property.
625
+ Zope Corporation was a sponsoring member of the PSF.
626
+
627
+ All Python releases are Open Source (see https://opensource.org for
628
+ the Open Source Definition). Historically, most, but not all, Python
629
+ releases have also been GPL-compatible; the table below summarizes
630
+ the various releases.
631
+
632
+ Release Derived Year Owner GPL-
633
+ from compatible? (1)
634
+
635
+ 0.9.0 thru 1.2 1991-1995 CWI yes
636
+ 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
637
+ 1.6 1.5.2 2000 CNRI no
638
+ 2.0 1.6 2000 BeOpen.com no
639
+ 1.6.1 1.6 2001 CNRI yes (2)
640
+ 2.1 2.0+1.6.1 2001 PSF no
641
+ 2.0.1 2.0+1.6.1 2001 PSF yes
642
+ 2.1.1 2.1+2.0.1 2001 PSF yes
643
+ 2.1.2 2.1.1 2002 PSF yes
644
+ 2.1.3 2.1.2 2002 PSF yes
645
+ 2.2 and above 2.1.1 2001-now PSF yes
646
+
647
+ Footnotes:
648
+
649
+ (1) GPL-compatible doesn't mean that we're distributing Python under
650
+ the GPL. All Python licenses, unlike the GPL, let you distribute
651
+ a modified version without making your changes open source. The
652
+ GPL-compatible licenses make it possible to combine Python with
653
+ other software that is released under the GPL; the others don't.
654
+
655
+ (2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
656
+ because its license has a choice of law clause. According to
657
+ CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
658
+ is "not incompatible" with the GPL.
659
+
660
+ Thanks to the many outside volunteers who have worked under Guido's
661
+ direction to make these releases possible.
662
+
663
+
664
+ B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
665
+ ===============================================================
666
+
667
+ Python software and documentation are licensed under the
668
+ Python Software Foundation License Version 2.
669
+
670
+ Starting with Python 3.8.6, examples, recipes, and other code in
671
+ the documentation are dual licensed under the PSF License Version 2
672
+ and the Zero-Clause BSD license.
673
+
674
+ Some software incorporated into Python is under different licenses.
675
+ The licenses are listed with code falling under that license.
676
+
677
+
678
+ PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
679
+ --------------------------------------------
680
+
681
+ 1. This LICENSE AGREEMENT is between the Python Software Foundation
682
+ ("PSF"), and the Individual or Organization ("Licensee") accessing and
683
+ otherwise using this software ("Python") in source or binary form and
684
+ its associated documentation.
685
+
686
+ 2. Subject to the terms and conditions of this License Agreement, PSF hereby
687
+ grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
688
+ analyze, test, perform and/or display publicly, prepare derivative works,
689
+ distribute, and otherwise use Python alone or in any derivative version,
690
+ provided, however, that PSF's License Agreement and PSF's notice of copyright,
691
+ i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
692
+ 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
693
+ All Rights Reserved" are retained in Python alone or in any derivative version
694
+ prepared by Licensee.
695
+
696
+ 3. In the event Licensee prepares a derivative work that is based on
697
+ or incorporates Python or any part thereof, and wants to make
698
+ the derivative work available to others as provided herein, then
699
+ Licensee hereby agrees to include in any such work a brief summary of
700
+ the changes made to Python.
701
+
702
+ 4. PSF is making Python available to Licensee on an "AS IS"
703
+ basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
704
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
705
+ DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
706
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
707
+ INFRINGE ANY THIRD PARTY RIGHTS.
708
+
709
+ 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
710
+ FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
711
+ A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
712
+ OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
713
+
714
+ 6. This License Agreement will automatically terminate upon a material
715
+ breach of its terms and conditions.
716
+
717
+ 7. Nothing in this License Agreement shall be deemed to create any
718
+ relationship of agency, partnership, or joint venture between PSF and
719
+ Licensee. This License Agreement does not grant permission to use PSF
720
+ trademarks or trade name in a trademark sense to endorse or promote
721
+ products or services of Licensee, or any third party.
722
+
723
+ 8. By copying, installing or otherwise using Python, Licensee
724
+ agrees to be bound by the terms and conditions of this License
725
+ Agreement.
726
+
727
+
728
+ BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
729
+ -------------------------------------------
730
+
731
+ BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
732
+
733
+ 1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
734
+ office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
735
+ Individual or Organization ("Licensee") accessing and otherwise using
736
+ this software in source or binary form and its associated
737
+ documentation ("the Software").
738
+
739
+ 2. Subject to the terms and conditions of this BeOpen Python License
740
+ Agreement, BeOpen hereby grants Licensee a non-exclusive,
741
+ royalty-free, world-wide license to reproduce, analyze, test, perform
742
+ and/or display publicly, prepare derivative works, distribute, and
743
+ otherwise use the Software alone or in any derivative version,
744
+ provided, however, that the BeOpen Python License is retained in the
745
+ Software, alone or in any derivative version prepared by Licensee.
746
+
747
+ 3. BeOpen is making the Software available to Licensee on an "AS IS"
748
+ basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
749
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
750
+ DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
751
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
752
+ INFRINGE ANY THIRD PARTY RIGHTS.
753
+
754
+ 4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
755
+ SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
756
+ AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
757
+ DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
758
+
759
+ 5. This License Agreement will automatically terminate upon a material
760
+ breach of its terms and conditions.
761
+
762
+ 6. This License Agreement shall be governed by and interpreted in all
763
+ respects by the law of the State of California, excluding conflict of
764
+ law provisions. Nothing in this License Agreement shall be deemed to
765
+ create any relationship of agency, partnership, or joint venture
766
+ between BeOpen and Licensee. This License Agreement does not grant
767
+ permission to use BeOpen trademarks or trade names in a trademark
768
+ sense to endorse or promote products or services of Licensee, or any
769
+ third party. As an exception, the "BeOpen Python" logos available at
770
+ http://www.pythonlabs.com/logos.html may be used according to the
771
+ permissions granted on that web page.
772
+
773
+ 7. By copying, installing or otherwise using the software, Licensee
774
+ agrees to be bound by the terms and conditions of this License
775
+ Agreement.
776
+
777
+
778
+ CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
779
+ ---------------------------------------
780
+
781
+ 1. This LICENSE AGREEMENT is between the Corporation for National
782
+ Research Initiatives, having an office at 1895 Preston White Drive,
783
+ Reston, VA 20191 ("CNRI"), and the Individual or Organization
784
+ ("Licensee") accessing and otherwise using Python 1.6.1 software in
785
+ source or binary form and its associated documentation.
786
+
787
+ 2. Subject to the terms and conditions of this License Agreement, CNRI
788
+ hereby grants Licensee a nonexclusive, royalty-free, world-wide
789
+ license to reproduce, analyze, test, perform and/or display publicly,
790
+ prepare derivative works, distribute, and otherwise use Python 1.6.1
791
+ alone or in any derivative version, provided, however, that CNRI's
792
+ License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
793
+ 1995-2001 Corporation for National Research Initiatives; All Rights
794
+ Reserved" are retained in Python 1.6.1 alone or in any derivative
795
+ version prepared by Licensee. Alternately, in lieu of CNRI's License
796
+ Agreement, Licensee may substitute the following text (omitting the
797
+ quotes): "Python 1.6.1 is made available subject to the terms and
798
+ conditions in CNRI's License Agreement. This Agreement together with
799
+ Python 1.6.1 may be located on the internet using the following
800
+ unique, persistent identifier (known as a handle): 1895.22/1013. This
801
+ Agreement may also be obtained from a proxy server on the internet
802
+ using the following URL: http://hdl.handle.net/1895.22/1013".
803
+
804
+ 3. In the event Licensee prepares a derivative work that is based on
805
+ or incorporates Python 1.6.1 or any part thereof, and wants to make
806
+ the derivative work available to others as provided herein, then
807
+ Licensee hereby agrees to include in any such work a brief summary of
808
+ the changes made to Python 1.6.1.
809
+
810
+ 4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
811
+ basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
812
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
813
+ DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
814
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
815
+ INFRINGE ANY THIRD PARTY RIGHTS.
816
+
817
+ 5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
818
+ 1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
819
+ A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
820
+ OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
821
+
822
+ 6. This License Agreement will automatically terminate upon a material
823
+ breach of its terms and conditions.
824
+
825
+ 7. This License Agreement shall be governed by the federal
826
+ intellectual property law of the United States, including without
827
+ limitation the federal copyright law, and, to the extent such
828
+ U.S. federal law does not apply, by the law of the Commonwealth of
829
+ Virginia, excluding Virginia's conflict of law provisions.
830
+ Notwithstanding the foregoing, with regard to derivative works based
831
+ on Python 1.6.1 that incorporate non-separable material that was
832
+ previously distributed under the GNU General Public License (GPL), the
833
+ law of the Commonwealth of Virginia shall govern this License
834
+ Agreement only as to issues arising under or with respect to
835
+ Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
836
+ License Agreement shall be deemed to create any relationship of
837
+ agency, partnership, or joint venture between CNRI and Licensee. This
838
+ License Agreement does not grant permission to use CNRI trademarks or
839
+ trade name in a trademark sense to endorse or promote products or
840
+ services of Licensee, or any third party.
841
+
842
+ 8. By clicking on the "ACCEPT" button where indicated, or by copying,
843
+ installing or otherwise using Python 1.6.1, Licensee agrees to be
844
+ bound by the terms and conditions of this License Agreement.
845
+
846
+ ACCEPT
847
+
848
+
849
+ CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
850
+ --------------------------------------------------
851
+
852
+ Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
853
+ The Netherlands. All rights reserved.
854
+
855
+ Permission to use, copy, modify, and distribute this software and its
856
+ documentation for any purpose and without fee is hereby granted,
857
+ provided that the above copyright notice appear in all copies and that
858
+ both that copyright notice and this permission notice appear in
859
+ supporting documentation, and that the name of Stichting Mathematisch
860
+ Centrum or CWI not be used in advertising or publicity pertaining to
861
+ distribution of the software without specific, written prior
862
+ permission.
863
+
864
+ STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
865
+ THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
866
+ FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
867
+ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
868
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
869
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
870
+ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
871
+
872
+ ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
873
+ ----------------------------------------------------------------------
874
+
875
+ Permission to use, copy, modify, and/or distribute this software for any
876
+ purpose with or without fee is hereby granted.
877
+
878
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
879
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
880
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
881
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
882
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
883
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
884
+ PERFORMANCE OF THIS SOFTWARE.
885
+ Copyright (c) 2014, Al Sweigart
886
+ All rights reserved.
887
+
888
+ Redistribution and use in source and binary forms, with or without
889
+ modification, are permitted provided that the following conditions are met:
890
+
891
+ * Redistributions of source code must retain the above copyright notice, this
892
+ list of conditions and the following disclaimer.
893
+
894
+ * Redistributions in binary form must reproduce the above copyright notice,
895
+ this list of conditions and the following disclaimer in the documentation
896
+ and/or other materials provided with the distribution.
897
+
898
+ * Neither the name of the {organization} nor the names of its
899
+ contributors may be used to endorse or promote products derived from
900
+ this software without specific prior written permission.
901
+
902
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
903
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
904
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
905
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
906
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
907
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
908
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
909
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
910
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
911
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Copyright (c) 2017 Anthony Sottile
912
+
913
+ Permission is hereby granted, free of charge, to any person obtaining a copy
914
+ of this software and associated documentation files (the "Software"), to deal
915
+ in the Software without restriction, including without limitation the rights
916
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
917
+ copies of the Software, and to permit persons to whom the Software is
918
+ furnished to do so, subject to the following conditions:
919
+
920
+ The above copyright notice and this permission notice shall be included in
921
+ all copies or substantial portions of the Software.
922
+
923
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
924
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
925
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
926
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
927
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
928
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
929
+ THE SOFTWARE.Copyright (c) 2015-2019 Jared Hobbs
930
+
931
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
932
+ this software and associated documentation files (the "Software"), to deal in
933
+ the Software without restriction, including without limitation the rights to
934
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
935
+ of the Software, and to permit persons to whom the Software is furnished to do
936
+ so, subject to the following conditions:
937
+
938
+ The above copyright notice and this permission notice shall be included in all
939
+ copies or substantial portions of the Software.
940
+
941
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
942
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
943
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
944
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
945
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
946
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
947
+ SOFTWARE.Developed by ESN, an Electronic Arts Inc. studio.
948
+ Copyright (c) 2014, Electronic Arts Inc.
949
+ All rights reserved.
950
+
951
+ Redistribution and use in source and binary forms, with or without
952
+ modification, are permitted provided that the following conditions are met:
953
+ * Redistributions of source code must retain the above copyright
954
+ notice, this list of conditions and the following disclaimer.
955
+ * Redistributions in binary form must reproduce the above copyright
956
+ notice, this list of conditions and the following disclaimer in the
957
+ documentation and/or other materials provided with the distribution.
958
+ * Neither the name of ESN, Electronic Arts Inc. nor the
959
+ names of its contributors may be used to endorse or promote products
960
+ derived from this software without specific prior written permission.
961
+
962
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
963
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
964
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
965
+ DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS INC. BE LIABLE
966
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
967
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
968
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
969
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
970
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
971
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
972
+
973
+ ----
974
+
975
+ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
976
+ https://github.com/client9/stringencoders
977
+
978
+ Copyright 2005, 2006, 2007
979
+ Nick Galbreath -- nickg [at] modp [dot] com
980
+ All rights reserved.
981
+
982
+ Redistribution and use in source and binary forms, with or without
983
+ modification, are permitted provided that the following conditions are
984
+ met:
985
+
986
+ Redistributions of source code must retain the above copyright
987
+ notice, this list of conditions and the following disclaimer.
988
+
989
+ Redistributions in binary form must reproduce the above copyright
990
+ notice, this list of conditions and the following disclaimer in the
991
+ documentation and/or other materials provided with the distribution.
992
+
993
+ Neither the name of the modp.com nor the names of its
994
+ contributors may be used to endorse or promote products derived from
995
+ this software without specific prior written permission.
996
+
997
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
998
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
999
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1000
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1001
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1002
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1003
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1004
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1005
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1006
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1007
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1008
+
1009
+ This is the standard "new" BSD license:
1010
+ http://www.opensource.org/licenses/bsd-license.php
1011
+
1012
+ https://github.com/client9/stringencoders/blob/cfd5c1507325ae497ea9bacdacba12c0ffd79d30/COPYING
1013
+
1014
+ ----
1015
+
1016
+ Numeric decoder derived from from TCL library
1017
+ https://opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
1018
+ * Copyright (c) 1988-1993 The Regents of the University of California.
1019
+ * Copyright (c) 1994 Sun Microsystems, Inc.
1020
+
1021
+ This software is copyrighted by the Regents of the University of
1022
+ California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState
1023
+ Corporation and other parties. The following terms apply to all files
1024
+ associated with the software unless explicitly disclaimed in
1025
+ individual files.
1026
+
1027
+ The authors hereby grant permission to use, copy, modify, distribute,
1028
+ and license this software and its documentation for any purpose, provided
1029
+ that existing copyright notices are retained in all copies and that this
1030
+ notice is included verbatim in any distributions. No written agreement,
1031
+ license, or royalty fee is required for any of the authorized uses.
1032
+ Modifications to this software may be copyrighted by their authors
1033
+ and need not follow the licensing terms described here, provided that
1034
+ the new terms are clearly indicated on the first page of each file where
1035
+ they apply.
1036
+
1037
+ IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
1038
+ FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
1039
+ ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
1040
+ DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
1041
+ POSSIBILITY OF SUCH DAMAGE.
1042
+
1043
+ THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
1044
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
1045
+ FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
1046
+ IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
1047
+ NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
1048
+ MODIFICATIONS.
1049
+
1050
+ GOVERNMENT USE: If you are acquiring this software on behalf of the
1051
+ U.S. government, the Government shall have only "Restricted Rights"
1052
+ in the software and related documentation as defined in the Federal
1053
+ Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
1054
+ are acquiring the software on behalf of the Department of Defense, the
1055
+ software shall be classified as "Commercial Computer Software" and the
1056
+ Government shall have only "Restricted Rights" as defined in Clause
1057
+ 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
1058
+ authors grant the U.S. Government and others acting in its behalf
1059
+ permission to use and distribute the software in accordance with the
1060
+ terms specified in this license.Apache License
1061
+ Version 2.0, January 2004
1062
+ http://www.apache.org/licenses/
1063
+
1064
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1065
+
1066
+ 1. Definitions.
1067
+
1068
+ "License" shall mean the terms and conditions for use, reproduction, and
1069
+ distribution as defined by Sections 1 through 9 of this document.
1070
+
1071
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
1072
+ owner that is granting the License.
1073
+
1074
+ "Legal Entity" shall mean the union of the acting entity and all other entities
1075
+ that control, are controlled by, or are under common control with that entity.
1076
+ For the purposes of this definition, "control" means (i) the power, direct or
1077
+ indirect, to cause the direction or management of such entity, whether by
1078
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
1079
+ outstanding shares, or (iii) beneficial ownership of such entity.
1080
+
1081
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
1082
+ permissions granted by this License.
1083
+
1084
+ "Source" form shall mean the preferred form for making modifications, including
1085
+ but not limited to software source code, documentation source, and configuration
1086
+ files.
1087
+
1088
+ "Object" form shall mean any form resulting from mechanical transformation or
1089
+ translation of a Source form, including but not limited to compiled object code,
1090
+ generated documentation, and conversions to other media types.
1091
+
1092
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
1093
+ available under the License, as indicated by a copyright notice that is included
1094
+ in or attached to the work (an example is provided in the Appendix below).
1095
+
1096
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
1097
+ is based on (or derived from) the Work and for which the editorial revisions,
1098
+ annotations, elaborations, or other modifications represent, as a whole, an
1099
+ original work of authorship. For the purposes of this License, Derivative Works
1100
+ shall not include works that remain separable from, or merely link (or bind by
1101
+ name) to the interfaces of, the Work and Derivative Works thereof.
1102
+
1103
+ "Contribution" shall mean any work of authorship, including the original version
1104
+ of the Work and any modifications or additions to that Work or Derivative Works
1105
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
1106
+ by the copyright owner or by an individual or Legal Entity authorized to submit
1107
+ on behalf of the copyright owner. For the purposes of this definition,
1108
+ "submitted" means any form of electronic, verbal, or written communication sent
1109
+ to the Licensor or its representatives, including but not limited to
1110
+ communication on electronic mailing lists, source code control systems, and
1111
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
1112
+ the purpose of discussing and improving the Work, but excluding communication
1113
+ that is conspicuously marked or otherwise designated in writing by the copyright
1114
+ owner as "Not a Contribution."
1115
+
1116
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
1117
+ of whom a Contribution has been received by Licensor and subsequently
1118
+ incorporated within the Work.
1119
+
1120
+ 2. Grant of Copyright License.
1121
+
1122
+ Subject to the terms and conditions of this License, each Contributor hereby
1123
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
1124
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
1125
+ publicly display, publicly perform, sublicense, and distribute the Work and such
1126
+ Derivative Works in Source or Object form.
1127
+
1128
+ 3. Grant of Patent License.
1129
+
1130
+ Subject to the terms and conditions of this License, each Contributor hereby
1131
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
1132
+ irrevocable (except as stated in this section) patent license to make, have
1133
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
1134
+ such license applies only to those patent claims licensable by such Contributor
1135
+ that are necessarily infringed by their Contribution(s) alone or by combination
1136
+ of their Contribution(s) with the Work to which such Contribution(s) was
1137
+ submitted. If You institute patent litigation against any entity (including a
1138
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
1139
+ Contribution incorporated within the Work constitutes direct or contributory
1140
+ patent infringement, then any patent licenses granted to You under this License
1141
+ for that Work shall terminate as of the date such litigation is filed.
1142
+
1143
+ 4. Redistribution.
1144
+
1145
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
1146
+ in any medium, with or without modifications, and in Source or Object form,
1147
+ provided that You meet the following conditions:
1148
+
1149
+ You must give any other recipients of the Work or Derivative Works a copy of
1150
+ this License; and
1151
+ You must cause any modified files to carry prominent notices stating that You
1152
+ changed the files; and
1153
+ You must retain, in the Source form of any Derivative Works that You distribute,
1154
+ all copyright, patent, trademark, and attribution notices from the Source form
1155
+ of the Work, excluding those notices that do not pertain to any part of the
1156
+ Derivative Works; and
1157
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
1158
+ Derivative Works that You distribute must include a readable copy of the
1159
+ attribution notices contained within such NOTICE file, excluding those notices
1160
+ that do not pertain to any part of the Derivative Works, in at least one of the
1161
+ following places: within a NOTICE text file distributed as part of the
1162
+ Derivative Works; within the Source form or documentation, if provided along
1163
+ with the Derivative Works; or, within a display generated by the Derivative
1164
+ Works, if and wherever such third-party notices normally appear. The contents of
1165
+ the NOTICE file are for informational purposes only and do not modify the
1166
+ License. You may add Your own attribution notices within Derivative Works that
1167
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
1168
+ provided that such additional attribution notices cannot be construed as
1169
+ modifying the License.
1170
+ You may add Your own copyright statement to Your modifications and may provide
1171
+ additional or different license terms and conditions for use, reproduction, or
1172
+ distribution of Your modifications, or for any such Derivative Works as a whole,
1173
+ provided Your use, reproduction, and distribution of the Work otherwise complies
1174
+ with the conditions stated in this License.
1175
+
1176
+ 5. Submission of Contributions.
1177
+
1178
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
1179
+ for inclusion in the Work by You to the Licensor shall be under the terms and
1180
+ conditions of this License, without any additional terms or conditions.
1181
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
1182
+ any separate license agreement you may have executed with Licensor regarding
1183
+ such Contributions.
1184
+
1185
+ 6. Trademarks.
1186
+
1187
+ This License does not grant permission to use the trade names, trademarks,
1188
+ service marks, or product names of the Licensor, except as required for
1189
+ reasonable and customary use in describing the origin of the Work and
1190
+ reproducing the content of the NOTICE file.
1191
+
1192
+ 7. Disclaimer of Warranty.
1193
+
1194
+ Unless required by applicable law or agreed to in writing, Licensor provides the
1195
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
1196
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
1197
+ including, without limitation, any warranties or conditions of TITLE,
1198
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
1199
+ solely responsible for determining the appropriateness of using or
1200
+ redistributing the Work and assume any risks associated with Your exercise of
1201
+ permissions under this License.
1202
+
1203
+ 8. Limitation of Liability.
1204
+
1205
+ In no event and under no legal theory, whether in tort (including negligence),
1206
+ contract, or otherwise, unless required by applicable law (such as deliberate
1207
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
1208
+ liable to You for damages, including any direct, indirect, special, incidental,
1209
+ or consequential damages of any character arising as a result of this License or
1210
+ out of the use or inability to use the Work (including but not limited to
1211
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
1212
+ any and all other commercial damages or losses), even if such Contributor has
1213
+ been advised of the possibility of such damages.
1214
+
1215
+ 9. Accepting Warranty or Additional Liability.
1216
+
1217
+ While redistributing the Work or Derivative Works thereof, You may choose to
1218
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
1219
+ other liability obligations and/or rights consistent with this License. However,
1220
+ in accepting such obligations, You may act only on Your own behalf and on Your
1221
+ sole responsibility, not on behalf of any other Contributor, and only if You
1222
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
1223
+ incurred by, or claims asserted against, such Contributor by reason of your
1224
+ accepting any such warranty or additional liability.
1225
+
1226
+ END OF TERMS AND CONDITIONS
1227
+
1228
+ APPENDIX: How to apply the Apache License to your work
1229
+
1230
+ To apply the Apache License to your work, attach the following boilerplate
1231
+ notice, with the fields enclosed by brackets "[]" replaced with your own
1232
+ identifying information. (Don't include the brackets!) The text should be
1233
+ enclosed in the appropriate comment syntax for the file format. We also
1234
+ recommend that a file or class name and description of purpose be included on
1235
+ the same "printed page" as the copyright notice for easier identification within
1236
+ third-party archives.
1237
+
1238
+ Copyright [yyyy] [name of copyright owner]
1239
+
1240
+ Licensed under the Apache License, Version 2.0 (the "License");
1241
+ you may not use this file except in compliance with the License.
1242
+ You may obtain a copy of the License at
1243
+
1244
+ http://www.apache.org/licenses/LICENSE-2.0
1245
+
1246
+ Unless required by applicable law or agreed to in writing, software
1247
+ distributed under the License is distributed on an "AS IS" BASIS,
1248
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1249
+ See the License for the specific language governing permissions and
1250
+ limitations under the License.
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/METADATA ADDED
@@ -0,0 +1,1574 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: pandas
3
+ Version: 2.3.3
4
+ Summary: Powerful data structures for data analysis, time series, and statistics
5
+ Author-Email: The Pandas Development Team <pandas-dev@python.org>
6
+ License: BSD 3-Clause License
7
+
8
+ Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
9
+ All rights reserved.
10
+
11
+ Copyright (c) 2011-2023, Open source contributors.
12
+
13
+ Redistribution and use in source and binary forms, with or without
14
+ modification, are permitted provided that the following conditions are met:
15
+
16
+ * Redistributions of source code must retain the above copyright notice, this
17
+ list of conditions and the following disclaimer.
18
+
19
+ * Redistributions in binary form must reproduce the above copyright notice,
20
+ this list of conditions and the following disclaimer in the documentation
21
+ and/or other materials provided with the distribution.
22
+
23
+ * Neither the name of the copyright holder nor the names of its
24
+ contributors may be used to endorse or promote products derived from
25
+ this software without specific prior written permission.
26
+
27
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+ Copyright (c) 2010-2019 Keith Goodman
38
+ Copyright (c) 2019 Bottleneck Developers
39
+ All rights reserved.
40
+
41
+ Redistribution and use in source and binary forms, with or without
42
+ modification, are permitted provided that the following conditions are met:
43
+
44
+ * Redistributions of source code must retain the above copyright notice,
45
+ this list of conditions and the following disclaimer.
46
+
47
+ * Redistributions in binary form must reproduce the above copyright
48
+ notice, this list of conditions and the following disclaimer in the
49
+ documentation and/or other materials provided with the distribution.
50
+
51
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
52
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
55
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61
+ POSSIBILITY OF SUCH DAMAGE.Copyright 2017- Paul Ganssle <paul@ganssle.io>
62
+ Copyright 2017- dateutil contributors (see AUTHORS file)
63
+
64
+ Licensed under the Apache License, Version 2.0 (the "License");
65
+ you may not use this file except in compliance with the License.
66
+ You may obtain a copy of the License at
67
+
68
+ http://www.apache.org/licenses/LICENSE-2.0
69
+
70
+ Unless required by applicable law or agreed to in writing, software
71
+ distributed under the License is distributed on an "AS IS" BASIS,
72
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73
+ See the License for the specific language governing permissions and
74
+ limitations under the License.
75
+
76
+ The above license applies to all contributions after 2017-12-01, as well as
77
+ all contributions that have been re-licensed (see AUTHORS file for the list of
78
+ contributors who have re-licensed their code).
79
+ --------------------------------------------------------------------------------
80
+ dateutil - Extensions to the standard Python datetime module.
81
+
82
+ Copyright (c) 2003-2011 - Gustavo Niemeyer <gustavo@niemeyer.net>
83
+ Copyright (c) 2012-2014 - Tomi Pieviläinen <tomi.pievilainen@iki.fi>
84
+ Copyright (c) 2014-2016 - Yaron de Leeuw <me@jarondl.net>
85
+ Copyright (c) 2015- - Paul Ganssle <paul@ganssle.io>
86
+ Copyright (c) 2015- - dateutil contributors (see AUTHORS file)
87
+
88
+ All rights reserved.
89
+
90
+ Redistribution and use in source and binary forms, with or without
91
+ modification, are permitted provided that the following conditions are met:
92
+
93
+ * Redistributions of source code must retain the above copyright notice,
94
+ this list of conditions and the following disclaimer.
95
+ * Redistributions in binary form must reproduce the above copyright notice,
96
+ this list of conditions and the following disclaimer in the documentation
97
+ and/or other materials provided with the distribution.
98
+ * Neither the name of the copyright holder nor the names of its
99
+ contributors may be used to endorse or promote products derived from
100
+ this software without specific prior written permission.
101
+
102
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
103
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
104
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
105
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
106
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
107
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
108
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
109
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
110
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
111
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
112
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
113
+
114
+ The above BSD License Applies to all code, even that also covered by Apache 2.0.# MIT License
115
+
116
+ Copyright (c) 2019 Hadley Wickham; RStudio; and Evan Miller
117
+
118
+ Permission is hereby granted, free of charge, to any person obtaining a copy
119
+ of this software and associated documentation files (the "Software"), to deal
120
+ in the Software without restriction, including without limitation the rights
121
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
122
+ copies of the Software, and to permit persons to whom the Software is
123
+ furnished to do so, subject to the following conditions:
124
+
125
+ The above copyright notice and this permission notice shall be included in all
126
+ copies or substantial portions of the Software.
127
+
128
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
129
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
130
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
131
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
132
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
133
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
134
+ SOFTWARE.
135
+ Based on http://opensource.org/licenses/MIT
136
+
137
+ This is a template. Complete and ship as file LICENSE the following 2
138
+ lines (only)
139
+
140
+ YEAR:
141
+ COPYRIGHT HOLDER:
142
+
143
+ and specify as
144
+
145
+ License: MIT + file LICENSE
146
+
147
+ Copyright (c) <YEAR>, <COPYRIGHT HOLDER>
148
+
149
+ Permission is hereby granted, free of charge, to any person obtaining
150
+ a copy of this software and associated documentation files (the
151
+ "Software"), to deal in the Software without restriction, including
152
+ without limitation the rights to use, copy, modify, merge, publish,
153
+ distribute, sublicense, and/or sell copies of the Software, and to
154
+ permit persons to whom the Software is furnished to do so, subject to
155
+ the following conditions:
156
+
157
+ The above copyright notice and this permission notice shall be
158
+ included in all copies or substantial portions of the Software.
159
+
160
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
161
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
162
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
163
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
164
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
165
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
166
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
167
+ The MIT License
168
+
169
+ Copyright (c) 2008- Attractive Chaos <attractor@live.co.uk>
170
+
171
+ Permission is hereby granted, free of charge, to any person obtaining
172
+ a copy of this software and associated documentation files (the
173
+ "Software"), to deal in the Software without restriction, including
174
+ without limitation the rights to use, copy, modify, merge, publish,
175
+ distribute, sublicense, and/or sell copies of the Software, and to
176
+ permit persons to whom the Software is furnished to do so, subject to
177
+ the following conditions:
178
+
179
+ The above copyright notice and this permission notice shall be
180
+ included in all copies or substantial portions of the Software.
181
+
182
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
183
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
184
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
185
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
186
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
187
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
188
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
189
+ SOFTWARE.musl as a whole is licensed under the following standard MIT license:
190
+
191
+ ----------------------------------------------------------------------
192
+ Copyright © 2005-2020 Rich Felker, et al.
193
+
194
+ Permission is hereby granted, free of charge, to any person obtaining
195
+ a copy of this software and associated documentation files (the
196
+ "Software"), to deal in the Software without restriction, including
197
+ without limitation the rights to use, copy, modify, merge, publish,
198
+ distribute, sublicense, and/or sell copies of the Software, and to
199
+ permit persons to whom the Software is furnished to do so, subject to
200
+ the following conditions:
201
+
202
+ The above copyright notice and this permission notice shall be
203
+ included in all copies or substantial portions of the Software.
204
+
205
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
206
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
207
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
208
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
209
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
210
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
211
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
212
+ ----------------------------------------------------------------------
213
+
214
+ Authors/contributors include:
215
+
216
+ A. Wilcox
217
+ Ada Worcester
218
+ Alex Dowad
219
+ Alex Suykov
220
+ Alexander Monakov
221
+ Andre McCurdy
222
+ Andrew Kelley
223
+ Anthony G. Basile
224
+ Aric Belsito
225
+ Arvid Picciani
226
+ Bartosz Brachaczek
227
+ Benjamin Peterson
228
+ Bobby Bingham
229
+ Boris Brezillon
230
+ Brent Cook
231
+ Chris Spiegel
232
+ Clément Vasseur
233
+ Daniel Micay
234
+ Daniel Sabogal
235
+ Daurnimator
236
+ David Carlier
237
+ David Edelsohn
238
+ Denys Vlasenko
239
+ Dmitry Ivanov
240
+ Dmitry V. Levin
241
+ Drew DeVault
242
+ Emil Renner Berthing
243
+ Fangrui Song
244
+ Felix Fietkau
245
+ Felix Janda
246
+ Gianluca Anzolin
247
+ Hauke Mehrtens
248
+ He X
249
+ Hiltjo Posthuma
250
+ Isaac Dunham
251
+ Jaydeep Patil
252
+ Jens Gustedt
253
+ Jeremy Huntwork
254
+ Jo-Philipp Wich
255
+ Joakim Sindholt
256
+ John Spencer
257
+ Julien Ramseier
258
+ Justin Cormack
259
+ Kaarle Ritvanen
260
+ Khem Raj
261
+ Kylie McClain
262
+ Leah Neukirchen
263
+ Luca Barbato
264
+ Luka Perkov
265
+ M Farkas-Dyck (Strake)
266
+ Mahesh Bodapati
267
+ Markus Wichmann
268
+ Masanori Ogino
269
+ Michael Clark
270
+ Michael Forney
271
+ Mikhail Kremnyov
272
+ Natanael Copa
273
+ Nicholas J. Kain
274
+ orc
275
+ Pascal Cuoq
276
+ Patrick Oppenlander
277
+ Petr Hosek
278
+ Petr Skocik
279
+ Pierre Carrier
280
+ Reini Urban
281
+ Rich Felker
282
+ Richard Pennington
283
+ Ryan Fairfax
284
+ Samuel Holland
285
+ Segev Finer
286
+ Shiz
287
+ sin
288
+ Solar Designer
289
+ Stefan Kristiansson
290
+ Stefan O'Rear
291
+ Szabolcs Nagy
292
+ Timo Teräs
293
+ Trutz Behn
294
+ Valentin Ochs
295
+ Will Dietz
296
+ William Haddon
297
+ William Pitcock
298
+
299
+ Portions of this software are derived from third-party works licensed
300
+ under terms compatible with the above MIT license:
301
+
302
+ The TRE regular expression implementation (src/regex/reg* and
303
+ src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
304
+ under a 2-clause BSD license (license text in the source files). The
305
+ included version has been heavily modified by Rich Felker in 2012, in
306
+ the interests of size, simplicity, and namespace cleanliness.
307
+
308
+ Much of the math library code (src/math/* and src/complex/*) is
309
+ Copyright © 1993,2004 Sun Microsystems or
310
+ Copyright © 2003-2011 David Schultz or
311
+ Copyright © 2003-2009 Steven G. Kargl or
312
+ Copyright © 2003-2009 Bruce D. Evans or
313
+ Copyright © 2008 Stephen L. Moshier or
314
+ Copyright © 2017-2018 Arm Limited
315
+ and labelled as such in comments in the individual source files. All
316
+ have been licensed under extremely permissive terms.
317
+
318
+ The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
319
+ The Android Open Source Project and is licensed under a two-clause BSD
320
+ license. It was taken from Bionic libc, used on Android.
321
+
322
+ The AArch64 memcpy and memset code (src/string/aarch64/*) are
323
+ Copyright © 1999-2019, Arm Limited.
324
+
325
+ The implementation of DES for crypt (src/crypt/crypt_des.c) is
326
+ Copyright © 1994 David Burren. It is licensed under a BSD license.
327
+
328
+ The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
329
+ originally written by Solar Designer and placed into the public
330
+ domain. The code also comes with a fallback permissive license for use
331
+ in jurisdictions that may not recognize the public domain.
332
+
333
+ The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
334
+ Valentin Ochs and is licensed under an MIT-style license.
335
+
336
+ The x86_64 port was written by Nicholas J. Kain and is licensed under
337
+ the standard MIT terms.
338
+
339
+ The mips and microblaze ports were originally written by Richard
340
+ Pennington for use in the ellcc project. The original code was adapted
341
+ by Rich Felker for build system and code conventions during upstream
342
+ integration. It is licensed under the standard MIT terms.
343
+
344
+ The mips64 port was contributed by Imagination Technologies and is
345
+ licensed under the standard MIT terms.
346
+
347
+ The powerpc port was also originally written by Richard Pennington,
348
+ and later supplemented and integrated by John Spencer. It is licensed
349
+ under the standard MIT terms.
350
+
351
+ All other files which have no copyright comments are original works
352
+ produced specifically for use as part of this library, written either
353
+ by Rich Felker, the main author of the library, or by one or more
354
+ contibutors listed above. Details on authorship of individual files
355
+ can be found in the git version control history of the project. The
356
+ omission of copyright and license comments in each file is in the
357
+ interest of source tree size.
358
+
359
+ In addition, permission is hereby granted for all public header files
360
+ (include/* and arch/*/bits/*) and crt files intended to be linked into
361
+ applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
362
+ the copyright notice and permission notice otherwise required by the
363
+ license, and to use these files without any requirement of
364
+ attribution. These files include substantial contributions from:
365
+
366
+ Bobby Bingham
367
+ John Spencer
368
+ Nicholas J. Kain
369
+ Rich Felker
370
+ Richard Pennington
371
+ Stefan Kristiansson
372
+ Szabolcs Nagy
373
+
374
+ all of whom have explicitly granted such permission.
375
+
376
+ This file previously contained text expressing a belief that most of
377
+ the files covered by the above exception were sufficiently trivial not
378
+ to be subject to copyright, resulting in confusion over whether it
379
+ negated the permissions granted in the license. In the spirit of
380
+ permissive licensing, and of not having licensing issues being an
381
+ obstacle to adoption, that text has been removed.Copyright (c) 2005-2023, NumPy Developers.
382
+ All rights reserved.
383
+
384
+ Redistribution and use in source and binary forms, with or without
385
+ modification, are permitted provided that the following conditions are
386
+ met:
387
+
388
+ * Redistributions of source code must retain the above copyright
389
+ notice, this list of conditions and the following disclaimer.
390
+
391
+ * Redistributions in binary form must reproduce the above
392
+ copyright notice, this list of conditions and the following
393
+ disclaimer in the documentation and/or other materials provided
394
+ with the distribution.
395
+
396
+ * Neither the name of the NumPy Developers nor the names of any
397
+ contributors may be used to endorse or promote products derived
398
+ from this software without specific prior written permission.
399
+
400
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
401
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
402
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
403
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
404
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
405
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
406
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
407
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
408
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
409
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
410
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
411
+ Apache License
412
+ Version 2.0, January 2004
413
+ http://www.apache.org/licenses/
414
+
415
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
416
+
417
+ 1. Definitions.
418
+
419
+ "License" shall mean the terms and conditions for use, reproduction,
420
+ and distribution as defined by Sections 1 through 9 of this document.
421
+
422
+ "Licensor" shall mean the copyright owner or entity authorized by
423
+ the copyright owner that is granting the License.
424
+
425
+ "Legal Entity" shall mean the union of the acting entity and all
426
+ other entities that control, are controlled by, or are under common
427
+ control with that entity. For the purposes of this definition,
428
+ "control" means (i) the power, direct or indirect, to cause the
429
+ direction or management of such entity, whether by contract or
430
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
431
+ outstanding shares, or (iii) beneficial ownership of such entity.
432
+
433
+ "You" (or "Your") shall mean an individual or Legal Entity
434
+ exercising permissions granted by this License.
435
+
436
+ "Source" form shall mean the preferred form for making modifications,
437
+ including but not limited to software source code, documentation
438
+ source, and configuration files.
439
+
440
+ "Object" form shall mean any form resulting from mechanical
441
+ transformation or translation of a Source form, including but
442
+ not limited to compiled object code, generated documentation,
443
+ and conversions to other media types.
444
+
445
+ "Work" shall mean the work of authorship, whether in Source or
446
+ Object form, made available under the License, as indicated by a
447
+ copyright notice that is included in or attached to the work
448
+ (an example is provided in the Appendix below).
449
+
450
+ "Derivative Works" shall mean any work, whether in Source or Object
451
+ form, that is based on (or derived from) the Work and for which the
452
+ editorial revisions, annotations, elaborations, or other modifications
453
+ represent, as a whole, an original work of authorship. For the purposes
454
+ of this License, Derivative Works shall not include works that remain
455
+ separable from, or merely link (or bind by name) to the interfaces of,
456
+ the Work and Derivative Works thereof.
457
+
458
+ "Contribution" shall mean any work of authorship, including
459
+ the original version of the Work and any modifications or additions
460
+ to that Work or Derivative Works thereof, that is intentionally
461
+ submitted to Licensor for inclusion in the Work by the copyright owner
462
+ or by an individual or Legal Entity authorized to submit on behalf of
463
+ the copyright owner. For the purposes of this definition, "submitted"
464
+ means any form of electronic, verbal, or written communication sent
465
+ to the Licensor or its representatives, including but not limited to
466
+ communication on electronic mailing lists, source code control systems,
467
+ and issue tracking systems that are managed by, or on behalf of, the
468
+ Licensor for the purpose of discussing and improving the Work, but
469
+ excluding communication that is conspicuously marked or otherwise
470
+ designated in writing by the copyright owner as "Not a Contribution."
471
+
472
+ "Contributor" shall mean Licensor and any individual or Legal Entity
473
+ on behalf of whom a Contribution has been received by Licensor and
474
+ subsequently incorporated within the Work.
475
+
476
+ 2. Grant of Copyright License. Subject to the terms and conditions of
477
+ this License, each Contributor hereby grants to You a perpetual,
478
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
479
+ copyright license to reproduce, prepare Derivative Works of,
480
+ publicly display, publicly perform, sublicense, and distribute the
481
+ Work and such Derivative Works in Source or Object form.
482
+
483
+ 3. Grant of Patent License. Subject to the terms and conditions of
484
+ this License, each Contributor hereby grants to You a perpetual,
485
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
486
+ (except as stated in this section) patent license to make, have made,
487
+ use, offer to sell, sell, import, and otherwise transfer the Work,
488
+ where such license applies only to those patent claims licensable
489
+ by such Contributor that are necessarily infringed by their
490
+ Contribution(s) alone or by combination of their Contribution(s)
491
+ with the Work to which such Contribution(s) was submitted. If You
492
+ institute patent litigation against any entity (including a
493
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
494
+ or a Contribution incorporated within the Work constitutes direct
495
+ or contributory patent infringement, then any patent licenses
496
+ granted to You under this License for that Work shall terminate
497
+ as of the date such litigation is filed.
498
+
499
+ 4. Redistribution. You may reproduce and distribute copies of the
500
+ Work or Derivative Works thereof in any medium, with or without
501
+ modifications, and in Source or Object form, provided that You
502
+ meet the following conditions:
503
+
504
+ (a) You must give any other recipients of the Work or
505
+ Derivative Works a copy of this License; and
506
+
507
+ (b) You must cause any modified files to carry prominent notices
508
+ stating that You changed the files; and
509
+
510
+ (c) You must retain, in the Source form of any Derivative Works
511
+ that You distribute, all copyright, patent, trademark, and
512
+ attribution notices from the Source form of the Work,
513
+ excluding those notices that do not pertain to any part of
514
+ the Derivative Works; and
515
+
516
+ (d) If the Work includes a "NOTICE" text file as part of its
517
+ distribution, then any Derivative Works that You distribute must
518
+ include a readable copy of the attribution notices contained
519
+ within such NOTICE file, excluding those notices that do not
520
+ pertain to any part of the Derivative Works, in at least one
521
+ of the following places: within a NOTICE text file distributed
522
+ as part of the Derivative Works; within the Source form or
523
+ documentation, if provided along with the Derivative Works; or,
524
+ within a display generated by the Derivative Works, if and
525
+ wherever such third-party notices normally appear. The contents
526
+ of the NOTICE file are for informational purposes only and
527
+ do not modify the License. You may add Your own attribution
528
+ notices within Derivative Works that You distribute, alongside
529
+ or as an addendum to the NOTICE text from the Work, provided
530
+ that such additional attribution notices cannot be construed
531
+ as modifying the License.
532
+
533
+ You may add Your own copyright statement to Your modifications and
534
+ may provide additional or different license terms and conditions
535
+ for use, reproduction, or distribution of Your modifications, or
536
+ for any such Derivative Works as a whole, provided Your use,
537
+ reproduction, and distribution of the Work otherwise complies with
538
+ the conditions stated in this License.
539
+
540
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
541
+ any Contribution intentionally submitted for inclusion in the Work
542
+ by You to the Licensor shall be under the terms and conditions of
543
+ this License, without any additional terms or conditions.
544
+ Notwithstanding the above, nothing herein shall supersede or modify
545
+ the terms of any separate license agreement you may have executed
546
+ with Licensor regarding such Contributions.
547
+
548
+ 6. Trademarks. This License does not grant permission to use the trade
549
+ names, trademarks, service marks, or product names of the Licensor,
550
+ except as required for reasonable and customary use in describing the
551
+ origin of the Work and reproducing the content of the NOTICE file.
552
+
553
+ 7. Disclaimer of Warranty. Unless required by applicable law or
554
+ agreed to in writing, Licensor provides the Work (and each
555
+ Contributor provides its Contributions) on an "AS IS" BASIS,
556
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
557
+ implied, including, without limitation, any warranties or conditions
558
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
559
+ PARTICULAR PURPOSE. You are solely responsible for determining the
560
+ appropriateness of using or redistributing the Work and assume any
561
+ risks associated with Your exercise of permissions under this License.
562
+
563
+ 8. Limitation of Liability. In no event and under no legal theory,
564
+ whether in tort (including negligence), contract, or otherwise,
565
+ unless required by applicable law (such as deliberate and grossly
566
+ negligent acts) or agreed to in writing, shall any Contributor be
567
+ liable to You for damages, including any direct, indirect, special,
568
+ incidental, or consequential damages of any character arising as a
569
+ result of this License or out of the use or inability to use the
570
+ Work (including but not limited to damages for loss of goodwill,
571
+ work stoppage, computer failure or malfunction, or any and all
572
+ other commercial damages or losses), even if such Contributor
573
+ has been advised of the possibility of such damages.
574
+
575
+ 9. Accepting Warranty or Additional Liability. While redistributing
576
+ the Work or Derivative Works thereof, You may choose to offer,
577
+ and charge a fee for, acceptance of support, warranty, indemnity,
578
+ or other liability obligations and/or rights consistent with this
579
+ License. However, in accepting such obligations, You may act only
580
+ on Your own behalf and on Your sole responsibility, not on behalf
581
+ of any other Contributor, and only if You agree to indemnify,
582
+ defend, and hold each Contributor harmless for any liability
583
+ incurred by, or claims asserted against, such Contributor by reason
584
+ of your accepting any such warranty or additional liability.
585
+
586
+ END OF TERMS AND CONDITIONS
587
+
588
+
589
+ Copyright (c) Donald Stufft and individual contributors.
590
+ All rights reserved.
591
+
592
+ Redistribution and use in source and binary forms, with or without
593
+ modification, are permitted provided that the following conditions are met:
594
+
595
+ 1. Redistributions of source code must retain the above copyright notice,
596
+ this list of conditions and the following disclaimer.
597
+
598
+ 2. Redistributions in binary form must reproduce the above copyright
599
+ notice, this list of conditions and the following disclaimer in the
600
+ documentation and/or other materials provided with the distribution.
601
+
602
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
603
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
604
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
605
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
606
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
607
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
608
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
609
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
610
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
611
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.A. HISTORY OF THE SOFTWARE
612
+ ==========================
613
+
614
+ Python was created in the early 1990s by Guido van Rossum at Stichting
615
+ Mathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands
616
+ as a successor of a language called ABC. Guido remains Python's
617
+ principal author, although it includes many contributions from others.
618
+
619
+ In 1995, Guido continued his work on Python at the Corporation for
620
+ National Research Initiatives (CNRI, see https://www.cnri.reston.va.us)
621
+ in Reston, Virginia where he released several versions of the
622
+ software.
623
+
624
+ In May 2000, Guido and the Python core development team moved to
625
+ BeOpen.com to form the BeOpen PythonLabs team. In October of the same
626
+ year, the PythonLabs team moved to Digital Creations, which became
627
+ Zope Corporation. In 2001, the Python Software Foundation (PSF, see
628
+ https://www.python.org/psf/) was formed, a non-profit organization
629
+ created specifically to own Python-related Intellectual Property.
630
+ Zope Corporation was a sponsoring member of the PSF.
631
+
632
+ All Python releases are Open Source (see https://opensource.org for
633
+ the Open Source Definition). Historically, most, but not all, Python
634
+ releases have also been GPL-compatible; the table below summarizes
635
+ the various releases.
636
+
637
+ Release Derived Year Owner GPL-
638
+ from compatible? (1)
639
+
640
+ 0.9.0 thru 1.2 1991-1995 CWI yes
641
+ 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
642
+ 1.6 1.5.2 2000 CNRI no
643
+ 2.0 1.6 2000 BeOpen.com no
644
+ 1.6.1 1.6 2001 CNRI yes (2)
645
+ 2.1 2.0+1.6.1 2001 PSF no
646
+ 2.0.1 2.0+1.6.1 2001 PSF yes
647
+ 2.1.1 2.1+2.0.1 2001 PSF yes
648
+ 2.1.2 2.1.1 2002 PSF yes
649
+ 2.1.3 2.1.2 2002 PSF yes
650
+ 2.2 and above 2.1.1 2001-now PSF yes
651
+
652
+ Footnotes:
653
+
654
+ (1) GPL-compatible doesn't mean that we're distributing Python under
655
+ the GPL. All Python licenses, unlike the GPL, let you distribute
656
+ a modified version without making your changes open source. The
657
+ GPL-compatible licenses make it possible to combine Python with
658
+ other software that is released under the GPL; the others don't.
659
+
660
+ (2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
661
+ because its license has a choice of law clause. According to
662
+ CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
663
+ is "not incompatible" with the GPL.
664
+
665
+ Thanks to the many outside volunteers who have worked under Guido's
666
+ direction to make these releases possible.
667
+
668
+
669
+ B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
670
+ ===============================================================
671
+
672
+ Python software and documentation are licensed under the
673
+ Python Software Foundation License Version 2.
674
+
675
+ Starting with Python 3.8.6, examples, recipes, and other code in
676
+ the documentation are dual licensed under the PSF License Version 2
677
+ and the Zero-Clause BSD license.
678
+
679
+ Some software incorporated into Python is under different licenses.
680
+ The licenses are listed with code falling under that license.
681
+
682
+
683
+ PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
684
+ --------------------------------------------
685
+
686
+ 1. This LICENSE AGREEMENT is between the Python Software Foundation
687
+ ("PSF"), and the Individual or Organization ("Licensee") accessing and
688
+ otherwise using this software ("Python") in source or binary form and
689
+ its associated documentation.
690
+
691
+ 2. Subject to the terms and conditions of this License Agreement, PSF hereby
692
+ grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
693
+ analyze, test, perform and/or display publicly, prepare derivative works,
694
+ distribute, and otherwise use Python alone or in any derivative version,
695
+ provided, however, that PSF's License Agreement and PSF's notice of copyright,
696
+ i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
697
+ 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
698
+ All Rights Reserved" are retained in Python alone or in any derivative version
699
+ prepared by Licensee.
700
+
701
+ 3. In the event Licensee prepares a derivative work that is based on
702
+ or incorporates Python or any part thereof, and wants to make
703
+ the derivative work available to others as provided herein, then
704
+ Licensee hereby agrees to include in any such work a brief summary of
705
+ the changes made to Python.
706
+
707
+ 4. PSF is making Python available to Licensee on an "AS IS"
708
+ basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
709
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
710
+ DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
711
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
712
+ INFRINGE ANY THIRD PARTY RIGHTS.
713
+
714
+ 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
715
+ FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
716
+ A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
717
+ OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
718
+
719
+ 6. This License Agreement will automatically terminate upon a material
720
+ breach of its terms and conditions.
721
+
722
+ 7. Nothing in this License Agreement shall be deemed to create any
723
+ relationship of agency, partnership, or joint venture between PSF and
724
+ Licensee. This License Agreement does not grant permission to use PSF
725
+ trademarks or trade name in a trademark sense to endorse or promote
726
+ products or services of Licensee, or any third party.
727
+
728
+ 8. By copying, installing or otherwise using Python, Licensee
729
+ agrees to be bound by the terms and conditions of this License
730
+ Agreement.
731
+
732
+
733
+ BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
734
+ -------------------------------------------
735
+
736
+ BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
737
+
738
+ 1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
739
+ office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
740
+ Individual or Organization ("Licensee") accessing and otherwise using
741
+ this software in source or binary form and its associated
742
+ documentation ("the Software").
743
+
744
+ 2. Subject to the terms and conditions of this BeOpen Python License
745
+ Agreement, BeOpen hereby grants Licensee a non-exclusive,
746
+ royalty-free, world-wide license to reproduce, analyze, test, perform
747
+ and/or display publicly, prepare derivative works, distribute, and
748
+ otherwise use the Software alone or in any derivative version,
749
+ provided, however, that the BeOpen Python License is retained in the
750
+ Software, alone or in any derivative version prepared by Licensee.
751
+
752
+ 3. BeOpen is making the Software available to Licensee on an "AS IS"
753
+ basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
754
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
755
+ DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
756
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
757
+ INFRINGE ANY THIRD PARTY RIGHTS.
758
+
759
+ 4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
760
+ SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
761
+ AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
762
+ DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
763
+
764
+ 5. This License Agreement will automatically terminate upon a material
765
+ breach of its terms and conditions.
766
+
767
+ 6. This License Agreement shall be governed by and interpreted in all
768
+ respects by the law of the State of California, excluding conflict of
769
+ law provisions. Nothing in this License Agreement shall be deemed to
770
+ create any relationship of agency, partnership, or joint venture
771
+ between BeOpen and Licensee. This License Agreement does not grant
772
+ permission to use BeOpen trademarks or trade names in a trademark
773
+ sense to endorse or promote products or services of Licensee, or any
774
+ third party. As an exception, the "BeOpen Python" logos available at
775
+ http://www.pythonlabs.com/logos.html may be used according to the
776
+ permissions granted on that web page.
777
+
778
+ 7. By copying, installing or otherwise using the software, Licensee
779
+ agrees to be bound by the terms and conditions of this License
780
+ Agreement.
781
+
782
+
783
+ CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
784
+ ---------------------------------------
785
+
786
+ 1. This LICENSE AGREEMENT is between the Corporation for National
787
+ Research Initiatives, having an office at 1895 Preston White Drive,
788
+ Reston, VA 20191 ("CNRI"), and the Individual or Organization
789
+ ("Licensee") accessing and otherwise using Python 1.6.1 software in
790
+ source or binary form and its associated documentation.
791
+
792
+ 2. Subject to the terms and conditions of this License Agreement, CNRI
793
+ hereby grants Licensee a nonexclusive, royalty-free, world-wide
794
+ license to reproduce, analyze, test, perform and/or display publicly,
795
+ prepare derivative works, distribute, and otherwise use Python 1.6.1
796
+ alone or in any derivative version, provided, however, that CNRI's
797
+ License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
798
+ 1995-2001 Corporation for National Research Initiatives; All Rights
799
+ Reserved" are retained in Python 1.6.1 alone or in any derivative
800
+ version prepared by Licensee. Alternately, in lieu of CNRI's License
801
+ Agreement, Licensee may substitute the following text (omitting the
802
+ quotes): "Python 1.6.1 is made available subject to the terms and
803
+ conditions in CNRI's License Agreement. This Agreement together with
804
+ Python 1.6.1 may be located on the internet using the following
805
+ unique, persistent identifier (known as a handle): 1895.22/1013. This
806
+ Agreement may also be obtained from a proxy server on the internet
807
+ using the following URL: http://hdl.handle.net/1895.22/1013".
808
+
809
+ 3. In the event Licensee prepares a derivative work that is based on
810
+ or incorporates Python 1.6.1 or any part thereof, and wants to make
811
+ the derivative work available to others as provided herein, then
812
+ Licensee hereby agrees to include in any such work a brief summary of
813
+ the changes made to Python 1.6.1.
814
+
815
+ 4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
816
+ basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
817
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
818
+ DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
819
+ FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
820
+ INFRINGE ANY THIRD PARTY RIGHTS.
821
+
822
+ 5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
823
+ 1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
824
+ A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
825
+ OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
826
+
827
+ 6. This License Agreement will automatically terminate upon a material
828
+ breach of its terms and conditions.
829
+
830
+ 7. This License Agreement shall be governed by the federal
831
+ intellectual property law of the United States, including without
832
+ limitation the federal copyright law, and, to the extent such
833
+ U.S. federal law does not apply, by the law of the Commonwealth of
834
+ Virginia, excluding Virginia's conflict of law provisions.
835
+ Notwithstanding the foregoing, with regard to derivative works based
836
+ on Python 1.6.1 that incorporate non-separable material that was
837
+ previously distributed under the GNU General Public License (GPL), the
838
+ law of the Commonwealth of Virginia shall govern this License
839
+ Agreement only as to issues arising under or with respect to
840
+ Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
841
+ License Agreement shall be deemed to create any relationship of
842
+ agency, partnership, or joint venture between CNRI and Licensee. This
843
+ License Agreement does not grant permission to use CNRI trademarks or
844
+ trade name in a trademark sense to endorse or promote products or
845
+ services of Licensee, or any third party.
846
+
847
+ 8. By clicking on the "ACCEPT" button where indicated, or by copying,
848
+ installing or otherwise using Python 1.6.1, Licensee agrees to be
849
+ bound by the terms and conditions of this License Agreement.
850
+
851
+ ACCEPT
852
+
853
+
854
+ CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
855
+ --------------------------------------------------
856
+
857
+ Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
858
+ The Netherlands. All rights reserved.
859
+
860
+ Permission to use, copy, modify, and distribute this software and its
861
+ documentation for any purpose and without fee is hereby granted,
862
+ provided that the above copyright notice appear in all copies and that
863
+ both that copyright notice and this permission notice appear in
864
+ supporting documentation, and that the name of Stichting Mathematisch
865
+ Centrum or CWI not be used in advertising or publicity pertaining to
866
+ distribution of the software without specific, written prior
867
+ permission.
868
+
869
+ STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
870
+ THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
871
+ FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
872
+ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
873
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
874
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
875
+ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
876
+
877
+ ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
878
+ ----------------------------------------------------------------------
879
+
880
+ Permission to use, copy, modify, and/or distribute this software for any
881
+ purpose with or without fee is hereby granted.
882
+
883
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
884
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
885
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
886
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
887
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
888
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
889
+ PERFORMANCE OF THIS SOFTWARE.
890
+ Copyright (c) 2014, Al Sweigart
891
+ All rights reserved.
892
+
893
+ Redistribution and use in source and binary forms, with or without
894
+ modification, are permitted provided that the following conditions are met:
895
+
896
+ * Redistributions of source code must retain the above copyright notice, this
897
+ list of conditions and the following disclaimer.
898
+
899
+ * Redistributions in binary form must reproduce the above copyright notice,
900
+ this list of conditions and the following disclaimer in the documentation
901
+ and/or other materials provided with the distribution.
902
+
903
+ * Neither the name of the {organization} nor the names of its
904
+ contributors may be used to endorse or promote products derived from
905
+ this software without specific prior written permission.
906
+
907
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
908
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
909
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
910
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
911
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
912
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
913
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
914
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
915
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
916
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Copyright (c) 2017 Anthony Sottile
917
+
918
+ Permission is hereby granted, free of charge, to any person obtaining a copy
919
+ of this software and associated documentation files (the "Software"), to deal
920
+ in the Software without restriction, including without limitation the rights
921
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
922
+ copies of the Software, and to permit persons to whom the Software is
923
+ furnished to do so, subject to the following conditions:
924
+
925
+ The above copyright notice and this permission notice shall be included in
926
+ all copies or substantial portions of the Software.
927
+
928
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
929
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
930
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
931
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
932
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
933
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
934
+ THE SOFTWARE.Copyright (c) 2015-2019 Jared Hobbs
935
+
936
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
937
+ this software and associated documentation files (the "Software"), to deal in
938
+ the Software without restriction, including without limitation the rights to
939
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
940
+ of the Software, and to permit persons to whom the Software is furnished to do
941
+ so, subject to the following conditions:
942
+
943
+ The above copyright notice and this permission notice shall be included in all
944
+ copies or substantial portions of the Software.
945
+
946
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
947
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
948
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
949
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
950
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
951
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
952
+ SOFTWARE.Developed by ESN, an Electronic Arts Inc. studio.
953
+ Copyright (c) 2014, Electronic Arts Inc.
954
+ All rights reserved.
955
+
956
+ Redistribution and use in source and binary forms, with or without
957
+ modification, are permitted provided that the following conditions are met:
958
+ * Redistributions of source code must retain the above copyright
959
+ notice, this list of conditions and the following disclaimer.
960
+ * Redistributions in binary form must reproduce the above copyright
961
+ notice, this list of conditions and the following disclaimer in the
962
+ documentation and/or other materials provided with the distribution.
963
+ * Neither the name of ESN, Electronic Arts Inc. nor the
964
+ names of its contributors may be used to endorse or promote products
965
+ derived from this software without specific prior written permission.
966
+
967
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
968
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
969
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
970
+ DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS INC. BE LIABLE
971
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
972
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
973
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
974
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
975
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
976
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
977
+
978
+ ----
979
+
980
+ Portions of code from MODP_ASCII - Ascii transformations (upper/lower, etc)
981
+ https://github.com/client9/stringencoders
982
+
983
+ Copyright 2005, 2006, 2007
984
+ Nick Galbreath -- nickg [at] modp [dot] com
985
+ All rights reserved.
986
+
987
+ Redistribution and use in source and binary forms, with or without
988
+ modification, are permitted provided that the following conditions are
989
+ met:
990
+
991
+ Redistributions of source code must retain the above copyright
992
+ notice, this list of conditions and the following disclaimer.
993
+
994
+ Redistributions in binary form must reproduce the above copyright
995
+ notice, this list of conditions and the following disclaimer in the
996
+ documentation and/or other materials provided with the distribution.
997
+
998
+ Neither the name of the modp.com nor the names of its
999
+ contributors may be used to endorse or promote products derived from
1000
+ this software without specific prior written permission.
1001
+
1002
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1003
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1004
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1005
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1006
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1007
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1008
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1009
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1010
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1011
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1012
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1013
+
1014
+ This is the standard "new" BSD license:
1015
+ http://www.opensource.org/licenses/bsd-license.php
1016
+
1017
+ https://github.com/client9/stringencoders/blob/cfd5c1507325ae497ea9bacdacba12c0ffd79d30/COPYING
1018
+
1019
+ ----
1020
+
1021
+ Numeric decoder derived from from TCL library
1022
+ https://opensource.apple.com/source/tcl/tcl-14/tcl/license.terms
1023
+ * Copyright (c) 1988-1993 The Regents of the University of California.
1024
+ * Copyright (c) 1994 Sun Microsystems, Inc.
1025
+
1026
+ This software is copyrighted by the Regents of the University of
1027
+ California, Sun Microsystems, Inc., Scriptics Corporation, ActiveState
1028
+ Corporation and other parties. The following terms apply to all files
1029
+ associated with the software unless explicitly disclaimed in
1030
+ individual files.
1031
+
1032
+ The authors hereby grant permission to use, copy, modify, distribute,
1033
+ and license this software and its documentation for any purpose, provided
1034
+ that existing copyright notices are retained in all copies and that this
1035
+ notice is included verbatim in any distributions. No written agreement,
1036
+ license, or royalty fee is required for any of the authorized uses.
1037
+ Modifications to this software may be copyrighted by their authors
1038
+ and need not follow the licensing terms described here, provided that
1039
+ the new terms are clearly indicated on the first page of each file where
1040
+ they apply.
1041
+
1042
+ IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
1043
+ FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
1044
+ ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
1045
+ DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
1046
+ POSSIBILITY OF SUCH DAMAGE.
1047
+
1048
+ THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
1049
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
1050
+ FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
1051
+ IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
1052
+ NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
1053
+ MODIFICATIONS.
1054
+
1055
+ GOVERNMENT USE: If you are acquiring this software on behalf of the
1056
+ U.S. government, the Government shall have only "Restricted Rights"
1057
+ in the software and related documentation as defined in the Federal
1058
+ Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
1059
+ are acquiring the software on behalf of the Department of Defense, the
1060
+ software shall be classified as "Commercial Computer Software" and the
1061
+ Government shall have only "Restricted Rights" as defined in Clause
1062
+ 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
1063
+ authors grant the U.S. Government and others acting in its behalf
1064
+ permission to use and distribute the software in accordance with the
1065
+ terms specified in this license.Apache License
1066
+ Version 2.0, January 2004
1067
+ http://www.apache.org/licenses/
1068
+
1069
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1070
+
1071
+ 1. Definitions.
1072
+
1073
+ "License" shall mean the terms and conditions for use, reproduction, and
1074
+ distribution as defined by Sections 1 through 9 of this document.
1075
+
1076
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
1077
+ owner that is granting the License.
1078
+
1079
+ "Legal Entity" shall mean the union of the acting entity and all other entities
1080
+ that control, are controlled by, or are under common control with that entity.
1081
+ For the purposes of this definition, "control" means (i) the power, direct or
1082
+ indirect, to cause the direction or management of such entity, whether by
1083
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
1084
+ outstanding shares, or (iii) beneficial ownership of such entity.
1085
+
1086
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
1087
+ permissions granted by this License.
1088
+
1089
+ "Source" form shall mean the preferred form for making modifications, including
1090
+ but not limited to software source code, documentation source, and configuration
1091
+ files.
1092
+
1093
+ "Object" form shall mean any form resulting from mechanical transformation or
1094
+ translation of a Source form, including but not limited to compiled object code,
1095
+ generated documentation, and conversions to other media types.
1096
+
1097
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
1098
+ available under the License, as indicated by a copyright notice that is included
1099
+ in or attached to the work (an example is provided in the Appendix below).
1100
+
1101
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
1102
+ is based on (or derived from) the Work and for which the editorial revisions,
1103
+ annotations, elaborations, or other modifications represent, as a whole, an
1104
+ original work of authorship. For the purposes of this License, Derivative Works
1105
+ shall not include works that remain separable from, or merely link (or bind by
1106
+ name) to the interfaces of, the Work and Derivative Works thereof.
1107
+
1108
+ "Contribution" shall mean any work of authorship, including the original version
1109
+ of the Work and any modifications or additions to that Work or Derivative Works
1110
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
1111
+ by the copyright owner or by an individual or Legal Entity authorized to submit
1112
+ on behalf of the copyright owner. For the purposes of this definition,
1113
+ "submitted" means any form of electronic, verbal, or written communication sent
1114
+ to the Licensor or its representatives, including but not limited to
1115
+ communication on electronic mailing lists, source code control systems, and
1116
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
1117
+ the purpose of discussing and improving the Work, but excluding communication
1118
+ that is conspicuously marked or otherwise designated in writing by the copyright
1119
+ owner as "Not a Contribution."
1120
+
1121
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
1122
+ of whom a Contribution has been received by Licensor and subsequently
1123
+ incorporated within the Work.
1124
+
1125
+ 2. Grant of Copyright License.
1126
+
1127
+ Subject to the terms and conditions of this License, each Contributor hereby
1128
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
1129
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
1130
+ publicly display, publicly perform, sublicense, and distribute the Work and such
1131
+ Derivative Works in Source or Object form.
1132
+
1133
+ 3. Grant of Patent License.
1134
+
1135
+ Subject to the terms and conditions of this License, each Contributor hereby
1136
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
1137
+ irrevocable (except as stated in this section) patent license to make, have
1138
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
1139
+ such license applies only to those patent claims licensable by such Contributor
1140
+ that are necessarily infringed by their Contribution(s) alone or by combination
1141
+ of their Contribution(s) with the Work to which such Contribution(s) was
1142
+ submitted. If You institute patent litigation against any entity (including a
1143
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
1144
+ Contribution incorporated within the Work constitutes direct or contributory
1145
+ patent infringement, then any patent licenses granted to You under this License
1146
+ for that Work shall terminate as of the date such litigation is filed.
1147
+
1148
+ 4. Redistribution.
1149
+
1150
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
1151
+ in any medium, with or without modifications, and in Source or Object form,
1152
+ provided that You meet the following conditions:
1153
+
1154
+ You must give any other recipients of the Work or Derivative Works a copy of
1155
+ this License; and
1156
+ You must cause any modified files to carry prominent notices stating that You
1157
+ changed the files; and
1158
+ You must retain, in the Source form of any Derivative Works that You distribute,
1159
+ all copyright, patent, trademark, and attribution notices from the Source form
1160
+ of the Work, excluding those notices that do not pertain to any part of the
1161
+ Derivative Works; and
1162
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
1163
+ Derivative Works that You distribute must include a readable copy of the
1164
+ attribution notices contained within such NOTICE file, excluding those notices
1165
+ that do not pertain to any part of the Derivative Works, in at least one of the
1166
+ following places: within a NOTICE text file distributed as part of the
1167
+ Derivative Works; within the Source form or documentation, if provided along
1168
+ with the Derivative Works; or, within a display generated by the Derivative
1169
+ Works, if and wherever such third-party notices normally appear. The contents of
1170
+ the NOTICE file are for informational purposes only and do not modify the
1171
+ License. You may add Your own attribution notices within Derivative Works that
1172
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
1173
+ provided that such additional attribution notices cannot be construed as
1174
+ modifying the License.
1175
+ You may add Your own copyright statement to Your modifications and may provide
1176
+ additional or different license terms and conditions for use, reproduction, or
1177
+ distribution of Your modifications, or for any such Derivative Works as a whole,
1178
+ provided Your use, reproduction, and distribution of the Work otherwise complies
1179
+ with the conditions stated in this License.
1180
+
1181
+ 5. Submission of Contributions.
1182
+
1183
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
1184
+ for inclusion in the Work by You to the Licensor shall be under the terms and
1185
+ conditions of this License, without any additional terms or conditions.
1186
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
1187
+ any separate license agreement you may have executed with Licensor regarding
1188
+ such Contributions.
1189
+
1190
+ 6. Trademarks.
1191
+
1192
+ This License does not grant permission to use the trade names, trademarks,
1193
+ service marks, or product names of the Licensor, except as required for
1194
+ reasonable and customary use in describing the origin of the Work and
1195
+ reproducing the content of the NOTICE file.
1196
+
1197
+ 7. Disclaimer of Warranty.
1198
+
1199
+ Unless required by applicable law or agreed to in writing, Licensor provides the
1200
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
1201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
1202
+ including, without limitation, any warranties or conditions of TITLE,
1203
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
1204
+ solely responsible for determining the appropriateness of using or
1205
+ redistributing the Work and assume any risks associated with Your exercise of
1206
+ permissions under this License.
1207
+
1208
+ 8. Limitation of Liability.
1209
+
1210
+ In no event and under no legal theory, whether in tort (including negligence),
1211
+ contract, or otherwise, unless required by applicable law (such as deliberate
1212
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
1213
+ liable to You for damages, including any direct, indirect, special, incidental,
1214
+ or consequential damages of any character arising as a result of this License or
1215
+ out of the use or inability to use the Work (including but not limited to
1216
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
1217
+ any and all other commercial damages or losses), even if such Contributor has
1218
+ been advised of the possibility of such damages.
1219
+
1220
+ 9. Accepting Warranty or Additional Liability.
1221
+
1222
+ While redistributing the Work or Derivative Works thereof, You may choose to
1223
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
1224
+ other liability obligations and/or rights consistent with this License. However,
1225
+ in accepting such obligations, You may act only on Your own behalf and on Your
1226
+ sole responsibility, not on behalf of any other Contributor, and only if You
1227
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
1228
+ incurred by, or claims asserted against, such Contributor by reason of your
1229
+ accepting any such warranty or additional liability.
1230
+
1231
+ END OF TERMS AND CONDITIONS
1232
+
1233
+ APPENDIX: How to apply the Apache License to your work
1234
+
1235
+ To apply the Apache License to your work, attach the following boilerplate
1236
+ notice, with the fields enclosed by brackets "[]" replaced with your own
1237
+ identifying information. (Don't include the brackets!) The text should be
1238
+ enclosed in the appropriate comment syntax for the file format. We also
1239
+ recommend that a file or class name and description of purpose be included on
1240
+ the same "printed page" as the copyright notice for easier identification within
1241
+ third-party archives.
1242
+
1243
+ Copyright [yyyy] [name of copyright owner]
1244
+
1245
+ Licensed under the Apache License, Version 2.0 (the "License");
1246
+ you may not use this file except in compliance with the License.
1247
+ You may obtain a copy of the License at
1248
+
1249
+ http://www.apache.org/licenses/LICENSE-2.0
1250
+
1251
+ Unless required by applicable law or agreed to in writing, software
1252
+ distributed under the License is distributed on an "AS IS" BASIS,
1253
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1254
+ See the License for the specific language governing permissions and
1255
+ limitations under the License.
1256
+ Classifier: Development Status :: 5 - Production/Stable
1257
+ Classifier: Environment :: Console
1258
+ Classifier: Intended Audience :: Science/Research
1259
+ Classifier: License :: OSI Approved :: BSD License
1260
+ Classifier: Operating System :: OS Independent
1261
+ Classifier: Programming Language :: Cython
1262
+ Classifier: Programming Language :: Python
1263
+ Classifier: Programming Language :: Python :: 3
1264
+ Classifier: Programming Language :: Python :: 3 :: Only
1265
+ Classifier: Programming Language :: Python :: 3.9
1266
+ Classifier: Programming Language :: Python :: 3.10
1267
+ Classifier: Programming Language :: Python :: 3.11
1268
+ Classifier: Programming Language :: Python :: 3.12
1269
+ Classifier: Programming Language :: Python :: 3.13
1270
+ Classifier: Programming Language :: Python :: 3.14
1271
+ Classifier: Topic :: Scientific/Engineering
1272
+ Project-URL: homepage, https://pandas.pydata.org
1273
+ Project-URL: documentation, https://pandas.pydata.org/docs/
1274
+ Project-URL: repository, https://github.com/pandas-dev/pandas
1275
+ Requires-Python: >=3.9
1276
+ Requires-Dist: numpy>=1.22.4; python_version < "3.11"
1277
+ Requires-Dist: numpy>=1.23.2; python_version == "3.11"
1278
+ Requires-Dist: numpy>=1.26.0; python_version >= "3.12"
1279
+ Requires-Dist: python-dateutil>=2.8.2
1280
+ Requires-Dist: pytz>=2020.1
1281
+ Requires-Dist: tzdata>=2022.7
1282
+ Provides-Extra: test
1283
+ Requires-Dist: hypothesis>=6.46.1; extra == "test"
1284
+ Requires-Dist: pytest>=7.3.2; extra == "test"
1285
+ Requires-Dist: pytest-xdist>=2.2.0; extra == "test"
1286
+ Provides-Extra: pyarrow
1287
+ Requires-Dist: pyarrow>=10.0.1; extra == "pyarrow"
1288
+ Provides-Extra: performance
1289
+ Requires-Dist: bottleneck>=1.3.6; extra == "performance"
1290
+ Requires-Dist: numba>=0.56.4; extra == "performance"
1291
+ Requires-Dist: numexpr>=2.8.4; extra == "performance"
1292
+ Provides-Extra: computation
1293
+ Requires-Dist: scipy>=1.10.0; extra == "computation"
1294
+ Requires-Dist: xarray>=2022.12.0; extra == "computation"
1295
+ Provides-Extra: fss
1296
+ Requires-Dist: fsspec>=2022.11.0; extra == "fss"
1297
+ Provides-Extra: aws
1298
+ Requires-Dist: s3fs>=2022.11.0; extra == "aws"
1299
+ Provides-Extra: gcp
1300
+ Requires-Dist: gcsfs>=2022.11.0; extra == "gcp"
1301
+ Requires-Dist: pandas-gbq>=0.19.0; extra == "gcp"
1302
+ Provides-Extra: excel
1303
+ Requires-Dist: odfpy>=1.4.1; extra == "excel"
1304
+ Requires-Dist: openpyxl>=3.1.0; extra == "excel"
1305
+ Requires-Dist: python-calamine>=0.1.7; extra == "excel"
1306
+ Requires-Dist: pyxlsb>=1.0.10; extra == "excel"
1307
+ Requires-Dist: xlrd>=2.0.1; extra == "excel"
1308
+ Requires-Dist: xlsxwriter>=3.0.5; extra == "excel"
1309
+ Provides-Extra: parquet
1310
+ Requires-Dist: pyarrow>=10.0.1; extra == "parquet"
1311
+ Provides-Extra: feather
1312
+ Requires-Dist: pyarrow>=10.0.1; extra == "feather"
1313
+ Provides-Extra: hdf5
1314
+ Requires-Dist: tables>=3.8.0; extra == "hdf5"
1315
+ Provides-Extra: spss
1316
+ Requires-Dist: pyreadstat>=1.2.0; extra == "spss"
1317
+ Provides-Extra: postgresql
1318
+ Requires-Dist: SQLAlchemy>=2.0.0; extra == "postgresql"
1319
+ Requires-Dist: psycopg2>=2.9.6; extra == "postgresql"
1320
+ Requires-Dist: adbc-driver-postgresql>=0.8.0; extra == "postgresql"
1321
+ Provides-Extra: mysql
1322
+ Requires-Dist: SQLAlchemy>=2.0.0; extra == "mysql"
1323
+ Requires-Dist: pymysql>=1.0.2; extra == "mysql"
1324
+ Provides-Extra: sql-other
1325
+ Requires-Dist: SQLAlchemy>=2.0.0; extra == "sql-other"
1326
+ Requires-Dist: adbc-driver-postgresql>=0.8.0; extra == "sql-other"
1327
+ Requires-Dist: adbc-driver-sqlite>=0.8.0; extra == "sql-other"
1328
+ Provides-Extra: html
1329
+ Requires-Dist: beautifulsoup4>=4.11.2; extra == "html"
1330
+ Requires-Dist: html5lib>=1.1; extra == "html"
1331
+ Requires-Dist: lxml>=4.9.2; extra == "html"
1332
+ Provides-Extra: xml
1333
+ Requires-Dist: lxml>=4.9.2; extra == "xml"
1334
+ Provides-Extra: plot
1335
+ Requires-Dist: matplotlib>=3.6.3; extra == "plot"
1336
+ Provides-Extra: output-formatting
1337
+ Requires-Dist: jinja2>=3.1.2; extra == "output-formatting"
1338
+ Requires-Dist: tabulate>=0.9.0; extra == "output-formatting"
1339
+ Provides-Extra: clipboard
1340
+ Requires-Dist: PyQt5>=5.15.9; extra == "clipboard"
1341
+ Requires-Dist: qtpy>=2.3.0; extra == "clipboard"
1342
+ Provides-Extra: compression
1343
+ Requires-Dist: zstandard>=0.19.0; extra == "compression"
1344
+ Provides-Extra: consortium-standard
1345
+ Requires-Dist: dataframe-api-compat>=0.1.7; extra == "consortium-standard"
1346
+ Provides-Extra: all
1347
+ Requires-Dist: adbc-driver-postgresql>=0.8.0; extra == "all"
1348
+ Requires-Dist: adbc-driver-sqlite>=0.8.0; extra == "all"
1349
+ Requires-Dist: beautifulsoup4>=4.11.2; extra == "all"
1350
+ Requires-Dist: bottleneck>=1.3.6; extra == "all"
1351
+ Requires-Dist: dataframe-api-compat>=0.1.7; extra == "all"
1352
+ Requires-Dist: fastparquet>=2022.12.0; extra == "all"
1353
+ Requires-Dist: fsspec>=2022.11.0; extra == "all"
1354
+ Requires-Dist: gcsfs>=2022.11.0; extra == "all"
1355
+ Requires-Dist: html5lib>=1.1; extra == "all"
1356
+ Requires-Dist: hypothesis>=6.46.1; extra == "all"
1357
+ Requires-Dist: jinja2>=3.1.2; extra == "all"
1358
+ Requires-Dist: lxml>=4.9.2; extra == "all"
1359
+ Requires-Dist: matplotlib>=3.6.3; extra == "all"
1360
+ Requires-Dist: numba>=0.56.4; extra == "all"
1361
+ Requires-Dist: numexpr>=2.8.4; extra == "all"
1362
+ Requires-Dist: odfpy>=1.4.1; extra == "all"
1363
+ Requires-Dist: openpyxl>=3.1.0; extra == "all"
1364
+ Requires-Dist: pandas-gbq>=0.19.0; extra == "all"
1365
+ Requires-Dist: psycopg2>=2.9.6; extra == "all"
1366
+ Requires-Dist: pyarrow>=10.0.1; extra == "all"
1367
+ Requires-Dist: pymysql>=1.0.2; extra == "all"
1368
+ Requires-Dist: PyQt5>=5.15.9; extra == "all"
1369
+ Requires-Dist: pyreadstat>=1.2.0; extra == "all"
1370
+ Requires-Dist: pytest>=7.3.2; extra == "all"
1371
+ Requires-Dist: pytest-xdist>=2.2.0; extra == "all"
1372
+ Requires-Dist: python-calamine>=0.1.7; extra == "all"
1373
+ Requires-Dist: pyxlsb>=1.0.10; extra == "all"
1374
+ Requires-Dist: qtpy>=2.3.0; extra == "all"
1375
+ Requires-Dist: scipy>=1.10.0; extra == "all"
1376
+ Requires-Dist: s3fs>=2022.11.0; extra == "all"
1377
+ Requires-Dist: SQLAlchemy>=2.0.0; extra == "all"
1378
+ Requires-Dist: tables>=3.8.0; extra == "all"
1379
+ Requires-Dist: tabulate>=0.9.0; extra == "all"
1380
+ Requires-Dist: xarray>=2022.12.0; extra == "all"
1381
+ Requires-Dist: xlrd>=2.0.1; extra == "all"
1382
+ Requires-Dist: xlsxwriter>=3.0.5; extra == "all"
1383
+ Requires-Dist: zstandard>=0.19.0; extra == "all"
1384
+ Description-Content-Type: text/markdown
1385
+
1386
+ <div align="center">
1387
+ <img src="https://pandas.pydata.org/static/img/pandas.svg"><br>
1388
+ </div>
1389
+
1390
+ -----------------
1391
+
1392
+ # pandas: powerful Python data analysis toolkit
1393
+
1394
+ | | |
1395
+ | --- | --- |
1396
+ | Testing | [![CI - Test](https://github.com/pandas-dev/pandas/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/pandas-dev/pandas/actions/workflows/unit-tests.yml) [![Coverage](https://codecov.io/github/pandas-dev/pandas/coverage.svg?branch=main)](https://codecov.io/gh/pandas-dev/pandas) |
1397
+ | Package | [![PyPI Latest Release](https://img.shields.io/pypi/v/pandas.svg)](https://pypi.org/project/pandas/) [![PyPI Downloads](https://img.shields.io/pypi/dm/pandas.svg?label=PyPI%20downloads)](https://pypi.org/project/pandas/) [![Conda Latest Release](https://anaconda.org/conda-forge/pandas/badges/version.svg)](https://anaconda.org/conda-forge/pandas) [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/pandas.svg?label=Conda%20downloads)](https://anaconda.org/conda-forge/pandas) |
1398
+ | Meta | [![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3509134.svg)](https://doi.org/10.5281/zenodo.3509134) [![License - BSD 3-Clause](https://img.shields.io/pypi/l/pandas.svg)](https://github.com/pandas-dev/pandas/blob/main/LICENSE) [![Slack](https://img.shields.io/badge/join_Slack-information-brightgreen.svg?logo=slack)](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack) |
1399
+
1400
+
1401
+ ## What is it?
1402
+
1403
+ **pandas** is a Python package that provides fast, flexible, and expressive data
1404
+ structures designed to make working with "relational" or "labeled" data both
1405
+ easy and intuitive. It aims to be the fundamental high-level building block for
1406
+ doing practical, **real world** data analysis in Python. Additionally, it has
1407
+ the broader goal of becoming **the most powerful and flexible open source data
1408
+ analysis / manipulation tool available in any language**. It is already well on
1409
+ its way towards this goal.
1410
+
1411
+ ## Table of Contents
1412
+
1413
+ - [Main Features](#main-features)
1414
+ - [Where to get it](#where-to-get-it)
1415
+ - [Dependencies](#dependencies)
1416
+ - [Installation from sources](#installation-from-sources)
1417
+ - [License](#license)
1418
+ - [Documentation](#documentation)
1419
+ - [Background](#background)
1420
+ - [Getting Help](#getting-help)
1421
+ - [Discussion and Development](#discussion-and-development)
1422
+ - [Contributing to pandas](#contributing-to-pandas)
1423
+
1424
+ ## Main Features
1425
+ Here are just a few of the things that pandas does well:
1426
+
1427
+ - Easy handling of [**missing data**][missing-data] (represented as
1428
+ `NaN`, `NA`, or `NaT`) in floating point as well as non-floating point data
1429
+ - Size mutability: columns can be [**inserted and
1430
+ deleted**][insertion-deletion] from DataFrame and higher dimensional
1431
+ objects
1432
+ - Automatic and explicit [**data alignment**][alignment]: objects can
1433
+ be explicitly aligned to a set of labels, or the user can simply
1434
+ ignore the labels and let `Series`, `DataFrame`, etc. automatically
1435
+ align the data for you in computations
1436
+ - Powerful, flexible [**group by**][groupby] functionality to perform
1437
+ split-apply-combine operations on data sets, for both aggregating
1438
+ and transforming data
1439
+ - Make it [**easy to convert**][conversion] ragged,
1440
+ differently-indexed data in other Python and NumPy data structures
1441
+ into DataFrame objects
1442
+ - Intelligent label-based [**slicing**][slicing], [**fancy
1443
+ indexing**][fancy-indexing], and [**subsetting**][subsetting] of
1444
+ large data sets
1445
+ - Intuitive [**merging**][merging] and [**joining**][joining] data
1446
+ sets
1447
+ - Flexible [**reshaping**][reshape] and [**pivoting**][pivot-table] of
1448
+ data sets
1449
+ - [**Hierarchical**][mi] labeling of axes (possible to have multiple
1450
+ labels per tick)
1451
+ - Robust IO tools for loading data from [**flat files**][flat-files]
1452
+ (CSV and delimited), [**Excel files**][excel], [**databases**][db],
1453
+ and saving/loading data from the ultrafast [**HDF5 format**][hdfstore]
1454
+ - [**Time series**][timeseries]-specific functionality: date range
1455
+ generation and frequency conversion, moving window statistics,
1456
+ date shifting and lagging
1457
+
1458
+
1459
+ [missing-data]: https://pandas.pydata.org/pandas-docs/stable/user_guide/missing_data.html
1460
+ [insertion-deletion]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html#column-selection-addition-deletion
1461
+ [alignment]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html?highlight=alignment#intro-to-data-structures
1462
+ [groupby]: https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#group-by-split-apply-combine
1463
+ [conversion]: https://pandas.pydata.org/pandas-docs/stable/user_guide/dsintro.html#dataframe
1464
+ [slicing]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#slicing-ranges
1465
+ [fancy-indexing]: https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#advanced
1466
+ [subsetting]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#boolean-indexing
1467
+ [merging]: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#database-style-dataframe-or-named-series-joining-merging
1468
+ [joining]: https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html#joining-on-index
1469
+ [reshape]: https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html
1470
+ [pivot-table]: https://pandas.pydata.org/pandas-docs/stable/user_guide/reshaping.html
1471
+ [mi]: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#hierarchical-indexing-multiindex
1472
+ [flat-files]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#csv-text-files
1473
+ [excel]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#excel-files
1474
+ [db]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#sql-queries
1475
+ [hdfstore]: https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#hdf5-pytables
1476
+ [timeseries]: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#time-series-date-functionality
1477
+
1478
+ ## Where to get it
1479
+ The source code is currently hosted on GitHub at:
1480
+ https://github.com/pandas-dev/pandas
1481
+
1482
+ Binary installers for the latest released version are available at the [Python
1483
+ Package Index (PyPI)](https://pypi.org/project/pandas) and on [Conda](https://docs.conda.io/en/latest/).
1484
+
1485
+ ```sh
1486
+ # conda
1487
+ conda install -c conda-forge pandas
1488
+ ```
1489
+
1490
+ ```sh
1491
+ # or PyPI
1492
+ pip install pandas
1493
+ ```
1494
+
1495
+ The list of changes to pandas between each release can be found
1496
+ [here](https://pandas.pydata.org/pandas-docs/stable/whatsnew/index.html). For full
1497
+ details, see the commit logs at https://github.com/pandas-dev/pandas.
1498
+
1499
+ ## Dependencies
1500
+ - [NumPy - Adds support for large, multi-dimensional arrays, matrices and high-level mathematical functions to operate on these arrays](https://www.numpy.org)
1501
+ - [python-dateutil - Provides powerful extensions to the standard datetime module](https://dateutil.readthedocs.io/en/stable/index.html)
1502
+ - [pytz - Brings the Olson tz database into Python which allows accurate and cross platform timezone calculations](https://github.com/stub42/pytz)
1503
+
1504
+ See the [full installation instructions](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies) for minimum supported versions of required, recommended and optional dependencies.
1505
+
1506
+ ## Installation from sources
1507
+ To install pandas from source you need [Cython](https://cython.org/) in addition to the normal
1508
+ dependencies above. Cython can be installed from PyPI:
1509
+
1510
+ ```sh
1511
+ pip install cython
1512
+ ```
1513
+
1514
+ In the `pandas` directory (same one where you found this file after
1515
+ cloning the git repo), execute:
1516
+
1517
+ ```sh
1518
+ pip install .
1519
+ ```
1520
+
1521
+ or for installing in [development mode](https://pip.pypa.io/en/latest/cli/pip_install/#install-editable):
1522
+
1523
+
1524
+ ```sh
1525
+ python -m pip install -ve . --no-build-isolation --config-settings=editable-verbose=true
1526
+ ```
1527
+
1528
+ See the full instructions for [installing from source](https://pandas.pydata.org/docs/dev/development/contributing_environment.html).
1529
+
1530
+ ## License
1531
+ [BSD 3](LICENSE)
1532
+
1533
+ ## Documentation
1534
+ The official documentation is hosted on [PyData.org](https://pandas.pydata.org/pandas-docs/stable/).
1535
+
1536
+ ## Background
1537
+ Work on ``pandas`` started at [AQR](https://www.aqr.com/) (a quantitative hedge fund) in 2008 and
1538
+ has been under active development since then.
1539
+
1540
+ ## Getting Help
1541
+
1542
+ For usage questions, the best place to go to is [StackOverflow](https://stackoverflow.com/questions/tagged/pandas).
1543
+ Further, general questions and discussions can also take place on the [pydata mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata).
1544
+
1545
+ ## Discussion and Development
1546
+ Most development discussions take place on GitHub in this repo, via the [GitHub issue tracker](https://github.com/pandas-dev/pandas/issues).
1547
+
1548
+ Further, the [pandas-dev mailing list](https://mail.python.org/mailman/listinfo/pandas-dev) can also be used for specialized discussions or design issues, and a [Slack channel](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack) is available for quick development related questions.
1549
+
1550
+ There are also frequent [community meetings](https://pandas.pydata.org/docs/dev/development/community.html#community-meeting) for project maintainers open to the community as well as monthly [new contributor meetings](https://pandas.pydata.org/docs/dev/development/community.html#new-contributor-meeting) to help support new contributors.
1551
+
1552
+ Additional information on the communication channels can be found on the [contributor community](https://pandas.pydata.org/docs/development/community.html) page.
1553
+
1554
+ ## Contributing to pandas
1555
+
1556
+ [![Open Source Helpers](https://www.codetriage.com/pandas-dev/pandas/badges/users.svg)](https://www.codetriage.com/pandas-dev/pandas)
1557
+
1558
+ All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
1559
+
1560
+ A detailed overview on how to contribute can be found in the **[contributing guide](https://pandas.pydata.org/docs/dev/development/contributing.html)**.
1561
+
1562
+ If you are simply looking to start working with the pandas codebase, navigate to the [GitHub "issues" tab](https://github.com/pandas-dev/pandas/issues) and start looking through interesting issues. There are a number of issues listed under [Docs](https://github.com/pandas-dev/pandas/issues?labels=Docs&sort=updated&state=open) and [good first issue](https://github.com/pandas-dev/pandas/issues?labels=good+first+issue&sort=updated&state=open) where you could start out.
1563
+
1564
+ You can also triage issues which may include reproducing bug reports, or asking for vital information such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to pandas on CodeTriage](https://www.codetriage.com/pandas-dev/pandas).
1565
+
1566
+ Or maybe through using pandas you have an idea of your own or are looking for something in the documentation and thinking ‘this can be improved’...you can do something about it!
1567
+
1568
+ Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Slack](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack).
1569
+
1570
+ As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/.github/blob/master/CODE_OF_CONDUCT.md)
1571
+
1572
+ <hr>
1573
+
1574
+ [Go to Top](#table-of-contents)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/RECORD ADDED
The diff for this file is too large to render. See raw diff
 
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: meson
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-manylinux_2_24_x86_64
5
+ Tag: cp310-cp310-manylinux_2_28_x86_64
6
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas-2.3.3.dist-info/entry_points.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [pandas_plotting_backends]
2
+ matplotlib = pandas:plotting._matplotlib
3
+
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_isin.py ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Series,
7
+ date_range,
8
+ )
9
+ import pandas._testing as tm
10
+ from pandas.core import algorithms
11
+ from pandas.core.arrays import PeriodArray
12
+
13
+
14
+ class TestSeriesIsIn:
15
+ def test_isin(self):
16
+ s = Series(["A", "B", "C", "a", "B", "B", "A", "C"])
17
+
18
+ result = s.isin(["A", "C"])
19
+ expected = Series([True, False, True, False, False, False, True, True])
20
+ tm.assert_series_equal(result, expected)
21
+
22
+ # GH#16012
23
+ # This specific issue has to have a series over 1e6 in len, but the
24
+ # comparison array (in_list) must be large enough so that numpy doesn't
25
+ # do a manual masking trick that will avoid this issue altogether
26
+ s = Series(list("abcdefghijk" * 10**5))
27
+ # If numpy doesn't do the manual comparison/mask, these
28
+ # unorderable mixed types are what cause the exception in numpy
29
+ in_list = [-1, "a", "b", "G", "Y", "Z", "E", "K", "E", "S", "I", "R", "R"] * 6
30
+
31
+ assert s.isin(in_list).sum() == 200000
32
+
33
+ def test_isin_with_string_scalar(self):
34
+ # GH#4763
35
+ s = Series(["A", "B", "C", "a", "B", "B", "A", "C"])
36
+ msg = (
37
+ r"only list-like objects are allowed to be passed to isin\(\), "
38
+ r"you passed a `str`"
39
+ )
40
+ with pytest.raises(TypeError, match=msg):
41
+ s.isin("a")
42
+
43
+ s = Series(["aaa", "b", "c"])
44
+ with pytest.raises(TypeError, match=msg):
45
+ s.isin("aaa")
46
+
47
+ def test_isin_datetimelike_mismatched_reso(self):
48
+ expected = Series([True, True, False, False, False])
49
+
50
+ ser = Series(date_range("jan-01-2013", "jan-05-2013"))
51
+
52
+ # fails on dtype conversion in the first place
53
+ day_values = np.asarray(ser[0:2].values).astype("datetime64[D]")
54
+ result = ser.isin(day_values)
55
+ tm.assert_series_equal(result, expected)
56
+
57
+ dta = ser[:2]._values.astype("M8[s]")
58
+ result = ser.isin(dta)
59
+ tm.assert_series_equal(result, expected)
60
+
61
+ def test_isin_datetimelike_mismatched_reso_list(self):
62
+ expected = Series([True, True, False, False, False])
63
+
64
+ ser = Series(date_range("jan-01-2013", "jan-05-2013"))
65
+
66
+ dta = ser[:2]._values.astype("M8[s]")
67
+ result = ser.isin(list(dta))
68
+ tm.assert_series_equal(result, expected)
69
+
70
+ def test_isin_with_i8(self):
71
+ # GH#5021
72
+
73
+ expected = Series([True, True, False, False, False])
74
+ expected2 = Series([False, True, False, False, False])
75
+
76
+ # datetime64[ns]
77
+ s = Series(date_range("jan-01-2013", "jan-05-2013"))
78
+
79
+ result = s.isin(s[0:2])
80
+ tm.assert_series_equal(result, expected)
81
+
82
+ result = s.isin(s[0:2].values)
83
+ tm.assert_series_equal(result, expected)
84
+
85
+ result = s.isin([s[1]])
86
+ tm.assert_series_equal(result, expected2)
87
+
88
+ result = s.isin([np.datetime64(s[1])])
89
+ tm.assert_series_equal(result, expected2)
90
+
91
+ result = s.isin(set(s[0:2]))
92
+ tm.assert_series_equal(result, expected)
93
+
94
+ # timedelta64[ns]
95
+ s = Series(pd.to_timedelta(range(5), unit="d"))
96
+ result = s.isin(s[0:2])
97
+ tm.assert_series_equal(result, expected)
98
+
99
+ @pytest.mark.parametrize("empty", [[], Series(dtype=object), np.array([])])
100
+ def test_isin_empty(self, empty):
101
+ # see GH#16991
102
+ s = Series(["a", "b"])
103
+ expected = Series([False, False])
104
+
105
+ result = s.isin(empty)
106
+ tm.assert_series_equal(expected, result)
107
+
108
+ def test_isin_read_only(self):
109
+ # https://github.com/pandas-dev/pandas/issues/37174
110
+ arr = np.array([1, 2, 3])
111
+ arr.setflags(write=False)
112
+ s = Series([1, 2, 3])
113
+ result = s.isin(arr)
114
+ expected = Series([True, True, True])
115
+ tm.assert_series_equal(result, expected)
116
+
117
+ @pytest.mark.parametrize("dtype", [object, None])
118
+ def test_isin_dt64_values_vs_ints(self, dtype):
119
+ # GH#36621 dont cast integers to datetimes for isin
120
+ dti = date_range("2013-01-01", "2013-01-05")
121
+ ser = Series(dti)
122
+
123
+ comps = np.asarray([1356998400000000000], dtype=dtype)
124
+
125
+ res = dti.isin(comps)
126
+ expected = np.array([False] * len(dti), dtype=bool)
127
+ tm.assert_numpy_array_equal(res, expected)
128
+
129
+ res = ser.isin(comps)
130
+ tm.assert_series_equal(res, Series(expected))
131
+
132
+ res = pd.core.algorithms.isin(ser, comps)
133
+ tm.assert_numpy_array_equal(res, expected)
134
+
135
+ def test_isin_tzawareness_mismatch(self):
136
+ dti = date_range("2013-01-01", "2013-01-05")
137
+ ser = Series(dti)
138
+
139
+ other = dti.tz_localize("UTC")
140
+
141
+ res = dti.isin(other)
142
+ expected = np.array([False] * len(dti), dtype=bool)
143
+ tm.assert_numpy_array_equal(res, expected)
144
+
145
+ res = ser.isin(other)
146
+ tm.assert_series_equal(res, Series(expected))
147
+
148
+ res = pd.core.algorithms.isin(ser, other)
149
+ tm.assert_numpy_array_equal(res, expected)
150
+
151
+ def test_isin_period_freq_mismatch(self):
152
+ dti = date_range("2013-01-01", "2013-01-05")
153
+ pi = dti.to_period("M")
154
+ ser = Series(pi)
155
+
156
+ # We construct another PeriodIndex with the same i8 values
157
+ # but different dtype
158
+ dtype = dti.to_period("Y").dtype
159
+ other = PeriodArray._simple_new(pi.asi8, dtype=dtype)
160
+
161
+ res = pi.isin(other)
162
+ expected = np.array([False] * len(pi), dtype=bool)
163
+ tm.assert_numpy_array_equal(res, expected)
164
+
165
+ res = ser.isin(other)
166
+ tm.assert_series_equal(res, Series(expected))
167
+
168
+ res = pd.core.algorithms.isin(ser, other)
169
+ tm.assert_numpy_array_equal(res, expected)
170
+
171
+ @pytest.mark.parametrize("values", [[-9.0, 0.0], [-9, 0]])
172
+ def test_isin_float_in_int_series(self, values):
173
+ # GH#19356 GH#21804
174
+ ser = Series(values)
175
+ result = ser.isin([-9, -0.5])
176
+ expected = Series([True, False])
177
+ tm.assert_series_equal(result, expected)
178
+
179
+ @pytest.mark.parametrize("dtype", ["boolean", "Int64", "Float64"])
180
+ @pytest.mark.parametrize(
181
+ "data,values,expected",
182
+ [
183
+ ([0, 1, 0], [1], [False, True, False]),
184
+ ([0, 1, 0], [1, pd.NA], [False, True, False]),
185
+ ([0, pd.NA, 0], [1, 0], [True, False, True]),
186
+ ([0, 1, pd.NA], [1, pd.NA], [False, True, True]),
187
+ ([0, 1, pd.NA], [1, np.nan], [False, True, False]),
188
+ ([0, pd.NA, pd.NA], [np.nan, pd.NaT, None], [False, False, False]),
189
+ ],
190
+ )
191
+ def test_isin_masked_types(self, dtype, data, values, expected):
192
+ # GH#42405
193
+ ser = Series(data, dtype=dtype)
194
+
195
+ result = ser.isin(values)
196
+ expected = Series(expected, dtype="boolean")
197
+
198
+ tm.assert_series_equal(result, expected)
199
+
200
+
201
+ def test_isin_large_series_mixed_dtypes_and_nan(monkeypatch):
202
+ # https://github.com/pandas-dev/pandas/issues/37094
203
+ # combination of object dtype for the values
204
+ # and > _MINIMUM_COMP_ARR_LEN elements
205
+ min_isin_comp = 5
206
+ ser = Series([1, 2, np.nan] * min_isin_comp)
207
+ with monkeypatch.context() as m:
208
+ m.setattr(algorithms, "_MINIMUM_COMP_ARR_LEN", min_isin_comp)
209
+ result = ser.isin({"foo", "bar"})
210
+ expected = Series([False] * 3 * min_isin_comp)
211
+ tm.assert_series_equal(result, expected)
212
+
213
+
214
+ @pytest.mark.parametrize(
215
+ "array,expected",
216
+ [
217
+ (
218
+ [0, 1j, 1j, 1, 1 + 1j, 1 + 2j, 1 + 1j],
219
+ Series([False, True, True, False, True, True, True], dtype=bool),
220
+ )
221
+ ],
222
+ )
223
+ def test_isin_complex_numbers(array, expected):
224
+ # GH 17927
225
+ result = Series(array).isin([1j, 1 + 1j, 1 + 2j])
226
+ tm.assert_series_equal(result, expected)
227
+
228
+
229
+ @pytest.mark.parametrize(
230
+ "data,is_in",
231
+ [([1, [2]], [1]), (["simple str", [{"values": 3}]], ["simple str"])],
232
+ )
233
+ def test_isin_filtering_with_mixed_object_types(data, is_in):
234
+ # GH 20883
235
+
236
+ ser = Series(data)
237
+ result = ser.isin(is_in)
238
+ expected = Series([True, False])
239
+
240
+ tm.assert_series_equal(result, expected)
241
+
242
+
243
+ @pytest.mark.parametrize("data", [[1, 2, 3], [1.0, 2.0, 3.0]])
244
+ @pytest.mark.parametrize("isin", [[1, 2], [1.0, 2.0]])
245
+ def test_isin_filtering_on_iterable(data, isin):
246
+ # GH 50234
247
+
248
+ ser = Series(data)
249
+ result = ser.isin(i for i in isin)
250
+ expected_result = Series([True, True, False])
251
+
252
+ tm.assert_series_equal(result, expected_result)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_isna.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ We also test Series.notna in this file.
3
+ """
4
+ import numpy as np
5
+
6
+ from pandas import (
7
+ Period,
8
+ Series,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestIsna:
14
+ def test_isna_period_dtype(self):
15
+ # GH#13737
16
+ ser = Series([Period("2011-01", freq="M"), Period("NaT", freq="M")])
17
+
18
+ expected = Series([False, True])
19
+
20
+ result = ser.isna()
21
+ tm.assert_series_equal(result, expected)
22
+
23
+ result = ser.notna()
24
+ tm.assert_series_equal(result, ~expected)
25
+
26
+ def test_isna(self):
27
+ ser = Series([0, 5.4, 3, np.nan, -0.001])
28
+ expected = Series([False, False, False, True, False])
29
+ tm.assert_series_equal(ser.isna(), expected)
30
+ tm.assert_series_equal(ser.notna(), ~expected)
31
+
32
+ ser = Series(["hi", "", np.nan])
33
+ expected = Series([False, False, True])
34
+ tm.assert_series_equal(ser.isna(), expected)
35
+ tm.assert_series_equal(ser.notna(), ~expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_item.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Series.item method, mainly testing that we get python scalars as opposed to
3
+ numpy scalars.
4
+ """
5
+ import pytest
6
+
7
+ from pandas import (
8
+ Series,
9
+ Timedelta,
10
+ Timestamp,
11
+ date_range,
12
+ )
13
+
14
+
15
+ class TestItem:
16
+ def test_item(self):
17
+ # We are testing that we get python scalars as opposed to numpy scalars
18
+ ser = Series([1])
19
+ result = ser.item()
20
+ assert result == 1
21
+ assert result == ser.iloc[0]
22
+ assert isinstance(result, int) # i.e. not np.int64
23
+
24
+ ser = Series([0.5], index=[3])
25
+ result = ser.item()
26
+ assert isinstance(result, float)
27
+ assert result == 0.5
28
+
29
+ ser = Series([1, 2])
30
+ msg = "can only convert an array of size 1"
31
+ with pytest.raises(ValueError, match=msg):
32
+ ser.item()
33
+
34
+ dti = date_range("2016-01-01", periods=2)
35
+ with pytest.raises(ValueError, match=msg):
36
+ dti.item()
37
+ with pytest.raises(ValueError, match=msg):
38
+ Series(dti).item()
39
+
40
+ val = dti[:1].item()
41
+ assert isinstance(val, Timestamp)
42
+ val = Series(dti)[:1].item()
43
+ assert isinstance(val, Timestamp)
44
+
45
+ tdi = dti - dti
46
+ with pytest.raises(ValueError, match=msg):
47
+ tdi.item()
48
+ with pytest.raises(ValueError, match=msg):
49
+ Series(tdi).item()
50
+
51
+ val = tdi[:1].item()
52
+ assert isinstance(val, Timedelta)
53
+ val = Series(tdi)[:1].item()
54
+ assert isinstance(val, Timedelta)
55
+
56
+ # Case where ser[0] would not work
57
+ ser = Series(dti, index=[5, 6])
58
+ val = ser.iloc[:1].item()
59
+ assert val == dti[0]
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_map.py ADDED
@@ -0,0 +1,604 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import (
2
+ Counter,
3
+ defaultdict,
4
+ )
5
+ from decimal import Decimal
6
+ import math
7
+
8
+ import numpy as np
9
+ import pytest
10
+
11
+ import pandas as pd
12
+ from pandas import (
13
+ DataFrame,
14
+ Index,
15
+ MultiIndex,
16
+ Series,
17
+ bdate_range,
18
+ date_range,
19
+ isna,
20
+ timedelta_range,
21
+ )
22
+ import pandas._testing as tm
23
+
24
+
25
+ def test_series_map_box_timedelta():
26
+ # GH#11349
27
+ ser = Series(timedelta_range("1 day 1 s", periods=5, freq="h"))
28
+
29
+ def f(x):
30
+ return x.total_seconds()
31
+
32
+ ser.map(f)
33
+
34
+
35
+ def test_map_callable(datetime_series):
36
+ with np.errstate(all="ignore"):
37
+ tm.assert_series_equal(datetime_series.map(np.sqrt), np.sqrt(datetime_series))
38
+
39
+ # map function element-wise
40
+ tm.assert_series_equal(datetime_series.map(math.exp), np.exp(datetime_series))
41
+
42
+ # empty series
43
+ s = Series(dtype=object, name="foo", index=Index([], name="bar"))
44
+ rs = s.map(lambda x: x)
45
+ tm.assert_series_equal(s, rs)
46
+
47
+ # check all metadata (GH 9322)
48
+ assert s is not rs
49
+ assert s.index is rs.index
50
+ assert s.dtype == rs.dtype
51
+ assert s.name == rs.name
52
+
53
+ # index but no data
54
+ s = Series(index=[1, 2, 3], dtype=np.float64)
55
+ rs = s.map(lambda x: x)
56
+ tm.assert_series_equal(s, rs)
57
+
58
+
59
+ def test_map_same_length_inference_bug():
60
+ s = Series([1, 2])
61
+
62
+ def f(x):
63
+ return (x, x + 1)
64
+
65
+ s = Series([1, 2, 3])
66
+ result = s.map(f)
67
+ expected = Series([(1, 2), (2, 3), (3, 4)])
68
+ tm.assert_series_equal(result, expected)
69
+
70
+ s = Series(["foo,bar"])
71
+ result = s.map(lambda x: x.split(","))
72
+ expected = Series([("foo", "bar")])
73
+ tm.assert_series_equal(result, expected)
74
+
75
+
76
+ def test_series_map_box_timestamps():
77
+ # GH#2689, GH#2627
78
+ ser = Series(date_range("1/1/2000", periods=3))
79
+
80
+ def func(x):
81
+ return (x.hour, x.day, x.month)
82
+
83
+ result = ser.map(func)
84
+ expected = Series([(0, 1, 1), (0, 2, 1), (0, 3, 1)])
85
+ tm.assert_series_equal(result, expected)
86
+
87
+
88
+ def test_map_series_stringdtype(any_string_dtype, using_infer_string):
89
+ # map test on StringDType, GH#40823
90
+ ser1 = Series(
91
+ data=["cat", "dog", "rabbit"],
92
+ index=["id1", "id2", "id3"],
93
+ dtype=any_string_dtype,
94
+ )
95
+ ser2 = Series(["id3", "id2", "id1", "id7000"], dtype=any_string_dtype)
96
+ result = ser2.map(ser1)
97
+
98
+ item = pd.NA
99
+ if ser2.dtype == object:
100
+ item = np.nan
101
+
102
+ expected = Series(data=["rabbit", "dog", "cat", item], dtype=any_string_dtype)
103
+ if using_infer_string and any_string_dtype == "object":
104
+ expected = expected.astype("str")
105
+
106
+ tm.assert_series_equal(result, expected)
107
+
108
+
109
+ @pytest.mark.parametrize(
110
+ "data, expected_dtype",
111
+ [(["1-1", "1-1", np.nan], "category"), (["1-1", "1-2", np.nan], "str")],
112
+ )
113
+ def test_map_categorical_with_nan_values(data, expected_dtype):
114
+ # GH 20714 bug fixed in: GH 24275
115
+ def func(val):
116
+ return val.split("-")[0]
117
+
118
+ s = Series(data, dtype="category")
119
+
120
+ result = s.map(func, na_action="ignore")
121
+ expected = Series(["1", "1", np.nan], dtype=expected_dtype)
122
+ tm.assert_series_equal(result, expected)
123
+
124
+
125
+ def test_map_empty_integer_series():
126
+ # GH52384
127
+ s = Series([], dtype=int)
128
+ result = s.map(lambda x: x)
129
+ tm.assert_series_equal(result, s)
130
+
131
+
132
+ def test_map_empty_integer_series_with_datetime_index():
133
+ # GH 21245
134
+ s = Series([], index=date_range(start="2018-01-01", periods=0), dtype=int)
135
+ result = s.map(lambda x: x)
136
+ tm.assert_series_equal(result, s)
137
+
138
+
139
+ @pytest.mark.parametrize("func", [str, lambda x: str(x)])
140
+ def test_map_simple_str_callables_same_as_astype(
141
+ string_series, func, using_infer_string
142
+ ):
143
+ # test that we are evaluating row-by-row first
144
+ # before vectorized evaluation
145
+ result = string_series.map(func)
146
+ expected = string_series.astype(str if not using_infer_string else "str")
147
+ tm.assert_series_equal(result, expected)
148
+
149
+
150
+ def test_list_raises(string_series):
151
+ with pytest.raises(TypeError, match="'list' object is not callable"):
152
+ string_series.map([lambda x: x])
153
+
154
+
155
+ def test_map():
156
+ data = {
157
+ "A": [0.0, 1.0, 2.0, 3.0, 4.0],
158
+ "B": [0.0, 1.0, 0.0, 1.0, 0.0],
159
+ "C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
160
+ "D": bdate_range("1/1/2009", periods=5),
161
+ }
162
+
163
+ source = Series(data["B"], index=data["C"])
164
+ target = Series(data["C"][:4], index=data["D"][:4])
165
+
166
+ merged = target.map(source)
167
+
168
+ for k, v in merged.items():
169
+ assert v == source[target[k]]
170
+
171
+ # input could be a dict
172
+ merged = target.map(source.to_dict())
173
+
174
+ for k, v in merged.items():
175
+ assert v == source[target[k]]
176
+
177
+
178
+ def test_map_datetime(datetime_series):
179
+ # function
180
+ result = datetime_series.map(lambda x: x * 2)
181
+ tm.assert_series_equal(result, datetime_series * 2)
182
+
183
+
184
+ def test_map_category():
185
+ # GH 10324
186
+ a = Series([1, 2, 3, 4])
187
+ b = Series(["even", "odd", "even", "odd"], dtype="category")
188
+ c = Series(["even", "odd", "even", "odd"])
189
+
190
+ exp = Series(["odd", "even", "odd", np.nan], dtype="category")
191
+ tm.assert_series_equal(a.map(b), exp)
192
+ exp = Series(["odd", "even", "odd", np.nan])
193
+ tm.assert_series_equal(a.map(c), exp)
194
+
195
+
196
+ def test_map_category_numeric():
197
+ a = Series(["a", "b", "c", "d"])
198
+ b = Series([1, 2, 3, 4], index=pd.CategoricalIndex(["b", "c", "d", "e"]))
199
+ c = Series([1, 2, 3, 4], index=Index(["b", "c", "d", "e"]))
200
+
201
+ exp = Series([np.nan, 1, 2, 3])
202
+ tm.assert_series_equal(a.map(b), exp)
203
+ exp = Series([np.nan, 1, 2, 3])
204
+ tm.assert_series_equal(a.map(c), exp)
205
+
206
+
207
+ def test_map_category_string():
208
+ a = Series(["a", "b", "c", "d"])
209
+ b = Series(
210
+ ["B", "C", "D", "E"],
211
+ dtype="category",
212
+ index=pd.CategoricalIndex(["b", "c", "d", "e"]),
213
+ )
214
+ c = Series(["B", "C", "D", "E"], index=Index(["b", "c", "d", "e"]))
215
+
216
+ exp = Series(
217
+ pd.Categorical([np.nan, "B", "C", "D"], categories=["B", "C", "D", "E"])
218
+ )
219
+ tm.assert_series_equal(a.map(b), exp)
220
+ exp = Series([np.nan, "B", "C", "D"])
221
+ tm.assert_series_equal(a.map(c), exp)
222
+
223
+
224
+ @pytest.mark.filterwarnings(r"ignore:Dtype inference:FutureWarning")
225
+ def test_map_empty(request, index):
226
+ if isinstance(index, MultiIndex):
227
+ request.applymarker(
228
+ pytest.mark.xfail(
229
+ reason="Initializing a Series from a MultiIndex is not supported"
230
+ )
231
+ )
232
+
233
+ s = Series(index)
234
+ result = s.map({})
235
+
236
+ expected = Series(np.nan, index=s.index)
237
+ tm.assert_series_equal(result, expected)
238
+
239
+
240
+ def test_map_compat():
241
+ # related GH 8024
242
+ s = Series([True, True, False], index=[1, 2, 3])
243
+ result = s.map({True: "foo", False: "bar"})
244
+ expected = Series(["foo", "foo", "bar"], index=[1, 2, 3])
245
+ tm.assert_series_equal(result, expected)
246
+
247
+
248
+ def test_map_int():
249
+ left = Series({"a": 1.0, "b": 2.0, "c": 3.0, "d": 4})
250
+ right = Series({1: 11, 2: 22, 3: 33})
251
+
252
+ assert left.dtype == np.float64
253
+ assert issubclass(right.dtype.type, np.integer)
254
+
255
+ merged = left.map(right)
256
+ assert merged.dtype == np.float64
257
+ assert isna(merged["d"])
258
+ assert not isna(merged["c"])
259
+
260
+
261
+ def test_map_type_inference():
262
+ s = Series(range(3))
263
+ s2 = s.map(lambda x: np.where(x == 0, 0, 1))
264
+ assert issubclass(s2.dtype.type, np.integer)
265
+
266
+
267
+ def test_map_decimal(string_series):
268
+ result = string_series.map(lambda x: Decimal(str(x)))
269
+ assert result.dtype == np.object_
270
+ assert isinstance(result.iloc[0], Decimal)
271
+
272
+
273
+ def test_map_na_exclusion():
274
+ s = Series([1.5, np.nan, 3, np.nan, 5])
275
+
276
+ result = s.map(lambda x: x * 2, na_action="ignore")
277
+ exp = s * 2
278
+ tm.assert_series_equal(result, exp)
279
+
280
+
281
+ def test_map_dict_with_tuple_keys():
282
+ """
283
+ Due to new MultiIndex-ing behaviour in v0.14.0,
284
+ dicts with tuple keys passed to map were being
285
+ converted to a multi-index, preventing tuple values
286
+ from being mapped properly.
287
+ """
288
+ # GH 18496
289
+ df = DataFrame({"a": [(1,), (2,), (3, 4), (5, 6)]})
290
+ label_mappings = {(1,): "A", (2,): "B", (3, 4): "A", (5, 6): "B"}
291
+
292
+ df["labels"] = df["a"].map(label_mappings)
293
+ df["expected_labels"] = Series(["A", "B", "A", "B"], index=df.index)
294
+ # All labels should be filled now
295
+ tm.assert_series_equal(df["labels"], df["expected_labels"], check_names=False)
296
+
297
+
298
+ def test_map_counter():
299
+ s = Series(["a", "b", "c"], index=[1, 2, 3])
300
+ counter = Counter()
301
+ counter["b"] = 5
302
+ counter["c"] += 1
303
+ result = s.map(counter)
304
+ expected = Series([0, 5, 1], index=[1, 2, 3])
305
+ tm.assert_series_equal(result, expected)
306
+
307
+
308
+ def test_map_defaultdict():
309
+ s = Series([1, 2, 3], index=["a", "b", "c"])
310
+ default_dict = defaultdict(lambda: "blank")
311
+ default_dict[1] = "stuff"
312
+ result = s.map(default_dict)
313
+ expected = Series(["stuff", "blank", "blank"], index=["a", "b", "c"])
314
+ tm.assert_series_equal(result, expected)
315
+
316
+
317
+ def test_map_dict_na_key():
318
+ # https://github.com/pandas-dev/pandas/issues/17648
319
+ # Checks that np.nan key is appropriately mapped
320
+ s = Series([1, 2, np.nan])
321
+ expected = Series(["a", "b", "c"])
322
+ result = s.map({1: "a", 2: "b", np.nan: "c"})
323
+ tm.assert_series_equal(result, expected)
324
+
325
+
326
+ @pytest.mark.parametrize("na_action", [None, "ignore"])
327
+ def test_map_defaultdict_na_key(na_action):
328
+ # GH 48813
329
+ s = Series([1, 2, np.nan])
330
+ default_map = defaultdict(lambda: "missing", {1: "a", 2: "b", np.nan: "c"})
331
+ result = s.map(default_map, na_action=na_action)
332
+ expected = Series({0: "a", 1: "b", 2: "c" if na_action is None else np.nan})
333
+ tm.assert_series_equal(result, expected)
334
+
335
+
336
+ @pytest.mark.parametrize("na_action", [None, "ignore"])
337
+ def test_map_defaultdict_missing_key(na_action):
338
+ # GH 48813
339
+ s = Series([1, 2, np.nan])
340
+ default_map = defaultdict(lambda: "missing", {1: "a", 2: "b", 3: "c"})
341
+ result = s.map(default_map, na_action=na_action)
342
+ expected = Series({0: "a", 1: "b", 2: "missing" if na_action is None else np.nan})
343
+ tm.assert_series_equal(result, expected)
344
+
345
+
346
+ @pytest.mark.parametrize("na_action", [None, "ignore"])
347
+ def test_map_defaultdict_unmutated(na_action):
348
+ # GH 48813
349
+ s = Series([1, 2, np.nan])
350
+ default_map = defaultdict(lambda: "missing", {1: "a", 2: "b", np.nan: "c"})
351
+ expected_default_map = default_map.copy()
352
+ s.map(default_map, na_action=na_action)
353
+ assert default_map == expected_default_map
354
+
355
+
356
+ @pytest.mark.parametrize("arg_func", [dict, Series])
357
+ def test_map_dict_ignore_na(arg_func):
358
+ # GH#47527
359
+ mapping = arg_func({1: 10, np.nan: 42})
360
+ ser = Series([1, np.nan, 2])
361
+ result = ser.map(mapping, na_action="ignore")
362
+ expected = Series([10, np.nan, np.nan])
363
+ tm.assert_series_equal(result, expected)
364
+
365
+
366
+ def test_map_defaultdict_ignore_na():
367
+ # GH#47527
368
+ mapping = defaultdict(int, {1: 10, np.nan: 42})
369
+ ser = Series([1, np.nan, 2])
370
+ result = ser.map(mapping)
371
+ expected = Series([10, 42, 0])
372
+ tm.assert_series_equal(result, expected)
373
+
374
+
375
+ @pytest.mark.parametrize(
376
+ "na_action, expected",
377
+ [(None, Series([10.0, 42.0, np.nan])), ("ignore", Series([10, np.nan, np.nan]))],
378
+ )
379
+ def test_map_categorical_na_ignore(na_action, expected):
380
+ # GH#47527
381
+ values = pd.Categorical([1, np.nan, 2], categories=[10, 1, 2])
382
+ ser = Series(values)
383
+ result = ser.map({1: 10, np.nan: 42}, na_action=na_action)
384
+ tm.assert_series_equal(result, expected)
385
+
386
+
387
+ def test_map_dict_subclass_with_missing():
388
+ """
389
+ Test Series.map with a dictionary subclass that defines __missing__,
390
+ i.e. sets a default value (GH #15999).
391
+ """
392
+
393
+ class DictWithMissing(dict):
394
+ def __missing__(self, key):
395
+ return "missing"
396
+
397
+ s = Series([1, 2, 3])
398
+ dictionary = DictWithMissing({3: "three"})
399
+ result = s.map(dictionary)
400
+ expected = Series(["missing", "missing", "three"])
401
+ tm.assert_series_equal(result, expected)
402
+
403
+
404
+ def test_map_dict_subclass_without_missing():
405
+ class DictWithoutMissing(dict):
406
+ pass
407
+
408
+ s = Series([1, 2, 3])
409
+ dictionary = DictWithoutMissing({3: "three"})
410
+ result = s.map(dictionary)
411
+ expected = Series([np.nan, np.nan, "three"])
412
+ tm.assert_series_equal(result, expected)
413
+
414
+
415
+ def test_map_abc_mapping(non_dict_mapping_subclass):
416
+ # https://github.com/pandas-dev/pandas/issues/29733
417
+ # Check collections.abc.Mapping support as mapper for Series.map
418
+ s = Series([1, 2, 3])
419
+ not_a_dictionary = non_dict_mapping_subclass({3: "three"})
420
+ result = s.map(not_a_dictionary)
421
+ expected = Series([np.nan, np.nan, "three"])
422
+ tm.assert_series_equal(result, expected)
423
+
424
+
425
+ def test_map_abc_mapping_with_missing(non_dict_mapping_subclass):
426
+ # https://github.com/pandas-dev/pandas/issues/29733
427
+ # Check collections.abc.Mapping support as mapper for Series.map
428
+ class NonDictMappingWithMissing(non_dict_mapping_subclass):
429
+ def __missing__(self, key):
430
+ return "missing"
431
+
432
+ s = Series([1, 2, 3])
433
+ not_a_dictionary = NonDictMappingWithMissing({3: "three"})
434
+ result = s.map(not_a_dictionary)
435
+ # __missing__ is a dict concept, not a Mapping concept,
436
+ # so it should not change the result!
437
+ expected = Series([np.nan, np.nan, "three"])
438
+ tm.assert_series_equal(result, expected)
439
+
440
+
441
+ def test_map_box_dt64(unit):
442
+ vals = [pd.Timestamp("2011-01-01"), pd.Timestamp("2011-01-02")]
443
+ ser = Series(vals).dt.as_unit(unit)
444
+ assert ser.dtype == f"datetime64[{unit}]"
445
+ # boxed value must be Timestamp instance
446
+ res = ser.map(lambda x: f"{type(x).__name__}_{x.day}_{x.tz}")
447
+ exp = Series(["Timestamp_1_None", "Timestamp_2_None"])
448
+ tm.assert_series_equal(res, exp)
449
+
450
+
451
+ def test_map_box_dt64tz(unit):
452
+ vals = [
453
+ pd.Timestamp("2011-01-01", tz="US/Eastern"),
454
+ pd.Timestamp("2011-01-02", tz="US/Eastern"),
455
+ ]
456
+ ser = Series(vals).dt.as_unit(unit)
457
+ assert ser.dtype == f"datetime64[{unit}, US/Eastern]"
458
+ res = ser.map(lambda x: f"{type(x).__name__}_{x.day}_{x.tz}")
459
+ exp = Series(["Timestamp_1_US/Eastern", "Timestamp_2_US/Eastern"])
460
+ tm.assert_series_equal(res, exp)
461
+
462
+
463
+ def test_map_box_td64(unit):
464
+ # timedelta
465
+ vals = [pd.Timedelta("1 days"), pd.Timedelta("2 days")]
466
+ ser = Series(vals).dt.as_unit(unit)
467
+ assert ser.dtype == f"timedelta64[{unit}]"
468
+ res = ser.map(lambda x: f"{type(x).__name__}_{x.days}")
469
+ exp = Series(["Timedelta_1", "Timedelta_2"])
470
+ tm.assert_series_equal(res, exp)
471
+
472
+
473
+ def test_map_box_period():
474
+ # period
475
+ vals = [pd.Period("2011-01-01", freq="M"), pd.Period("2011-01-02", freq="M")]
476
+ ser = Series(vals)
477
+ assert ser.dtype == "Period[M]"
478
+ res = ser.map(lambda x: f"{type(x).__name__}_{x.freqstr}")
479
+ exp = Series(["Period_M", "Period_M"])
480
+ tm.assert_series_equal(res, exp)
481
+
482
+
483
+ @pytest.mark.parametrize("na_action", [None, "ignore"])
484
+ def test_map_categorical(na_action, using_infer_string):
485
+ values = pd.Categorical(list("ABBABCD"), categories=list("DCBA"), ordered=True)
486
+ s = Series(values, name="XX", index=list("abcdefg"))
487
+
488
+ result = s.map(lambda x: x.lower(), na_action=na_action)
489
+ exp_values = pd.Categorical(list("abbabcd"), categories=list("dcba"), ordered=True)
490
+ exp = Series(exp_values, name="XX", index=list("abcdefg"))
491
+ tm.assert_series_equal(result, exp)
492
+ tm.assert_categorical_equal(result.values, exp_values)
493
+
494
+ result = s.map(lambda x: "A", na_action=na_action)
495
+ exp = Series(["A"] * 7, name="XX", index=list("abcdefg"))
496
+ tm.assert_series_equal(result, exp)
497
+ assert result.dtype == object if not using_infer_string else "str"
498
+
499
+
500
+ @pytest.mark.parametrize(
501
+ "na_action, expected",
502
+ (
503
+ [None, Series(["A", "B", "nan"], name="XX")],
504
+ [
505
+ "ignore",
506
+ Series(
507
+ ["A", "B", np.nan],
508
+ name="XX",
509
+ dtype=pd.CategoricalDtype(list("DCBA"), True),
510
+ ),
511
+ ],
512
+ ),
513
+ )
514
+ def test_map_categorical_na_action(na_action, expected):
515
+ dtype = pd.CategoricalDtype(list("DCBA"), ordered=True)
516
+ values = pd.Categorical(list("AB") + [np.nan], dtype=dtype)
517
+ s = Series(values, name="XX")
518
+ result = s.map(str, na_action=na_action)
519
+ tm.assert_series_equal(result, expected)
520
+
521
+
522
+ def test_map_datetimetz():
523
+ values = date_range("2011-01-01", "2011-01-02", freq="h").tz_localize("Asia/Tokyo")
524
+ s = Series(values, name="XX")
525
+
526
+ # keep tz
527
+ result = s.map(lambda x: x + pd.offsets.Day())
528
+ exp_values = date_range("2011-01-02", "2011-01-03", freq="h").tz_localize(
529
+ "Asia/Tokyo"
530
+ )
531
+ exp = Series(exp_values, name="XX")
532
+ tm.assert_series_equal(result, exp)
533
+
534
+ result = s.map(lambda x: x.hour)
535
+ exp = Series(list(range(24)) + [0], name="XX", dtype=np.int64)
536
+ tm.assert_series_equal(result, exp)
537
+
538
+ # not vectorized
539
+ def f(x):
540
+ if not isinstance(x, pd.Timestamp):
541
+ raise ValueError
542
+ return str(x.tz)
543
+
544
+ result = s.map(f)
545
+ exp = Series(["Asia/Tokyo"] * 25, name="XX")
546
+ tm.assert_series_equal(result, exp)
547
+
548
+
549
+ @pytest.mark.parametrize(
550
+ "vals,mapping,exp",
551
+ [
552
+ (list("abc"), {np.nan: "not NaN"}, [np.nan] * 3 + ["not NaN"]),
553
+ (list("abc"), {"a": "a letter"}, ["a letter"] + [np.nan] * 3),
554
+ (list(range(3)), {0: 42}, [42] + [np.nan] * 3),
555
+ ],
556
+ )
557
+ def test_map_missing_mixed(vals, mapping, exp):
558
+ # GH20495
559
+ s = Series(vals + [np.nan])
560
+ result = s.map(mapping)
561
+ exp = Series(exp)
562
+ tm.assert_series_equal(result, exp)
563
+
564
+
565
+ def test_map_scalar_on_date_time_index_aware_series():
566
+ # GH 25959
567
+ # Calling map on a localized time series should not cause an error
568
+ series = Series(
569
+ np.arange(10, dtype=np.float64),
570
+ index=date_range("2020-01-01", periods=10, tz="UTC"),
571
+ name="ts",
572
+ )
573
+ result = Series(series.index).map(lambda x: 1)
574
+ tm.assert_series_equal(result, Series(np.ones(len(series)), dtype="int64"))
575
+
576
+
577
+ def test_map_float_to_string_precision():
578
+ # GH 13228
579
+ ser = Series(1 / 3)
580
+ result = ser.map(lambda val: str(val)).to_dict()
581
+ expected = {0: "0.3333333333333333"}
582
+ assert result == expected
583
+
584
+
585
+ def test_map_to_timedelta():
586
+ list_of_valid_strings = ["00:00:01", "00:00:02"]
587
+ a = pd.to_timedelta(list_of_valid_strings)
588
+ b = Series(list_of_valid_strings).map(pd.to_timedelta)
589
+ tm.assert_series_equal(Series(a), b)
590
+
591
+ list_of_strings = ["00:00:01", np.nan, pd.NaT, pd.NaT]
592
+
593
+ a = pd.to_timedelta(list_of_strings)
594
+ ser = Series(list_of_strings)
595
+ b = ser.map(pd.to_timedelta)
596
+ tm.assert_series_equal(Series(a), b)
597
+
598
+
599
+ def test_map_type():
600
+ # GH 46719
601
+ s = Series([3, "string", float], index=["a", "b", "c"])
602
+ result = s.map(type)
603
+ expected = Series([int, str, type], index=["a", "b", "c"])
604
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_matmul.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import operator
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ from pandas import (
7
+ DataFrame,
8
+ Series,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestMatmul:
14
+ def test_matmul(self):
15
+ # matmul test is for GH#10259
16
+ a = Series(
17
+ np.random.default_rng(2).standard_normal(4), index=["p", "q", "r", "s"]
18
+ )
19
+ b = DataFrame(
20
+ np.random.default_rng(2).standard_normal((3, 4)),
21
+ index=["1", "2", "3"],
22
+ columns=["p", "q", "r", "s"],
23
+ ).T
24
+
25
+ # Series @ DataFrame -> Series
26
+ result = operator.matmul(a, b)
27
+ expected = Series(np.dot(a.values, b.values), index=["1", "2", "3"])
28
+ tm.assert_series_equal(result, expected)
29
+
30
+ # DataFrame @ Series -> Series
31
+ result = operator.matmul(b.T, a)
32
+ expected = Series(np.dot(b.T.values, a.T.values), index=["1", "2", "3"])
33
+ tm.assert_series_equal(result, expected)
34
+
35
+ # Series @ Series -> scalar
36
+ result = operator.matmul(a, a)
37
+ expected = np.dot(a.values, a.values)
38
+ tm.assert_almost_equal(result, expected)
39
+
40
+ # GH#21530
41
+ # vector (1D np.array) @ Series (__rmatmul__)
42
+ result = operator.matmul(a.values, a)
43
+ expected = np.dot(a.values, a.values)
44
+ tm.assert_almost_equal(result, expected)
45
+
46
+ # GH#21530
47
+ # vector (1D list) @ Series (__rmatmul__)
48
+ result = operator.matmul(a.values.tolist(), a)
49
+ expected = np.dot(a.values, a.values)
50
+ tm.assert_almost_equal(result, expected)
51
+
52
+ # GH#21530
53
+ # matrix (2D np.array) @ Series (__rmatmul__)
54
+ result = operator.matmul(b.T.values, a)
55
+ expected = np.dot(b.T.values, a.values)
56
+ tm.assert_almost_equal(result, expected)
57
+
58
+ # GH#21530
59
+ # matrix (2D nested lists) @ Series (__rmatmul__)
60
+ result = operator.matmul(b.T.values.tolist(), a)
61
+ expected = np.dot(b.T.values, a.values)
62
+ tm.assert_almost_equal(result, expected)
63
+
64
+ # mixed dtype DataFrame @ Series
65
+ a["p"] = int(a.p)
66
+ result = operator.matmul(b.T, a)
67
+ expected = Series(np.dot(b.T.values, a.T.values), index=["1", "2", "3"])
68
+ tm.assert_series_equal(result, expected)
69
+
70
+ # different dtypes DataFrame @ Series
71
+ a = a.astype(int)
72
+ result = operator.matmul(b.T, a)
73
+ expected = Series(np.dot(b.T.values, a.T.values), index=["1", "2", "3"])
74
+ tm.assert_series_equal(result, expected)
75
+
76
+ msg = r"Dot product shape mismatch, \(4,\) vs \(3,\)"
77
+ # exception raised is of type Exception
78
+ with pytest.raises(Exception, match=msg):
79
+ a.dot(a.values[:3])
80
+ msg = "matrices are not aligned"
81
+ with pytest.raises(ValueError, match=msg):
82
+ a.dot(b.T)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_nlargest.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Note: for naming purposes, most tests are title with as e.g. "test_nlargest_foo"
3
+ but are implicitly also testing nsmallest_foo.
4
+ """
5
+ from itertools import product
6
+
7
+ import numpy as np
8
+ import pytest
9
+
10
+ import pandas as pd
11
+ from pandas import Series
12
+ import pandas._testing as tm
13
+
14
+ main_dtypes = [
15
+ "datetime",
16
+ "datetimetz",
17
+ "timedelta",
18
+ "int8",
19
+ "int16",
20
+ "int32",
21
+ "int64",
22
+ "float32",
23
+ "float64",
24
+ "uint8",
25
+ "uint16",
26
+ "uint32",
27
+ "uint64",
28
+ ]
29
+
30
+
31
+ @pytest.fixture
32
+ def s_main_dtypes():
33
+ """
34
+ A DataFrame with many dtypes
35
+
36
+ * datetime
37
+ * datetimetz
38
+ * timedelta
39
+ * [u]int{8,16,32,64}
40
+ * float{32,64}
41
+
42
+ The columns are the name of the dtype.
43
+ """
44
+ df = pd.DataFrame(
45
+ {
46
+ "datetime": pd.to_datetime(["2003", "2002", "2001", "2002", "2005"]),
47
+ "datetimetz": pd.to_datetime(
48
+ ["2003", "2002", "2001", "2002", "2005"]
49
+ ).tz_localize("US/Eastern"),
50
+ "timedelta": pd.to_timedelta(["3d", "2d", "1d", "2d", "5d"]),
51
+ }
52
+ )
53
+
54
+ for dtype in [
55
+ "int8",
56
+ "int16",
57
+ "int32",
58
+ "int64",
59
+ "float32",
60
+ "float64",
61
+ "uint8",
62
+ "uint16",
63
+ "uint32",
64
+ "uint64",
65
+ ]:
66
+ df[dtype] = Series([3, 2, 1, 2, 5], dtype=dtype)
67
+
68
+ return df
69
+
70
+
71
+ @pytest.fixture(params=main_dtypes)
72
+ def s_main_dtypes_split(request, s_main_dtypes):
73
+ """Each series in s_main_dtypes."""
74
+ return s_main_dtypes[request.param]
75
+
76
+
77
+ def assert_check_nselect_boundary(vals, dtype, method):
78
+ # helper function for 'test_boundary_{dtype}' tests
79
+ ser = Series(vals, dtype=dtype)
80
+ result = getattr(ser, method)(3)
81
+ expected_idxr = [0, 1, 2] if method == "nsmallest" else [3, 2, 1]
82
+ expected = ser.loc[expected_idxr]
83
+ tm.assert_series_equal(result, expected)
84
+
85
+
86
+ class TestSeriesNLargestNSmallest:
87
+ @pytest.mark.parametrize(
88
+ "r",
89
+ [
90
+ Series([3.0, 2, 1, 2, "5"], dtype="object"),
91
+ Series([3.0, 2, 1, 2, 5], dtype="object"),
92
+ # not supported on some archs
93
+ # Series([3., 2, 1, 2, 5], dtype='complex256'),
94
+ Series([3.0, 2, 1, 2, 5], dtype="complex128"),
95
+ Series(list("abcde")),
96
+ Series(list("abcde"), dtype="category"),
97
+ ],
98
+ )
99
+ def test_nlargest_error(self, r):
100
+ dt = r.dtype
101
+ msg = f"Cannot use method 'n(largest|smallest)' with dtype {dt}"
102
+ args = 2, len(r), 0, -1
103
+ methods = r.nlargest, r.nsmallest
104
+ for method, arg in product(methods, args):
105
+ with pytest.raises(TypeError, match=msg):
106
+ method(arg)
107
+
108
+ def test_nsmallest_nlargest(self, s_main_dtypes_split):
109
+ # float, int, datetime64 (use i8), timedelts64 (same),
110
+ # object that are numbers, object that are strings
111
+ ser = s_main_dtypes_split
112
+
113
+ tm.assert_series_equal(ser.nsmallest(2), ser.iloc[[2, 1]])
114
+ tm.assert_series_equal(ser.nsmallest(2, keep="last"), ser.iloc[[2, 3]])
115
+
116
+ empty = ser.iloc[0:0]
117
+ tm.assert_series_equal(ser.nsmallest(0), empty)
118
+ tm.assert_series_equal(ser.nsmallest(-1), empty)
119
+ tm.assert_series_equal(ser.nlargest(0), empty)
120
+ tm.assert_series_equal(ser.nlargest(-1), empty)
121
+
122
+ tm.assert_series_equal(ser.nsmallest(len(ser)), ser.sort_values())
123
+ tm.assert_series_equal(ser.nsmallest(len(ser) + 1), ser.sort_values())
124
+ tm.assert_series_equal(ser.nlargest(len(ser)), ser.iloc[[4, 0, 1, 3, 2]])
125
+ tm.assert_series_equal(ser.nlargest(len(ser) + 1), ser.iloc[[4, 0, 1, 3, 2]])
126
+
127
+ def test_nlargest_misc(self):
128
+ ser = Series([3.0, np.nan, 1, 2, 5])
129
+ result = ser.nlargest()
130
+ expected = ser.iloc[[4, 0, 3, 2, 1]]
131
+ tm.assert_series_equal(result, expected)
132
+ result = ser.nsmallest()
133
+ expected = ser.iloc[[2, 3, 0, 4, 1]]
134
+ tm.assert_series_equal(result, expected)
135
+
136
+ msg = 'keep must be either "first", "last"'
137
+ with pytest.raises(ValueError, match=msg):
138
+ ser.nsmallest(keep="invalid")
139
+ with pytest.raises(ValueError, match=msg):
140
+ ser.nlargest(keep="invalid")
141
+
142
+ # GH#15297
143
+ ser = Series([1] * 5, index=[1, 2, 3, 4, 5])
144
+ expected_first = Series([1] * 3, index=[1, 2, 3])
145
+ expected_last = Series([1] * 3, index=[5, 4, 3])
146
+
147
+ result = ser.nsmallest(3)
148
+ tm.assert_series_equal(result, expected_first)
149
+
150
+ result = ser.nsmallest(3, keep="last")
151
+ tm.assert_series_equal(result, expected_last)
152
+
153
+ result = ser.nlargest(3)
154
+ tm.assert_series_equal(result, expected_first)
155
+
156
+ result = ser.nlargest(3, keep="last")
157
+ tm.assert_series_equal(result, expected_last)
158
+
159
+ @pytest.mark.parametrize("n", range(1, 5))
160
+ def test_nlargest_n(self, n):
161
+ # GH 13412
162
+ ser = Series([1, 4, 3, 2], index=[0, 0, 1, 1])
163
+ result = ser.nlargest(n)
164
+ expected = ser.sort_values(ascending=False).head(n)
165
+ tm.assert_series_equal(result, expected)
166
+
167
+ result = ser.nsmallest(n)
168
+ expected = ser.sort_values().head(n)
169
+ tm.assert_series_equal(result, expected)
170
+
171
+ def test_nlargest_boundary_integer(self, nselect_method, any_int_numpy_dtype):
172
+ # GH#21426
173
+ dtype_info = np.iinfo(any_int_numpy_dtype)
174
+ min_val, max_val = dtype_info.min, dtype_info.max
175
+ vals = [min_val, min_val + 1, max_val - 1, max_val]
176
+ assert_check_nselect_boundary(vals, any_int_numpy_dtype, nselect_method)
177
+
178
+ def test_nlargest_boundary_float(self, nselect_method, float_numpy_dtype):
179
+ # GH#21426
180
+ dtype_info = np.finfo(float_numpy_dtype)
181
+ min_val, max_val = dtype_info.min, dtype_info.max
182
+ min_2nd, max_2nd = np.nextafter([min_val, max_val], 0, dtype=float_numpy_dtype)
183
+ vals = [min_val, min_2nd, max_2nd, max_val]
184
+ assert_check_nselect_boundary(vals, float_numpy_dtype, nselect_method)
185
+
186
+ @pytest.mark.parametrize("dtype", ["datetime64[ns]", "timedelta64[ns]"])
187
+ def test_nlargest_boundary_datetimelike(self, nselect_method, dtype):
188
+ # GH#21426
189
+ # use int64 bounds and +1 to min_val since true minimum is NaT
190
+ # (include min_val/NaT at end to maintain same expected_idxr)
191
+ dtype_info = np.iinfo("int64")
192
+ min_val, max_val = dtype_info.min, dtype_info.max
193
+ vals = [min_val + 1, min_val + 2, max_val - 1, max_val, min_val]
194
+ assert_check_nselect_boundary(vals, dtype, nselect_method)
195
+
196
+ def test_nlargest_duplicate_keep_all_ties(self):
197
+ # see GH#16818
198
+ ser = Series([10, 9, 8, 7, 7, 7, 7, 6])
199
+ result = ser.nlargest(4, keep="all")
200
+ expected = Series([10, 9, 8, 7, 7, 7, 7])
201
+ tm.assert_series_equal(result, expected)
202
+
203
+ result = ser.nsmallest(2, keep="all")
204
+ expected = Series([6, 7, 7, 7, 7], index=[7, 3, 4, 5, 6])
205
+ tm.assert_series_equal(result, expected)
206
+
207
+ @pytest.mark.parametrize(
208
+ "data,expected", [([True, False], [True]), ([True, False, True, True], [True])]
209
+ )
210
+ def test_nlargest_boolean(self, data, expected):
211
+ # GH#26154 : ensure True > False
212
+ ser = Series(data)
213
+ result = ser.nlargest(1)
214
+ expected = Series(expected)
215
+ tm.assert_series_equal(result, expected)
216
+
217
+ def test_nlargest_nullable(self, any_numeric_ea_dtype):
218
+ # GH#42816
219
+ dtype = any_numeric_ea_dtype
220
+ if dtype.startswith("UInt"):
221
+ # Can't cast from negative float to uint on some platforms
222
+ arr = np.random.default_rng(2).integers(1, 10, 10)
223
+ else:
224
+ arr = np.random.default_rng(2).standard_normal(10)
225
+ arr = arr.astype(dtype.lower(), copy=False)
226
+
227
+ ser = Series(arr.copy(), dtype=dtype)
228
+ ser[1] = pd.NA
229
+ result = ser.nlargest(5)
230
+
231
+ expected = (
232
+ Series(np.delete(arr, 1), index=ser.index.delete(1))
233
+ .nlargest(5)
234
+ .astype(dtype)
235
+ )
236
+ tm.assert_series_equal(result, expected)
237
+
238
+ def test_nsmallest_nan_when_keep_is_all(self):
239
+ # GH#46589
240
+ s = Series([1, 2, 3, 3, 3, None])
241
+ result = s.nsmallest(3, keep="all")
242
+ expected = Series([1.0, 2.0, 3.0, 3.0, 3.0])
243
+ tm.assert_series_equal(result, expected)
244
+
245
+ s = Series([1, 2, None, None, None])
246
+ result = s.nsmallest(3, keep="all")
247
+ expected = Series([1, 2, None, None, None])
248
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_nunique.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from pandas import (
4
+ Categorical,
5
+ Series,
6
+ )
7
+
8
+
9
+ def test_nunique():
10
+ # basics.rst doc example
11
+ series = Series(np.random.default_rng(2).standard_normal(500))
12
+ series[20:500] = np.nan
13
+ series[10:20] = 5000
14
+ result = series.nunique()
15
+ assert result == 11
16
+
17
+
18
+ def test_nunique_categorical():
19
+ # GH#18051
20
+ ser = Series(Categorical([]))
21
+ assert ser.nunique() == 0
22
+
23
+ ser = Series(Categorical([np.nan]))
24
+ assert ser.nunique() == 0
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_pct_change.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Series,
6
+ date_range,
7
+ )
8
+ import pandas._testing as tm
9
+
10
+
11
+ class TestSeriesPctChange:
12
+ def test_pct_change(self, datetime_series):
13
+ msg = (
14
+ "The 'fill_method' keyword being not None and the 'limit' keyword in "
15
+ "Series.pct_change are deprecated"
16
+ )
17
+
18
+ rs = datetime_series.pct_change(fill_method=None)
19
+ tm.assert_series_equal(rs, datetime_series / datetime_series.shift(1) - 1)
20
+
21
+ rs = datetime_series.pct_change(2)
22
+ filled = datetime_series.ffill()
23
+ tm.assert_series_equal(rs, filled / filled.shift(2) - 1)
24
+
25
+ with tm.assert_produces_warning(FutureWarning, match=msg):
26
+ rs = datetime_series.pct_change(fill_method="bfill", limit=1)
27
+ filled = datetime_series.bfill(limit=1)
28
+ tm.assert_series_equal(rs, filled / filled.shift(1) - 1)
29
+
30
+ rs = datetime_series.pct_change(freq="5D")
31
+ filled = datetime_series.ffill()
32
+ tm.assert_series_equal(
33
+ rs, (filled / filled.shift(freq="5D") - 1).reindex_like(filled)
34
+ )
35
+
36
+ def test_pct_change_with_duplicate_axis(self):
37
+ # GH#28664
38
+ common_idx = date_range("2019-11-14", periods=5, freq="D")
39
+ result = Series(range(5), common_idx).pct_change(freq="B")
40
+
41
+ # the reason that the expected should be like this is documented at PR 28681
42
+ expected = Series([np.nan, np.inf, np.nan, np.nan, 3.0], common_idx)
43
+
44
+ tm.assert_series_equal(result, expected)
45
+
46
+ def test_pct_change_shift_over_nas(self):
47
+ s = Series([1.0, 1.5, np.nan, 2.5, 3.0])
48
+
49
+ msg = "The default fill_method='pad' in Series.pct_change is deprecated"
50
+ with tm.assert_produces_warning(FutureWarning, match=msg):
51
+ chg = s.pct_change()
52
+
53
+ expected = Series([np.nan, 0.5, 0.0, 2.5 / 1.5 - 1, 0.2])
54
+ tm.assert_series_equal(chg, expected)
55
+
56
+ @pytest.mark.parametrize(
57
+ "freq, periods, fill_method, limit",
58
+ [
59
+ ("5B", 5, None, None),
60
+ ("3B", 3, None, None),
61
+ ("3B", 3, "bfill", None),
62
+ ("7B", 7, "pad", 1),
63
+ ("7B", 7, "bfill", 3),
64
+ ("14B", 14, None, None),
65
+ ],
66
+ )
67
+ def test_pct_change_periods_freq(
68
+ self, freq, periods, fill_method, limit, datetime_series
69
+ ):
70
+ msg = (
71
+ "The 'fill_method' keyword being not None and the 'limit' keyword in "
72
+ "Series.pct_change are deprecated"
73
+ )
74
+
75
+ # GH#7292
76
+ with tm.assert_produces_warning(FutureWarning, match=msg):
77
+ rs_freq = datetime_series.pct_change(
78
+ freq=freq, fill_method=fill_method, limit=limit
79
+ )
80
+ with tm.assert_produces_warning(FutureWarning, match=msg):
81
+ rs_periods = datetime_series.pct_change(
82
+ periods, fill_method=fill_method, limit=limit
83
+ )
84
+ tm.assert_series_equal(rs_freq, rs_periods)
85
+
86
+ empty_ts = Series(index=datetime_series.index, dtype=object)
87
+ with tm.assert_produces_warning(FutureWarning, match=msg):
88
+ rs_freq = empty_ts.pct_change(
89
+ freq=freq, fill_method=fill_method, limit=limit
90
+ )
91
+ with tm.assert_produces_warning(FutureWarning, match=msg):
92
+ rs_periods = empty_ts.pct_change(
93
+ periods, fill_method=fill_method, limit=limit
94
+ )
95
+ tm.assert_series_equal(rs_freq, rs_periods)
96
+
97
+
98
+ @pytest.mark.parametrize("fill_method", ["pad", "ffill", None])
99
+ def test_pct_change_with_duplicated_indices(fill_method):
100
+ # GH30463
101
+ s = Series([np.nan, 1, 2, 3, 9, 18], index=["a", "b"] * 3)
102
+
103
+ warn = None if fill_method is None else FutureWarning
104
+ msg = (
105
+ "The 'fill_method' keyword being not None and the 'limit' keyword in "
106
+ "Series.pct_change are deprecated"
107
+ )
108
+ with tm.assert_produces_warning(warn, match=msg):
109
+ result = s.pct_change(fill_method=fill_method)
110
+
111
+ expected = Series([np.nan, np.nan, 1.0, 0.5, 2.0, 1.0], index=["a", "b"] * 3)
112
+ tm.assert_series_equal(result, expected)
113
+
114
+
115
+ def test_pct_change_no_warning_na_beginning():
116
+ # GH#54981
117
+ ser = Series([None, None, 1, 2, 3])
118
+ result = ser.pct_change()
119
+ expected = Series([np.nan, np.nan, np.nan, 1, 0.5])
120
+ tm.assert_series_equal(result, expected)
121
+
122
+
123
+ def test_pct_change_empty():
124
+ # GH 57056
125
+ ser = Series([], dtype="float64")
126
+ expected = ser.copy()
127
+ result = ser.pct_change(periods=0)
128
+ tm.assert_series_equal(expected, result)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_pop.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pandas import Series
2
+ import pandas._testing as tm
3
+
4
+
5
+ def test_pop():
6
+ # GH#6600
7
+ ser = Series([0, 4, 0], index=["A", "B", "C"], name=4)
8
+
9
+ result = ser.pop("B")
10
+ assert result == 4
11
+
12
+ expected = Series([0, 0], index=["A", "C"], name=4)
13
+ tm.assert_series_equal(ser, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_quantile.py ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas.core.dtypes.common import is_integer
5
+
6
+ import pandas as pd
7
+ from pandas import (
8
+ Index,
9
+ Series,
10
+ )
11
+ import pandas._testing as tm
12
+ from pandas.core.indexes.datetimes import Timestamp
13
+
14
+
15
+ class TestSeriesQuantile:
16
+ def test_quantile(self, datetime_series):
17
+ q = datetime_series.quantile(0.1)
18
+ assert q == np.percentile(datetime_series.dropna(), 10)
19
+
20
+ q = datetime_series.quantile(0.9)
21
+ assert q == np.percentile(datetime_series.dropna(), 90)
22
+
23
+ # object dtype
24
+ q = Series(datetime_series, dtype=object).quantile(0.9)
25
+ assert q == np.percentile(datetime_series.dropna(), 90)
26
+
27
+ # datetime64[ns] dtype
28
+ dts = datetime_series.index.to_series()
29
+ q = dts.quantile(0.2)
30
+ assert q == Timestamp("2000-01-10 19:12:00")
31
+
32
+ # timedelta64[ns] dtype
33
+ tds = dts.diff()
34
+ q = tds.quantile(0.25)
35
+ assert q == pd.to_timedelta("24:00:00")
36
+
37
+ # GH7661
38
+ result = Series([np.timedelta64("NaT")]).sum()
39
+ assert result == pd.Timedelta(0)
40
+
41
+ msg = "percentiles should all be in the interval \\[0, 1\\]"
42
+ for invalid in [-1, 2, [0.5, -1], [0.5, 2]]:
43
+ with pytest.raises(ValueError, match=msg):
44
+ datetime_series.quantile(invalid)
45
+
46
+ s = Series(np.random.default_rng(2).standard_normal(100))
47
+ percentile_array = [-0.5, 0.25, 1.5]
48
+ with pytest.raises(ValueError, match=msg):
49
+ s.quantile(percentile_array)
50
+
51
+ def test_quantile_multi(self, datetime_series, unit):
52
+ datetime_series.index = datetime_series.index.as_unit(unit)
53
+ qs = [0.1, 0.9]
54
+ result = datetime_series.quantile(qs)
55
+ expected = Series(
56
+ [
57
+ np.percentile(datetime_series.dropna(), 10),
58
+ np.percentile(datetime_series.dropna(), 90),
59
+ ],
60
+ index=qs,
61
+ name=datetime_series.name,
62
+ )
63
+ tm.assert_series_equal(result, expected)
64
+
65
+ dts = datetime_series.index.to_series()
66
+ dts.name = "xxx"
67
+ result = dts.quantile((0.2, 0.2))
68
+ expected = Series(
69
+ [Timestamp("2000-01-10 19:12:00"), Timestamp("2000-01-10 19:12:00")],
70
+ index=[0.2, 0.2],
71
+ name="xxx",
72
+ dtype=f"M8[{unit}]",
73
+ )
74
+ tm.assert_series_equal(result, expected)
75
+
76
+ result = datetime_series.quantile([])
77
+ expected = Series(
78
+ [], name=datetime_series.name, index=Index([], dtype=float), dtype="float64"
79
+ )
80
+ tm.assert_series_equal(result, expected)
81
+
82
+ def test_quantile_interpolation(self, datetime_series):
83
+ # see gh-10174
84
+
85
+ # interpolation = linear (default case)
86
+ q = datetime_series.quantile(0.1, interpolation="linear")
87
+ assert q == np.percentile(datetime_series.dropna(), 10)
88
+ q1 = datetime_series.quantile(0.1)
89
+ assert q1 == np.percentile(datetime_series.dropna(), 10)
90
+
91
+ # test with and without interpolation keyword
92
+ assert q == q1
93
+
94
+ def test_quantile_interpolation_dtype(self):
95
+ # GH #10174
96
+
97
+ # interpolation = linear (default case)
98
+ q = Series([1, 3, 4]).quantile(0.5, interpolation="lower")
99
+ assert q == np.percentile(np.array([1, 3, 4]), 50)
100
+ assert is_integer(q)
101
+
102
+ q = Series([1, 3, 4]).quantile(0.5, interpolation="higher")
103
+ assert q == np.percentile(np.array([1, 3, 4]), 50)
104
+ assert is_integer(q)
105
+
106
+ def test_quantile_nan(self):
107
+ # GH 13098
108
+ ser = Series([1, 2, 3, 4, np.nan])
109
+ result = ser.quantile(0.5)
110
+ expected = 2.5
111
+ assert result == expected
112
+
113
+ # all nan/empty
114
+ s1 = Series([], dtype=object)
115
+ cases = [s1, Series([np.nan, np.nan])]
116
+
117
+ for ser in cases:
118
+ res = ser.quantile(0.5)
119
+ assert np.isnan(res)
120
+
121
+ res = ser.quantile([0.5])
122
+ tm.assert_series_equal(res, Series([np.nan], index=[0.5]))
123
+
124
+ res = ser.quantile([0.2, 0.3])
125
+ tm.assert_series_equal(res, Series([np.nan, np.nan], index=[0.2, 0.3]))
126
+
127
+ @pytest.mark.parametrize(
128
+ "case",
129
+ [
130
+ [
131
+ Timestamp("2011-01-01"),
132
+ Timestamp("2011-01-02"),
133
+ Timestamp("2011-01-03"),
134
+ ],
135
+ [
136
+ Timestamp("2011-01-01", tz="US/Eastern"),
137
+ Timestamp("2011-01-02", tz="US/Eastern"),
138
+ Timestamp("2011-01-03", tz="US/Eastern"),
139
+ ],
140
+ [pd.Timedelta("1 days"), pd.Timedelta("2 days"), pd.Timedelta("3 days")],
141
+ # NaT
142
+ [
143
+ Timestamp("2011-01-01"),
144
+ Timestamp("2011-01-02"),
145
+ Timestamp("2011-01-03"),
146
+ pd.NaT,
147
+ ],
148
+ [
149
+ Timestamp("2011-01-01", tz="US/Eastern"),
150
+ Timestamp("2011-01-02", tz="US/Eastern"),
151
+ Timestamp("2011-01-03", tz="US/Eastern"),
152
+ pd.NaT,
153
+ ],
154
+ [
155
+ pd.Timedelta("1 days"),
156
+ pd.Timedelta("2 days"),
157
+ pd.Timedelta("3 days"),
158
+ pd.NaT,
159
+ ],
160
+ ],
161
+ )
162
+ def test_quantile_box(self, case):
163
+ ser = Series(case, name="XXX")
164
+ res = ser.quantile(0.5)
165
+ assert res == case[1]
166
+
167
+ res = ser.quantile([0.5])
168
+ exp = Series([case[1]], index=[0.5], name="XXX")
169
+ tm.assert_series_equal(res, exp)
170
+
171
+ def test_datetime_timedelta_quantiles(self):
172
+ # covers #9694
173
+ assert pd.isna(Series([], dtype="M8[ns]").quantile(0.5))
174
+ assert pd.isna(Series([], dtype="m8[ns]").quantile(0.5))
175
+
176
+ def test_quantile_nat(self):
177
+ res = Series([pd.NaT, pd.NaT]).quantile(0.5)
178
+ assert res is pd.NaT
179
+
180
+ res = Series([pd.NaT, pd.NaT]).quantile([0.5])
181
+ tm.assert_series_equal(res, Series([pd.NaT], index=[0.5]))
182
+
183
+ @pytest.mark.parametrize(
184
+ "values, dtype",
185
+ [([0, 0, 0, 1, 2, 3], "Sparse[int]"), ([0.0, None, 1.0, 2.0], "Sparse[float]")],
186
+ )
187
+ def test_quantile_sparse(self, values, dtype):
188
+ ser = Series(values, dtype=dtype)
189
+ result = ser.quantile([0.5])
190
+ expected = Series(np.asarray(ser)).quantile([0.5]).astype("Sparse[float]")
191
+ tm.assert_series_equal(result, expected)
192
+
193
+ def test_quantile_empty_float64(self):
194
+ # floats
195
+ ser = Series([], dtype="float64")
196
+
197
+ res = ser.quantile(0.5)
198
+ assert np.isnan(res)
199
+
200
+ res = ser.quantile([0.5])
201
+ exp = Series([np.nan], index=[0.5])
202
+ tm.assert_series_equal(res, exp)
203
+
204
+ def test_quantile_empty_int64(self):
205
+ # int
206
+ ser = Series([], dtype="int64")
207
+
208
+ res = ser.quantile(0.5)
209
+ assert np.isnan(res)
210
+
211
+ res = ser.quantile([0.5])
212
+ exp = Series([np.nan], index=[0.5])
213
+ tm.assert_series_equal(res, exp)
214
+
215
+ def test_quantile_empty_dt64(self):
216
+ # datetime
217
+ ser = Series([], dtype="datetime64[ns]")
218
+
219
+ res = ser.quantile(0.5)
220
+ assert res is pd.NaT
221
+
222
+ res = ser.quantile([0.5])
223
+ exp = Series([pd.NaT], index=[0.5], dtype=ser.dtype)
224
+ tm.assert_series_equal(res, exp)
225
+
226
+ @pytest.mark.parametrize("dtype", [int, float, "Int64"])
227
+ def test_quantile_dtypes(self, dtype):
228
+ result = Series([1, 2, 3], dtype=dtype).quantile(np.arange(0, 1, 0.25))
229
+ expected = Series(np.arange(1, 3, 0.5), index=np.arange(0, 1, 0.25))
230
+ if dtype == "Int64":
231
+ expected = expected.astype("Float64")
232
+ tm.assert_series_equal(result, expected)
233
+
234
+ def test_quantile_all_na(self, any_int_ea_dtype):
235
+ # GH#50681
236
+ ser = Series([pd.NA, pd.NA], dtype=any_int_ea_dtype)
237
+ with tm.assert_produces_warning(None):
238
+ result = ser.quantile([0.1, 0.5])
239
+ expected = Series([pd.NA, pd.NA], dtype=any_int_ea_dtype, index=[0.1, 0.5])
240
+ tm.assert_series_equal(result, expected)
241
+
242
+ def test_quantile_dtype_size(self, any_int_ea_dtype):
243
+ # GH#50681
244
+ ser = Series([pd.NA, pd.NA, 1], dtype=any_int_ea_dtype)
245
+ result = ser.quantile([0.1, 0.5])
246
+ expected = Series([1, 1], dtype=any_int_ea_dtype, index=[0.1, 0.5])
247
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_rank.py ADDED
@@ -0,0 +1,563 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from itertools import chain
2
+ import operator
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ from pandas._libs.algos import (
8
+ Infinity,
9
+ NegInfinity,
10
+ )
11
+ import pandas.util._test_decorators as td
12
+
13
+ from pandas import (
14
+ NA,
15
+ NaT,
16
+ Series,
17
+ Timestamp,
18
+ date_range,
19
+ )
20
+ import pandas._testing as tm
21
+ from pandas.api.types import CategoricalDtype
22
+
23
+
24
+ @pytest.fixture
25
+ def ser():
26
+ return Series([1, 3, 4, 2, np.nan, 2, 1, 5, np.nan, 3])
27
+
28
+
29
+ @pytest.fixture(
30
+ params=[
31
+ ["average", np.array([1.5, 5.5, 7.0, 3.5, np.nan, 3.5, 1.5, 8.0, np.nan, 5.5])],
32
+ ["min", np.array([1, 5, 7, 3, np.nan, 3, 1, 8, np.nan, 5])],
33
+ ["max", np.array([2, 6, 7, 4, np.nan, 4, 2, 8, np.nan, 6])],
34
+ ["first", np.array([1, 5, 7, 3, np.nan, 4, 2, 8, np.nan, 6])],
35
+ ["dense", np.array([1, 3, 4, 2, np.nan, 2, 1, 5, np.nan, 3])],
36
+ ],
37
+ ids=lambda x: x[0],
38
+ )
39
+ def results(request):
40
+ return request.param
41
+
42
+
43
+ @pytest.fixture(
44
+ params=[
45
+ "object",
46
+ "float64",
47
+ "int64",
48
+ "Float64",
49
+ "Int64",
50
+ pytest.param("float64[pyarrow]", marks=td.skip_if_no("pyarrow")),
51
+ pytest.param("int64[pyarrow]", marks=td.skip_if_no("pyarrow")),
52
+ pytest.param("string[pyarrow]", marks=td.skip_if_no("pyarrow")),
53
+ "string[python]",
54
+ "str",
55
+ ]
56
+ )
57
+ def dtype(request):
58
+ return request.param
59
+
60
+
61
+ def expected_dtype(dtype, method, pct=False):
62
+ exp_dtype = "float64"
63
+ # elif dtype in ["Int64", "Float64", "string[pyarrow]", "string[python]"]:
64
+ if dtype in ["string[pyarrow]"]:
65
+ exp_dtype = "Float64"
66
+ elif dtype in ["float64[pyarrow]", "int64[pyarrow]"]:
67
+ if method == "average" or pct:
68
+ exp_dtype = "double[pyarrow]"
69
+ else:
70
+ exp_dtype = "uint64[pyarrow]"
71
+
72
+ return exp_dtype
73
+
74
+
75
+ class TestSeriesRank:
76
+ def test_rank(self, datetime_series):
77
+ sp_stats = pytest.importorskip("scipy.stats")
78
+
79
+ datetime_series[::2] = np.nan
80
+ datetime_series[:10:3] = 4.0
81
+
82
+ ranks = datetime_series.rank()
83
+ oranks = datetime_series.astype("O").rank()
84
+
85
+ tm.assert_series_equal(ranks, oranks)
86
+
87
+ mask = np.isnan(datetime_series)
88
+ filled = datetime_series.fillna(np.inf)
89
+
90
+ # rankdata returns a ndarray
91
+ exp = Series(sp_stats.rankdata(filled), index=filled.index, name="ts")
92
+ exp[mask] = np.nan
93
+
94
+ tm.assert_series_equal(ranks, exp)
95
+
96
+ iseries = Series(np.arange(5).repeat(2))
97
+
98
+ iranks = iseries.rank()
99
+ exp = iseries.astype(float).rank()
100
+ tm.assert_series_equal(iranks, exp)
101
+ iseries = Series(np.arange(5)) + 1.0
102
+ exp = iseries / 5.0
103
+ iranks = iseries.rank(pct=True)
104
+
105
+ tm.assert_series_equal(iranks, exp)
106
+
107
+ iseries = Series(np.repeat(1, 100))
108
+ exp = Series(np.repeat(0.505, 100))
109
+ iranks = iseries.rank(pct=True)
110
+ tm.assert_series_equal(iranks, exp)
111
+
112
+ # Explicit cast to float to avoid implicit cast when setting nan
113
+ iseries = iseries.astype("float")
114
+ iseries[1] = np.nan
115
+ exp = Series(np.repeat(50.0 / 99.0, 100))
116
+ exp[1] = np.nan
117
+ iranks = iseries.rank(pct=True)
118
+ tm.assert_series_equal(iranks, exp)
119
+
120
+ iseries = Series(np.arange(5)) + 1.0
121
+ iseries[4] = np.nan
122
+ exp = iseries / 4.0
123
+ iranks = iseries.rank(pct=True)
124
+ tm.assert_series_equal(iranks, exp)
125
+
126
+ iseries = Series(np.repeat(np.nan, 100))
127
+ exp = iseries.copy()
128
+ iranks = iseries.rank(pct=True)
129
+ tm.assert_series_equal(iranks, exp)
130
+
131
+ # Explicit cast to float to avoid implicit cast when setting nan
132
+ iseries = Series(np.arange(5), dtype="float") + 1
133
+ iseries[4] = np.nan
134
+ exp = iseries / 4.0
135
+ iranks = iseries.rank(pct=True)
136
+ tm.assert_series_equal(iranks, exp)
137
+
138
+ rng = date_range("1/1/1990", periods=5)
139
+ # Explicit cast to float to avoid implicit cast when setting nan
140
+ iseries = Series(np.arange(5), rng, dtype="float") + 1
141
+ iseries.iloc[4] = np.nan
142
+ exp = iseries / 4.0
143
+ iranks = iseries.rank(pct=True)
144
+ tm.assert_series_equal(iranks, exp)
145
+
146
+ iseries = Series([1e-50, 1e-100, 1e-20, 1e-2, 1e-20 + 1e-30, 1e-1])
147
+ exp = Series([2, 1, 3, 5, 4, 6.0])
148
+ iranks = iseries.rank()
149
+ tm.assert_series_equal(iranks, exp)
150
+
151
+ # GH 5968
152
+ iseries = Series(["3 day", "1 day 10m", "-2 day", NaT], dtype="m8[ns]")
153
+ exp = Series([3, 2, 1, np.nan])
154
+ iranks = iseries.rank()
155
+ tm.assert_series_equal(iranks, exp)
156
+
157
+ values = np.array(
158
+ [-50, -1, -1e-20, -1e-25, -1e-50, 0, 1e-40, 1e-20, 1e-10, 2, 40],
159
+ dtype="float64",
160
+ )
161
+ random_order = np.random.default_rng(2).permutation(len(values))
162
+ iseries = Series(values[random_order])
163
+ exp = Series(random_order + 1.0, dtype="float64")
164
+ iranks = iseries.rank()
165
+ tm.assert_series_equal(iranks, exp)
166
+
167
+ def test_rank_categorical(self):
168
+ # GH issue #15420 rank incorrectly orders ordered categories
169
+
170
+ # Test ascending/descending ranking for ordered categoricals
171
+ exp = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
172
+ exp_desc = Series([6.0, 5.0, 4.0, 3.0, 2.0, 1.0])
173
+ ordered = Series(
174
+ ["first", "second", "third", "fourth", "fifth", "sixth"]
175
+ ).astype(
176
+ CategoricalDtype(
177
+ categories=["first", "second", "third", "fourth", "fifth", "sixth"],
178
+ ordered=True,
179
+ )
180
+ )
181
+ tm.assert_series_equal(ordered.rank(), exp)
182
+ tm.assert_series_equal(ordered.rank(ascending=False), exp_desc)
183
+
184
+ # Unordered categoricals should be ranked as objects
185
+ unordered = Series(
186
+ ["first", "second", "third", "fourth", "fifth", "sixth"]
187
+ ).astype(
188
+ CategoricalDtype(
189
+ categories=["first", "second", "third", "fourth", "fifth", "sixth"],
190
+ ordered=False,
191
+ )
192
+ )
193
+ exp_unordered = Series([2.0, 4.0, 6.0, 3.0, 1.0, 5.0])
194
+ res = unordered.rank()
195
+ tm.assert_series_equal(res, exp_unordered)
196
+
197
+ unordered1 = Series([1, 2, 3, 4, 5, 6]).astype(
198
+ CategoricalDtype([1, 2, 3, 4, 5, 6], False)
199
+ )
200
+ exp_unordered1 = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
201
+ res1 = unordered1.rank()
202
+ tm.assert_series_equal(res1, exp_unordered1)
203
+
204
+ # Test na_option for rank data
205
+ na_ser = Series(
206
+ ["first", "second", "third", "fourth", "fifth", "sixth", np.nan]
207
+ ).astype(
208
+ CategoricalDtype(
209
+ ["first", "second", "third", "fourth", "fifth", "sixth", "seventh"],
210
+ True,
211
+ )
212
+ )
213
+
214
+ exp_top = Series([2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 1.0])
215
+ exp_bot = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0])
216
+ exp_keep = Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, np.nan])
217
+
218
+ tm.assert_series_equal(na_ser.rank(na_option="top"), exp_top)
219
+ tm.assert_series_equal(na_ser.rank(na_option="bottom"), exp_bot)
220
+ tm.assert_series_equal(na_ser.rank(na_option="keep"), exp_keep)
221
+
222
+ # Test na_option for rank data with ascending False
223
+ exp_top = Series([7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0])
224
+ exp_bot = Series([6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 7.0])
225
+ exp_keep = Series([6.0, 5.0, 4.0, 3.0, 2.0, 1.0, np.nan])
226
+
227
+ tm.assert_series_equal(na_ser.rank(na_option="top", ascending=False), exp_top)
228
+ tm.assert_series_equal(
229
+ na_ser.rank(na_option="bottom", ascending=False), exp_bot
230
+ )
231
+ tm.assert_series_equal(na_ser.rank(na_option="keep", ascending=False), exp_keep)
232
+
233
+ # Test invalid values for na_option
234
+ msg = "na_option must be one of 'keep', 'top', or 'bottom'"
235
+
236
+ with pytest.raises(ValueError, match=msg):
237
+ na_ser.rank(na_option="bad", ascending=False)
238
+
239
+ # invalid type
240
+ with pytest.raises(ValueError, match=msg):
241
+ na_ser.rank(na_option=True, ascending=False)
242
+
243
+ # Test with pct=True
244
+ na_ser = Series(["first", "second", "third", "fourth", np.nan]).astype(
245
+ CategoricalDtype(["first", "second", "third", "fourth"], True)
246
+ )
247
+ exp_top = Series([0.4, 0.6, 0.8, 1.0, 0.2])
248
+ exp_bot = Series([0.2, 0.4, 0.6, 0.8, 1.0])
249
+ exp_keep = Series([0.25, 0.5, 0.75, 1.0, np.nan])
250
+
251
+ tm.assert_series_equal(na_ser.rank(na_option="top", pct=True), exp_top)
252
+ tm.assert_series_equal(na_ser.rank(na_option="bottom", pct=True), exp_bot)
253
+ tm.assert_series_equal(na_ser.rank(na_option="keep", pct=True), exp_keep)
254
+
255
+ def test_rank_signature(self):
256
+ s = Series([0, 1])
257
+ s.rank(method="average")
258
+ msg = "No axis named average for object type Series"
259
+ with pytest.raises(ValueError, match=msg):
260
+ s.rank("average")
261
+
262
+ def test_rank_tie_methods(self, ser, results, dtype, using_infer_string):
263
+ method, exp = results
264
+ if (
265
+ dtype == "int64"
266
+ or dtype == "Int64"
267
+ or (not using_infer_string and dtype == "str")
268
+ ):
269
+ pytest.skip("int64/str does not support NaN")
270
+
271
+ ser = ser if dtype is None else ser.astype(dtype)
272
+ result = ser.rank(method=method)
273
+ tm.assert_series_equal(result, Series(exp, dtype=expected_dtype(dtype, method)))
274
+
275
+ @pytest.mark.parametrize("ascending", [True, False])
276
+ @pytest.mark.parametrize("method", ["average", "min", "max", "first", "dense"])
277
+ @pytest.mark.parametrize("na_option", ["top", "bottom", "keep"])
278
+ @pytest.mark.parametrize(
279
+ "dtype, na_value, pos_inf, neg_inf",
280
+ [
281
+ ("object", None, Infinity(), NegInfinity()),
282
+ ("float64", np.nan, np.inf, -np.inf),
283
+ ("Float64", NA, np.inf, -np.inf),
284
+ pytest.param(
285
+ "float64[pyarrow]",
286
+ NA,
287
+ np.inf,
288
+ -np.inf,
289
+ marks=td.skip_if_no("pyarrow"),
290
+ ),
291
+ ],
292
+ )
293
+ def test_rank_tie_methods_on_infs_nans(
294
+ self, method, na_option, ascending, dtype, na_value, pos_inf, neg_inf
295
+ ):
296
+ pytest.importorskip("scipy")
297
+ if dtype == "float64[pyarrow]":
298
+ if method == "average":
299
+ exp_dtype = "float64[pyarrow]"
300
+ else:
301
+ exp_dtype = "uint64[pyarrow]"
302
+ else:
303
+ exp_dtype = "float64"
304
+
305
+ chunk = 3
306
+ in_arr = [neg_inf] * chunk + [na_value] * chunk + [pos_inf] * chunk
307
+ iseries = Series(in_arr, dtype=dtype)
308
+ exp_ranks = {
309
+ "average": ([2, 2, 2], [5, 5, 5], [8, 8, 8]),
310
+ "min": ([1, 1, 1], [4, 4, 4], [7, 7, 7]),
311
+ "max": ([3, 3, 3], [6, 6, 6], [9, 9, 9]),
312
+ "first": ([1, 2, 3], [4, 5, 6], [7, 8, 9]),
313
+ "dense": ([1, 1, 1], [2, 2, 2], [3, 3, 3]),
314
+ }
315
+ ranks = exp_ranks[method]
316
+ if na_option == "top":
317
+ order = [ranks[1], ranks[0], ranks[2]]
318
+ elif na_option == "bottom":
319
+ order = [ranks[0], ranks[2], ranks[1]]
320
+ else:
321
+ order = [ranks[0], [np.nan] * chunk, ranks[1]]
322
+ expected = order if ascending else order[::-1]
323
+ expected = list(chain.from_iterable(expected))
324
+ result = iseries.rank(method=method, na_option=na_option, ascending=ascending)
325
+ tm.assert_series_equal(result, Series(expected, dtype=exp_dtype))
326
+
327
+ def test_rank_desc_mix_nans_infs(self):
328
+ # GH 19538
329
+ # check descending ranking when mix nans and infs
330
+ iseries = Series([1, np.nan, np.inf, -np.inf, 25])
331
+ result = iseries.rank(ascending=False)
332
+ exp = Series([3, np.nan, 1, 4, 2], dtype="float64")
333
+ tm.assert_series_equal(result, exp)
334
+
335
+ @pytest.mark.parametrize("method", ["average", "min", "max", "first", "dense"])
336
+ @pytest.mark.parametrize(
337
+ "op, value",
338
+ [
339
+ [operator.add, 0],
340
+ [operator.add, 1e6],
341
+ [operator.mul, 1e-6],
342
+ ],
343
+ )
344
+ def test_rank_methods_series(self, method, op, value):
345
+ sp_stats = pytest.importorskip("scipy.stats")
346
+
347
+ xs = np.random.default_rng(2).standard_normal(9)
348
+ xs = np.concatenate([xs[i:] for i in range(0, 9, 2)]) # add duplicates
349
+ np.random.default_rng(2).shuffle(xs)
350
+
351
+ index = [chr(ord("a") + i) for i in range(len(xs))]
352
+ vals = op(xs, value)
353
+ ts = Series(vals, index=index)
354
+ result = ts.rank(method=method)
355
+ sprank = sp_stats.rankdata(vals, method if method != "first" else "ordinal")
356
+ expected = Series(sprank, index=index).astype("float64")
357
+ tm.assert_series_equal(result, expected)
358
+
359
+ @pytest.mark.parametrize(
360
+ "ser, exp",
361
+ [
362
+ ([1], [1]),
363
+ ([2], [1]),
364
+ ([0], [1]),
365
+ ([2, 2], [1, 1]),
366
+ ([1, 2, 3], [1, 2, 3]),
367
+ ([4, 2, 1], [3, 2, 1]),
368
+ ([1, 1, 5, 5, 3], [1, 1, 3, 3, 2]),
369
+ ([-5, -4, -3, -2, -1], [1, 2, 3, 4, 5]),
370
+ ],
371
+ )
372
+ def test_rank_dense_method(self, dtype, ser, exp):
373
+ if ser[0] < 0 and dtype.startswith("str"):
374
+ exp = exp[::-1]
375
+ s = Series(ser).astype(dtype)
376
+ result = s.rank(method="dense")
377
+ expected = Series(exp).astype(expected_dtype(dtype, "dense"))
378
+ tm.assert_series_equal(result, expected)
379
+
380
+ def test_rank_descending(self, ser, results, dtype, using_infer_string):
381
+ method, _ = results
382
+ if dtype == "int64" or (not using_infer_string and dtype == "str"):
383
+ s = ser.dropna()
384
+ else:
385
+ s = ser.astype(dtype)
386
+
387
+ res = s.rank(ascending=False)
388
+ if dtype.startswith("str"):
389
+ expected = (s.astype("float64").max() - s.astype("float64")).rank()
390
+ else:
391
+ expected = (s.max() - s).rank()
392
+ tm.assert_series_equal(res, expected.astype(expected_dtype(dtype, "average")))
393
+
394
+ if dtype.startswith("str"):
395
+ expected = (s.astype("float64").max() - s.astype("float64")).rank(
396
+ method=method
397
+ )
398
+ else:
399
+ expected = (s.max() - s).rank(method=method)
400
+ res2 = s.rank(method=method, ascending=False)
401
+ tm.assert_series_equal(res2, expected.astype(expected_dtype(dtype, method)))
402
+
403
+ def test_rank_int(self, ser, results):
404
+ method, exp = results
405
+ s = ser.dropna().astype("i8")
406
+
407
+ result = s.rank(method=method)
408
+ expected = Series(exp).dropna()
409
+ expected.index = result.index
410
+ tm.assert_series_equal(result, expected)
411
+
412
+ def test_rank_object_bug(self):
413
+ # GH 13445
414
+
415
+ # smoke tests
416
+ Series([np.nan] * 32).astype(object).rank(ascending=True)
417
+ Series([np.nan] * 32).astype(object).rank(ascending=False)
418
+
419
+ def test_rank_modify_inplace(self):
420
+ # GH 18521
421
+ # Check rank does not mutate series
422
+ s = Series([Timestamp("2017-01-05 10:20:27.569000"), NaT])
423
+ expected = s.copy()
424
+
425
+ s.rank()
426
+ result = s
427
+ tm.assert_series_equal(result, expected)
428
+
429
+ def test_rank_ea_small_values(self):
430
+ # GH#52471
431
+ ser = Series(
432
+ [5.4954145e29, -9.791984e-21, 9.3715776e-26, NA, 1.8790257e-28],
433
+ dtype="Float64",
434
+ )
435
+ result = ser.rank(method="min")
436
+ expected = Series([4, 1, 3, np.nan, 2])
437
+ tm.assert_series_equal(result, expected)
438
+
439
+
440
+ # GH15630, pct should be on 100% basis when method='dense'
441
+
442
+
443
+ @pytest.mark.parametrize(
444
+ "ser, exp",
445
+ [
446
+ ([1], [1.0]),
447
+ ([1, 2], [1.0 / 2, 2.0 / 2]),
448
+ ([2, 2], [1.0, 1.0]),
449
+ ([1, 2, 3], [1.0 / 3, 2.0 / 3, 3.0 / 3]),
450
+ ([1, 2, 2], [1.0 / 2, 2.0 / 2, 2.0 / 2]),
451
+ ([4, 2, 1], [3.0 / 3, 2.0 / 3, 1.0 / 3]),
452
+ ([1, 1, 5, 5, 3], [1.0 / 3, 1.0 / 3, 3.0 / 3, 3.0 / 3, 2.0 / 3]),
453
+ ([1, 1, 3, 3, 5, 5], [1.0 / 3, 1.0 / 3, 2.0 / 3, 2.0 / 3, 3.0 / 3, 3.0 / 3]),
454
+ ([-5, -4, -3, -2, -1], [1.0 / 5, 2.0 / 5, 3.0 / 5, 4.0 / 5, 5.0 / 5]),
455
+ ],
456
+ )
457
+ def test_rank_dense_pct(dtype, ser, exp):
458
+ if ser[0] < 0 and dtype.startswith("str"):
459
+ exp = exp[::-1]
460
+ s = Series(ser).astype(dtype)
461
+ result = s.rank(method="dense", pct=True)
462
+ expected = Series(exp).astype(expected_dtype(dtype, "dense", pct=True))
463
+ tm.assert_series_equal(result, expected)
464
+
465
+
466
+ @pytest.mark.parametrize(
467
+ "ser, exp",
468
+ [
469
+ ([1], [1.0]),
470
+ ([1, 2], [1.0 / 2, 2.0 / 2]),
471
+ ([2, 2], [1.0 / 2, 1.0 / 2]),
472
+ ([1, 2, 3], [1.0 / 3, 2.0 / 3, 3.0 / 3]),
473
+ ([1, 2, 2], [1.0 / 3, 2.0 / 3, 2.0 / 3]),
474
+ ([4, 2, 1], [3.0 / 3, 2.0 / 3, 1.0 / 3]),
475
+ ([1, 1, 5, 5, 3], [1.0 / 5, 1.0 / 5, 4.0 / 5, 4.0 / 5, 3.0 / 5]),
476
+ ([1, 1, 3, 3, 5, 5], [1.0 / 6, 1.0 / 6, 3.0 / 6, 3.0 / 6, 5.0 / 6, 5.0 / 6]),
477
+ ([-5, -4, -3, -2, -1], [1.0 / 5, 2.0 / 5, 3.0 / 5, 4.0 / 5, 5.0 / 5]),
478
+ ],
479
+ )
480
+ def test_rank_min_pct(dtype, ser, exp):
481
+ if ser[0] < 0 and dtype.startswith("str"):
482
+ exp = exp[::-1]
483
+ s = Series(ser).astype(dtype)
484
+ result = s.rank(method="min", pct=True)
485
+ expected = Series(exp).astype(expected_dtype(dtype, "min", pct=True))
486
+ tm.assert_series_equal(result, expected)
487
+
488
+
489
+ @pytest.mark.parametrize(
490
+ "ser, exp",
491
+ [
492
+ ([1], [1.0]),
493
+ ([1, 2], [1.0 / 2, 2.0 / 2]),
494
+ ([2, 2], [1.0, 1.0]),
495
+ ([1, 2, 3], [1.0 / 3, 2.0 / 3, 3.0 / 3]),
496
+ ([1, 2, 2], [1.0 / 3, 3.0 / 3, 3.0 / 3]),
497
+ ([4, 2, 1], [3.0 / 3, 2.0 / 3, 1.0 / 3]),
498
+ ([1, 1, 5, 5, 3], [2.0 / 5, 2.0 / 5, 5.0 / 5, 5.0 / 5, 3.0 / 5]),
499
+ ([1, 1, 3, 3, 5, 5], [2.0 / 6, 2.0 / 6, 4.0 / 6, 4.0 / 6, 6.0 / 6, 6.0 / 6]),
500
+ ([-5, -4, -3, -2, -1], [1.0 / 5, 2.0 / 5, 3.0 / 5, 4.0 / 5, 5.0 / 5]),
501
+ ],
502
+ )
503
+ def test_rank_max_pct(dtype, ser, exp):
504
+ if ser[0] < 0 and dtype.startswith("str"):
505
+ exp = exp[::-1]
506
+ s = Series(ser).astype(dtype)
507
+ result = s.rank(method="max", pct=True)
508
+ expected = Series(exp).astype(expected_dtype(dtype, "max", pct=True))
509
+ tm.assert_series_equal(result, expected)
510
+
511
+
512
+ @pytest.mark.parametrize(
513
+ "ser, exp",
514
+ [
515
+ ([1], [1.0]),
516
+ ([1, 2], [1.0 / 2, 2.0 / 2]),
517
+ ([2, 2], [1.5 / 2, 1.5 / 2]),
518
+ ([1, 2, 3], [1.0 / 3, 2.0 / 3, 3.0 / 3]),
519
+ ([1, 2, 2], [1.0 / 3, 2.5 / 3, 2.5 / 3]),
520
+ ([4, 2, 1], [3.0 / 3, 2.0 / 3, 1.0 / 3]),
521
+ ([1, 1, 5, 5, 3], [1.5 / 5, 1.5 / 5, 4.5 / 5, 4.5 / 5, 3.0 / 5]),
522
+ ([1, 1, 3, 3, 5, 5], [1.5 / 6, 1.5 / 6, 3.5 / 6, 3.5 / 6, 5.5 / 6, 5.5 / 6]),
523
+ ([-5, -4, -3, -2, -1], [1.0 / 5, 2.0 / 5, 3.0 / 5, 4.0 / 5, 5.0 / 5]),
524
+ ],
525
+ )
526
+ def test_rank_average_pct(dtype, ser, exp):
527
+ if ser[0] < 0 and dtype.startswith("str"):
528
+ exp = exp[::-1]
529
+ s = Series(ser).astype(dtype)
530
+ result = s.rank(method="average", pct=True)
531
+ expected = Series(exp).astype(expected_dtype(dtype, "average", pct=True))
532
+ tm.assert_series_equal(result, expected)
533
+
534
+
535
+ @pytest.mark.parametrize(
536
+ "ser, exp",
537
+ [
538
+ ([1], [1.0]),
539
+ ([1, 2], [1.0 / 2, 2.0 / 2]),
540
+ ([2, 2], [1.0 / 2, 2.0 / 2.0]),
541
+ ([1, 2, 3], [1.0 / 3, 2.0 / 3, 3.0 / 3]),
542
+ ([1, 2, 2], [1.0 / 3, 2.0 / 3, 3.0 / 3]),
543
+ ([4, 2, 1], [3.0 / 3, 2.0 / 3, 1.0 / 3]),
544
+ ([1, 1, 5, 5, 3], [1.0 / 5, 2.0 / 5, 4.0 / 5, 5.0 / 5, 3.0 / 5]),
545
+ ([1, 1, 3, 3, 5, 5], [1.0 / 6, 2.0 / 6, 3.0 / 6, 4.0 / 6, 5.0 / 6, 6.0 / 6]),
546
+ ([-5, -4, -3, -2, -1], [1.0 / 5, 2.0 / 5, 3.0 / 5, 4.0 / 5, 5.0 / 5]),
547
+ ],
548
+ )
549
+ def test_rank_first_pct(dtype, ser, exp):
550
+ if ser[0] < 0 and dtype.startswith("str"):
551
+ exp = exp[::-1]
552
+ s = Series(ser).astype(dtype)
553
+ result = s.rank(method="first", pct=True)
554
+ expected = Series(exp).astype(expected_dtype(dtype, "first", pct=True))
555
+ tm.assert_series_equal(result, expected)
556
+
557
+
558
+ @pytest.mark.single_cpu
559
+ def test_pct_max_many_rows():
560
+ # GH 18271
561
+ s = Series(np.arange(2**24 + 1))
562
+ result = s.rank(pct=True).max()
563
+ assert result == 1
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_reindex.py ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas.util._test_decorators as td
5
+
6
+ from pandas import (
7
+ NA,
8
+ Categorical,
9
+ Float64Dtype,
10
+ Index,
11
+ MultiIndex,
12
+ NaT,
13
+ Period,
14
+ PeriodIndex,
15
+ RangeIndex,
16
+ Series,
17
+ Timedelta,
18
+ Timestamp,
19
+ date_range,
20
+ isna,
21
+ )
22
+ import pandas._testing as tm
23
+
24
+
25
+ def test_reindex(datetime_series, string_series):
26
+ identity = string_series.reindex(string_series.index)
27
+
28
+ assert tm.shares_memory(string_series.index, identity.index)
29
+
30
+ assert identity.index.is_(string_series.index)
31
+ assert identity.index.identical(string_series.index)
32
+
33
+ subIndex = string_series.index[10:20]
34
+ subSeries = string_series.reindex(subIndex)
35
+
36
+ for idx, val in subSeries.items():
37
+ assert val == string_series[idx]
38
+
39
+ subIndex2 = datetime_series.index[10:20]
40
+ subTS = datetime_series.reindex(subIndex2)
41
+
42
+ for idx, val in subTS.items():
43
+ assert val == datetime_series[idx]
44
+ stuffSeries = datetime_series.reindex(subIndex)
45
+
46
+ assert np.isnan(stuffSeries).all()
47
+
48
+ # This is extremely important for the Cython code to not screw up
49
+ nonContigIndex = datetime_series.index[::2]
50
+ subNonContig = datetime_series.reindex(nonContigIndex)
51
+ for idx, val in subNonContig.items():
52
+ assert val == datetime_series[idx]
53
+
54
+ # return a copy the same index here
55
+ result = datetime_series.reindex()
56
+ assert result is not datetime_series
57
+
58
+
59
+ def test_reindex_nan():
60
+ ts = Series([2, 3, 5, 7], index=[1, 4, np.nan, 8])
61
+
62
+ i, j = [np.nan, 1, np.nan, 8, 4, np.nan], [2, 0, 2, 3, 1, 2]
63
+ tm.assert_series_equal(ts.reindex(i), ts.iloc[j])
64
+
65
+ ts.index = ts.index.astype("object")
66
+
67
+ # reindex coerces index.dtype to float, loc/iloc doesn't
68
+ tm.assert_series_equal(ts.reindex(i), ts.iloc[j], check_index_type=False)
69
+
70
+
71
+ def test_reindex_series_add_nat():
72
+ rng = date_range("1/1/2000 00:00:00", periods=10, freq="10s")
73
+ series = Series(rng)
74
+
75
+ result = series.reindex(range(15))
76
+ assert np.issubdtype(result.dtype, np.dtype("M8[ns]"))
77
+
78
+ mask = result.isna()
79
+ assert mask[-5:].all()
80
+ assert not mask[:-5].any()
81
+
82
+
83
+ def test_reindex_with_datetimes():
84
+ rng = date_range("1/1/2000", periods=20)
85
+ ts = Series(np.random.default_rng(2).standard_normal(20), index=rng)
86
+
87
+ result = ts.reindex(list(ts.index[5:10]))
88
+ expected = ts[5:10]
89
+ expected.index = expected.index._with_freq(None)
90
+ tm.assert_series_equal(result, expected)
91
+
92
+ result = ts[list(ts.index[5:10])]
93
+ tm.assert_series_equal(result, expected)
94
+
95
+
96
+ def test_reindex_corner(datetime_series):
97
+ # (don't forget to fix this) I think it's fixed
98
+ empty = Series(index=[])
99
+ empty.reindex(datetime_series.index, method="pad") # it works
100
+
101
+ # corner case: pad empty series
102
+ reindexed = empty.reindex(datetime_series.index, method="pad")
103
+
104
+ # pass non-Index
105
+ reindexed = datetime_series.reindex(list(datetime_series.index))
106
+ datetime_series.index = datetime_series.index._with_freq(None)
107
+ tm.assert_series_equal(datetime_series, reindexed)
108
+
109
+ # bad fill method
110
+ ts = datetime_series[::2]
111
+ msg = (
112
+ r"Invalid fill method\. Expecting pad \(ffill\), backfill "
113
+ r"\(bfill\) or nearest\. Got foo"
114
+ )
115
+ with pytest.raises(ValueError, match=msg):
116
+ ts.reindex(datetime_series.index, method="foo")
117
+
118
+
119
+ def test_reindex_pad():
120
+ s = Series(np.arange(10), dtype="int64")
121
+ s2 = s[::2]
122
+
123
+ reindexed = s2.reindex(s.index, method="pad")
124
+ reindexed2 = s2.reindex(s.index, method="ffill")
125
+ tm.assert_series_equal(reindexed, reindexed2)
126
+
127
+ expected = Series([0, 0, 2, 2, 4, 4, 6, 6, 8, 8])
128
+ tm.assert_series_equal(reindexed, expected)
129
+
130
+
131
+ def test_reindex_pad2():
132
+ # GH4604
133
+ s = Series([1, 2, 3, 4, 5], index=["a", "b", "c", "d", "e"])
134
+ new_index = ["a", "g", "c", "f"]
135
+ expected = Series([1, 1, 3, 3], index=new_index)
136
+
137
+ # this changes dtype because the ffill happens after
138
+ result = s.reindex(new_index).ffill()
139
+ tm.assert_series_equal(result, expected.astype("float64"))
140
+
141
+ msg = "The 'downcast' keyword in ffill is deprecated"
142
+ with tm.assert_produces_warning(FutureWarning, match=msg):
143
+ result = s.reindex(new_index).ffill(downcast="infer")
144
+ tm.assert_series_equal(result, expected)
145
+
146
+ expected = Series([1, 5, 3, 5], index=new_index)
147
+ result = s.reindex(new_index, method="ffill")
148
+ tm.assert_series_equal(result, expected)
149
+
150
+
151
+ def test_reindex_inference():
152
+ # inference of new dtype
153
+ s = Series([True, False, False, True], index=list("abcd"))
154
+ new_index = "agc"
155
+ msg = "Downcasting object dtype arrays on"
156
+ with tm.assert_produces_warning(FutureWarning, match=msg):
157
+ result = s.reindex(list(new_index)).ffill()
158
+ expected = Series([True, True, False], index=list(new_index))
159
+ tm.assert_series_equal(result, expected)
160
+
161
+
162
+ def test_reindex_downcasting():
163
+ # GH4618 shifted series downcasting
164
+ s = Series(False, index=range(5))
165
+ msg = "Downcasting object dtype arrays on"
166
+ with tm.assert_produces_warning(FutureWarning, match=msg):
167
+ result = s.shift(1).bfill()
168
+ expected = Series(False, index=range(5))
169
+ tm.assert_series_equal(result, expected)
170
+
171
+
172
+ def test_reindex_nearest():
173
+ s = Series(np.arange(10, dtype="int64"))
174
+ target = [0.1, 0.9, 1.5, 2.0]
175
+ result = s.reindex(target, method="nearest")
176
+ expected = Series(np.around(target).astype("int64"), target)
177
+ tm.assert_series_equal(expected, result)
178
+
179
+ result = s.reindex(target, method="nearest", tolerance=0.2)
180
+ expected = Series([0, 1, np.nan, 2], target)
181
+ tm.assert_series_equal(expected, result)
182
+
183
+ result = s.reindex(target, method="nearest", tolerance=[0.3, 0.01, 0.4, 3])
184
+ expected = Series([0, np.nan, np.nan, 2], target)
185
+ tm.assert_series_equal(expected, result)
186
+
187
+
188
+ def test_reindex_int(datetime_series):
189
+ ts = datetime_series[::2]
190
+ int_ts = Series(np.zeros(len(ts), dtype=int), index=ts.index)
191
+
192
+ # this should work fine
193
+ reindexed_int = int_ts.reindex(datetime_series.index)
194
+
195
+ # if NaNs introduced
196
+ assert reindexed_int.dtype == np.float64
197
+
198
+ # NO NaNs introduced
199
+ reindexed_int = int_ts.reindex(int_ts.index[::2])
200
+ assert reindexed_int.dtype == np.dtype(int)
201
+
202
+
203
+ def test_reindex_bool(datetime_series):
204
+ # A series other than float, int, string, or object
205
+ ts = datetime_series[::2]
206
+ bool_ts = Series(np.zeros(len(ts), dtype=bool), index=ts.index)
207
+
208
+ # this should work fine
209
+ reindexed_bool = bool_ts.reindex(datetime_series.index)
210
+
211
+ # if NaNs introduced
212
+ assert reindexed_bool.dtype == np.object_
213
+
214
+ # NO NaNs introduced
215
+ reindexed_bool = bool_ts.reindex(bool_ts.index[::2])
216
+ assert reindexed_bool.dtype == np.bool_
217
+
218
+
219
+ def test_reindex_bool_pad(datetime_series):
220
+ # fail
221
+ ts = datetime_series[5:]
222
+ bool_ts = Series(np.zeros(len(ts), dtype=bool), index=ts.index)
223
+ filled_bool = bool_ts.reindex(datetime_series.index, method="pad")
224
+ assert isna(filled_bool[:5]).all()
225
+
226
+
227
+ def test_reindex_categorical():
228
+ index = date_range("20000101", periods=3)
229
+
230
+ # reindexing to an invalid Categorical
231
+ s = Series(["a", "b", "c"], dtype="category")
232
+ result = s.reindex(index)
233
+ expected = Series(
234
+ Categorical(values=[np.nan, np.nan, np.nan], categories=["a", "b", "c"])
235
+ )
236
+ expected.index = index
237
+ tm.assert_series_equal(result, expected)
238
+
239
+ # partial reindexing
240
+ expected = Series(Categorical(values=["b", "c"], categories=["a", "b", "c"]))
241
+ expected.index = [1, 2]
242
+ result = s.reindex([1, 2])
243
+ tm.assert_series_equal(result, expected)
244
+
245
+ expected = Series(Categorical(values=["c", np.nan], categories=["a", "b", "c"]))
246
+ expected.index = [2, 3]
247
+ result = s.reindex([2, 3])
248
+ tm.assert_series_equal(result, expected)
249
+
250
+
251
+ def test_reindex_astype_order_consistency():
252
+ # GH#17444
253
+ ser = Series([1, 2, 3], index=[2, 0, 1])
254
+ new_index = [0, 1, 2]
255
+ temp_dtype = "category"
256
+ new_dtype = str
257
+ result = ser.reindex(new_index).astype(temp_dtype).astype(new_dtype)
258
+ expected = ser.astype(temp_dtype).reindex(new_index).astype(new_dtype)
259
+ tm.assert_series_equal(result, expected)
260
+
261
+
262
+ def test_reindex_fill_value():
263
+ # -----------------------------------------------------------
264
+ # floats
265
+ floats = Series([1.0, 2.0, 3.0])
266
+ result = floats.reindex([1, 2, 3])
267
+ expected = Series([2.0, 3.0, np.nan], index=[1, 2, 3])
268
+ tm.assert_series_equal(result, expected)
269
+
270
+ result = floats.reindex([1, 2, 3], fill_value=0)
271
+ expected = Series([2.0, 3.0, 0], index=[1, 2, 3])
272
+ tm.assert_series_equal(result, expected)
273
+
274
+ # -----------------------------------------------------------
275
+ # ints
276
+ ints = Series([1, 2, 3])
277
+
278
+ result = ints.reindex([1, 2, 3])
279
+ expected = Series([2.0, 3.0, np.nan], index=[1, 2, 3])
280
+ tm.assert_series_equal(result, expected)
281
+
282
+ # don't upcast
283
+ result = ints.reindex([1, 2, 3], fill_value=0)
284
+ expected = Series([2, 3, 0], index=[1, 2, 3])
285
+ assert issubclass(result.dtype.type, np.integer)
286
+ tm.assert_series_equal(result, expected)
287
+
288
+ # -----------------------------------------------------------
289
+ # objects
290
+ objects = Series([1, 2, 3], dtype=object)
291
+
292
+ result = objects.reindex([1, 2, 3])
293
+ expected = Series([2, 3, np.nan], index=[1, 2, 3], dtype=object)
294
+ tm.assert_series_equal(result, expected)
295
+
296
+ result = objects.reindex([1, 2, 3], fill_value="foo")
297
+ expected = Series([2, 3, "foo"], index=[1, 2, 3], dtype=object)
298
+ tm.assert_series_equal(result, expected)
299
+
300
+ # ------------------------------------------------------------
301
+ # bools
302
+ bools = Series([True, False, True])
303
+
304
+ result = bools.reindex([1, 2, 3])
305
+ expected = Series([False, True, np.nan], index=[1, 2, 3], dtype=object)
306
+ tm.assert_series_equal(result, expected)
307
+
308
+ result = bools.reindex([1, 2, 3], fill_value=False)
309
+ expected = Series([False, True, False], index=[1, 2, 3])
310
+ tm.assert_series_equal(result, expected)
311
+
312
+
313
+ @td.skip_array_manager_not_yet_implemented
314
+ @pytest.mark.parametrize("dtype", ["datetime64[ns]", "timedelta64[ns]"])
315
+ @pytest.mark.parametrize("fill_value", ["string", 0, Timedelta(0)])
316
+ def test_reindex_fill_value_datetimelike_upcast(dtype, fill_value, using_array_manager):
317
+ # https://github.com/pandas-dev/pandas/issues/42921
318
+ if dtype == "timedelta64[ns]" and fill_value == Timedelta(0):
319
+ # use the scalar that is not compatible with the dtype for this test
320
+ fill_value = Timestamp(0)
321
+
322
+ ser = Series([NaT], dtype=dtype)
323
+
324
+ result = ser.reindex([0, 1], fill_value=fill_value)
325
+ expected = Series([NaT, fill_value], index=[0, 1], dtype=object)
326
+ tm.assert_series_equal(result, expected)
327
+
328
+
329
+ def test_reindex_datetimeindexes_tz_naive_and_aware():
330
+ # GH 8306
331
+ idx = date_range("20131101", tz="America/Chicago", periods=7)
332
+ newidx = date_range("20131103", periods=10, freq="h")
333
+ s = Series(range(7), index=idx)
334
+ msg = (
335
+ r"Cannot compare dtypes datetime64\[ns, America/Chicago\] "
336
+ r"and datetime64\[ns\]"
337
+ )
338
+ with pytest.raises(TypeError, match=msg):
339
+ s.reindex(newidx, method="ffill")
340
+
341
+
342
+ def test_reindex_empty_series_tz_dtype():
343
+ # GH 20869
344
+ result = Series(dtype="datetime64[ns, UTC]").reindex([0, 1])
345
+ expected = Series([NaT] * 2, dtype="datetime64[ns, UTC]")
346
+ tm.assert_equal(result, expected)
347
+
348
+
349
+ @pytest.mark.parametrize(
350
+ "p_values, o_values, values, expected_values",
351
+ [
352
+ (
353
+ [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC")],
354
+ [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC"), "All"],
355
+ [1.0, 1.0],
356
+ [1.0, 1.0, np.nan],
357
+ ),
358
+ (
359
+ [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC")],
360
+ [Period("2019Q1", "Q-DEC"), Period("2019Q2", "Q-DEC")],
361
+ [1.0, 1.0],
362
+ [1.0, 1.0],
363
+ ),
364
+ ],
365
+ )
366
+ def test_reindex_periodindex_with_object(p_values, o_values, values, expected_values):
367
+ # GH#28337
368
+ period_index = PeriodIndex(p_values)
369
+ object_index = Index(o_values)
370
+
371
+ ser = Series(values, index=period_index)
372
+ result = ser.reindex(object_index)
373
+ expected = Series(expected_values, index=object_index)
374
+ tm.assert_series_equal(result, expected)
375
+
376
+
377
+ def test_reindex_too_many_args():
378
+ # GH 40980
379
+ ser = Series([1, 2])
380
+ msg = r"reindex\(\) takes from 1 to 2 positional arguments but 3 were given"
381
+ with pytest.raises(TypeError, match=msg):
382
+ ser.reindex([2, 3], False)
383
+
384
+
385
+ def test_reindex_double_index():
386
+ # GH 40980
387
+ ser = Series([1, 2])
388
+ msg = r"reindex\(\) got multiple values for argument 'index'"
389
+ with pytest.raises(TypeError, match=msg):
390
+ ser.reindex([2, 3], index=[3, 4])
391
+
392
+
393
+ def test_reindex_no_posargs():
394
+ # GH 40980
395
+ ser = Series([1, 2])
396
+ result = ser.reindex(index=[1, 0])
397
+ expected = Series([2, 1], index=[1, 0])
398
+ tm.assert_series_equal(result, expected)
399
+
400
+
401
+ @pytest.mark.parametrize("values", [[["a"], ["x"]], [[], []]])
402
+ def test_reindex_empty_with_level(values):
403
+ # GH41170
404
+ ser = Series(
405
+ range(len(values[0])), index=MultiIndex.from_arrays(values), dtype="object"
406
+ )
407
+ result = ser.reindex(np.array(["b"]), level=0)
408
+ expected = Series(
409
+ index=MultiIndex(levels=[["b"], values[1]], codes=[[], []]), dtype="object"
410
+ )
411
+ tm.assert_series_equal(result, expected)
412
+
413
+
414
+ def test_reindex_missing_category():
415
+ # GH#18185
416
+ ser = Series([1, 2, 3, 1], dtype="category")
417
+ msg = r"Cannot setitem on a Categorical with a new category \(-1\)"
418
+ with pytest.raises(TypeError, match=msg):
419
+ ser.reindex([1, 2, 3, 4, 5], fill_value=-1)
420
+
421
+
422
+ def test_reindexing_with_float64_NA_log():
423
+ # GH 47055
424
+ s = Series([1.0, NA], dtype=Float64Dtype())
425
+ s_reindex = s.reindex(range(3))
426
+ result = s_reindex.values._data
427
+ expected = np.array([1, np.nan, np.nan])
428
+ tm.assert_numpy_array_equal(result, expected)
429
+ with tm.assert_produces_warning(None):
430
+ result_log = np.log(s_reindex)
431
+ expected_log = Series([0, np.nan, np.nan], dtype=Float64Dtype())
432
+ tm.assert_series_equal(result_log, expected_log)
433
+
434
+
435
+ @pytest.mark.parametrize("dtype", ["timedelta64", "datetime64"])
436
+ def test_reindex_expand_nonnano_nat(dtype):
437
+ # GH 53497
438
+ ser = Series(np.array([1], dtype=f"{dtype}[s]"))
439
+ result = ser.reindex(RangeIndex(2))
440
+ expected = Series(
441
+ np.array([1, getattr(np, dtype)("nat", "s")], dtype=f"{dtype}[s]")
442
+ )
443
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_reindex_like.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ import numpy as np
4
+
5
+ from pandas import Series
6
+ import pandas._testing as tm
7
+
8
+
9
+ def test_reindex_like(datetime_series):
10
+ other = datetime_series[::2]
11
+ tm.assert_series_equal(
12
+ datetime_series.reindex(other.index), datetime_series.reindex_like(other)
13
+ )
14
+
15
+ # GH#7179
16
+ day1 = datetime(2013, 3, 5)
17
+ day2 = datetime(2013, 5, 5)
18
+ day3 = datetime(2014, 3, 5)
19
+
20
+ series1 = Series([5, None, None], [day1, day2, day3])
21
+ series2 = Series([None, None], [day1, day3])
22
+
23
+ result = series1.reindex_like(series2, method="pad")
24
+ expected = Series([5, np.nan], index=[day1, day3])
25
+ tm.assert_series_equal(result, expected)
26
+
27
+
28
+ def test_reindex_like_nearest():
29
+ ser = Series(np.arange(10, dtype="int64"))
30
+
31
+ target = [0.1, 0.9, 1.5, 2.0]
32
+ other = ser.reindex(target, method="nearest")
33
+ expected = Series(np.around(target).astype("int64"), target)
34
+
35
+ result = ser.reindex_like(other, method="nearest")
36
+ tm.assert_series_equal(expected, result)
37
+
38
+ result = ser.reindex_like(other, method="nearest", tolerance=1)
39
+ tm.assert_series_equal(expected, result)
40
+ result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4])
41
+ tm.assert_series_equal(expected, result)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_rename.py ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import re
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ from pandas import (
8
+ Index,
9
+ MultiIndex,
10
+ Series,
11
+ array,
12
+ )
13
+ import pandas._testing as tm
14
+
15
+
16
+ class TestRename:
17
+ def test_rename(self, datetime_series):
18
+ ts = datetime_series
19
+ renamer = lambda x: x.strftime("%Y%m%d")
20
+ renamed = ts.rename(renamer)
21
+ assert renamed.index[0] == renamer(ts.index[0])
22
+
23
+ # dict
24
+ rename_dict = dict(zip(ts.index, renamed.index))
25
+ renamed2 = ts.rename(rename_dict)
26
+ tm.assert_series_equal(renamed, renamed2)
27
+
28
+ def test_rename_partial_dict(self):
29
+ # partial dict
30
+ ser = Series(np.arange(4), index=["a", "b", "c", "d"], dtype="int64")
31
+ renamed = ser.rename({"b": "foo", "d": "bar"})
32
+ tm.assert_index_equal(renamed.index, Index(["a", "foo", "c", "bar"]))
33
+
34
+ def test_rename_retain_index_name(self):
35
+ # index with name
36
+ renamer = Series(
37
+ np.arange(4), index=Index(["a", "b", "c", "d"], name="name"), dtype="int64"
38
+ )
39
+ renamed = renamer.rename({})
40
+ assert renamed.index.name == renamer.index.name
41
+
42
+ def test_rename_by_series(self):
43
+ ser = Series(range(5), name="foo")
44
+ renamer = Series({1: 10, 2: 20})
45
+ result = ser.rename(renamer)
46
+ expected = Series(range(5), index=[0, 10, 20, 3, 4], name="foo")
47
+ tm.assert_series_equal(result, expected)
48
+
49
+ def test_rename_set_name(self, using_infer_string):
50
+ ser = Series(range(4), index=list("abcd"))
51
+ for name in ["foo", 123, 123.0, datetime(2001, 11, 11), ("foo",)]:
52
+ result = ser.rename(name)
53
+ assert result.name == name
54
+ if using_infer_string:
55
+ tm.assert_extension_array_equal(result.index.values, ser.index.values)
56
+ else:
57
+ tm.assert_numpy_array_equal(result.index.values, ser.index.values)
58
+ assert ser.name is None
59
+
60
+ def test_rename_set_name_inplace(self, using_infer_string):
61
+ ser = Series(range(3), index=list("abc"))
62
+ for name in ["foo", 123, 123.0, datetime(2001, 11, 11), ("foo",)]:
63
+ ser.rename(name, inplace=True)
64
+ assert ser.name == name
65
+ exp = np.array(["a", "b", "c"], dtype=np.object_)
66
+ if using_infer_string:
67
+ exp = array(exp, dtype="str")
68
+ tm.assert_extension_array_equal(ser.index.values, exp)
69
+ else:
70
+ tm.assert_numpy_array_equal(ser.index.values, exp)
71
+
72
+ def test_rename_axis_supported(self):
73
+ # Supporting axis for compatibility, detailed in GH-18589
74
+ ser = Series(range(5))
75
+ ser.rename({}, axis=0)
76
+ ser.rename({}, axis="index")
77
+
78
+ with pytest.raises(ValueError, match="No axis named 5"):
79
+ ser.rename({}, axis=5)
80
+
81
+ def test_rename_inplace(self, datetime_series):
82
+ renamer = lambda x: x.strftime("%Y%m%d")
83
+ expected = renamer(datetime_series.index[0])
84
+
85
+ datetime_series.rename(renamer, inplace=True)
86
+ assert datetime_series.index[0] == expected
87
+
88
+ def test_rename_with_custom_indexer(self):
89
+ # GH 27814
90
+ class MyIndexer:
91
+ pass
92
+
93
+ ix = MyIndexer()
94
+ ser = Series([1, 2, 3]).rename(ix)
95
+ assert ser.name is ix
96
+
97
+ def test_rename_with_custom_indexer_inplace(self):
98
+ # GH 27814
99
+ class MyIndexer:
100
+ pass
101
+
102
+ ix = MyIndexer()
103
+ ser = Series([1, 2, 3])
104
+ ser.rename(ix, inplace=True)
105
+ assert ser.name is ix
106
+
107
+ def test_rename_callable(self):
108
+ # GH 17407
109
+ ser = Series(range(1, 6), index=Index(range(2, 7), name="IntIndex"))
110
+ result = ser.rename(str)
111
+ expected = ser.rename(lambda i: str(i))
112
+ tm.assert_series_equal(result, expected)
113
+
114
+ assert result.name == expected.name
115
+
116
+ def test_rename_none(self):
117
+ # GH 40977
118
+ ser = Series([1, 2], name="foo")
119
+ result = ser.rename(None)
120
+ expected = Series([1, 2])
121
+ tm.assert_series_equal(result, expected)
122
+
123
+ def test_rename_series_with_multiindex(self):
124
+ # issue #43659
125
+ arrays = [
126
+ ["bar", "baz", "baz", "foo", "qux"],
127
+ ["one", "one", "two", "two", "one"],
128
+ ]
129
+
130
+ index = MultiIndex.from_arrays(arrays, names=["first", "second"])
131
+ ser = Series(np.ones(5), index=index)
132
+ result = ser.rename(index={"one": "yes"}, level="second", errors="raise")
133
+
134
+ arrays_expected = [
135
+ ["bar", "baz", "baz", "foo", "qux"],
136
+ ["yes", "yes", "two", "two", "yes"],
137
+ ]
138
+
139
+ index_expected = MultiIndex.from_arrays(
140
+ arrays_expected, names=["first", "second"]
141
+ )
142
+ series_expected = Series(np.ones(5), index=index_expected)
143
+
144
+ tm.assert_series_equal(result, series_expected)
145
+
146
+ def test_rename_series_with_multiindex_keeps_ea_dtypes(self):
147
+ # GH21055
148
+ arrays = [
149
+ Index([1, 2, 3], dtype="Int64").astype("category"),
150
+ Index([1, 2, 3], dtype="Int64"),
151
+ ]
152
+ mi = MultiIndex.from_arrays(arrays, names=["A", "B"])
153
+ ser = Series(1, index=mi)
154
+ result = ser.rename({1: 4}, level=1)
155
+
156
+ arrays_expected = [
157
+ Index([1, 2, 3], dtype="Int64").astype("category"),
158
+ Index([4, 2, 3], dtype="Int64"),
159
+ ]
160
+ mi_expected = MultiIndex.from_arrays(arrays_expected, names=["A", "B"])
161
+ expected = Series(1, index=mi_expected)
162
+
163
+ tm.assert_series_equal(result, expected)
164
+
165
+ def test_rename_error_arg(self):
166
+ # GH 46889
167
+ ser = Series(["foo", "bar"])
168
+ match = re.escape("[2] not found in axis")
169
+ with pytest.raises(KeyError, match=match):
170
+ ser.rename({2: 9}, errors="raise")
171
+
172
+ def test_rename_copy_false(self, using_copy_on_write, warn_copy_on_write):
173
+ # GH 46889
174
+ ser = Series(["foo", "bar"])
175
+ ser_orig = ser.copy()
176
+ shallow_copy = ser.rename({1: 9}, copy=False)
177
+ with tm.assert_cow_warning(warn_copy_on_write):
178
+ ser[0] = "foobar"
179
+ if using_copy_on_write:
180
+ assert ser_orig[0] == shallow_copy[0]
181
+ assert ser_orig[1] == shallow_copy[9]
182
+ else:
183
+ assert ser[0] == shallow_copy[0]
184
+ assert ser[1] == shallow_copy[9]
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_rename_axis.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import (
4
+ Index,
5
+ MultiIndex,
6
+ Series,
7
+ )
8
+ import pandas._testing as tm
9
+
10
+
11
+ class TestSeriesRenameAxis:
12
+ def test_rename_axis_mapper(self):
13
+ # GH 19978
14
+ mi = MultiIndex.from_product([["a", "b", "c"], [1, 2]], names=["ll", "nn"])
15
+ ser = Series(list(range(len(mi))), index=mi)
16
+
17
+ result = ser.rename_axis(index={"ll": "foo"})
18
+ assert result.index.names == ["foo", "nn"]
19
+
20
+ result = ser.rename_axis(index=str.upper, axis=0)
21
+ assert result.index.names == ["LL", "NN"]
22
+
23
+ result = ser.rename_axis(index=["foo", "goo"])
24
+ assert result.index.names == ["foo", "goo"]
25
+
26
+ with pytest.raises(TypeError, match="unexpected"):
27
+ ser.rename_axis(columns="wrong")
28
+
29
+ def test_rename_axis_inplace(self, datetime_series):
30
+ # GH 15704
31
+ expected = datetime_series.rename_axis("foo")
32
+ result = datetime_series
33
+ no_return = result.rename_axis("foo", inplace=True)
34
+
35
+ assert no_return is None
36
+ tm.assert_series_equal(result, expected)
37
+
38
+ @pytest.mark.parametrize("kwargs", [{"mapper": None}, {"index": None}, {}])
39
+ def test_rename_axis_none(self, kwargs):
40
+ # GH 25034
41
+ index = Index(list("abc"), name="foo")
42
+ ser = Series([1, 2, 3], index=index)
43
+
44
+ result = ser.rename_axis(**kwargs)
45
+ expected_index = index.rename(None) if kwargs else index
46
+ expected = Series([1, 2, 3], index=expected_index)
47
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_repeat.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ MultiIndex,
6
+ Series,
7
+ )
8
+ import pandas._testing as tm
9
+
10
+
11
+ class TestRepeat:
12
+ def test_repeat(self):
13
+ ser = Series(np.random.default_rng(2).standard_normal(3), index=["a", "b", "c"])
14
+
15
+ reps = ser.repeat(5)
16
+ exp = Series(ser.values.repeat(5), index=ser.index.values.repeat(5))
17
+ tm.assert_series_equal(reps, exp)
18
+
19
+ to_rep = [2, 3, 4]
20
+ reps = ser.repeat(to_rep)
21
+ exp = Series(ser.values.repeat(to_rep), index=ser.index.values.repeat(to_rep))
22
+ tm.assert_series_equal(reps, exp)
23
+
24
+ def test_numpy_repeat(self):
25
+ ser = Series(np.arange(3), name="x")
26
+ expected = Series(
27
+ ser.values.repeat(2), name="x", index=ser.index.values.repeat(2)
28
+ )
29
+ tm.assert_series_equal(np.repeat(ser, 2), expected)
30
+
31
+ msg = "the 'axis' parameter is not supported"
32
+ with pytest.raises(ValueError, match=msg):
33
+ np.repeat(ser, 2, axis=0)
34
+
35
+ def test_repeat_with_multiindex(self):
36
+ # GH#9361, fixed by GH#7891
37
+ m_idx = MultiIndex.from_tuples([(1, 2), (3, 4), (5, 6), (7, 8)])
38
+ data = ["a", "b", "c", "d"]
39
+ m_df = Series(data, index=m_idx)
40
+ assert m_df.repeat(3).shape == (3 * len(data),)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_replace.py ADDED
@@ -0,0 +1,819 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ import pandas as pd
7
+ import pandas._testing as tm
8
+ from pandas.core.arrays import IntervalArray
9
+
10
+
11
+ class TestSeriesReplace:
12
+ def test_replace_explicit_none(self):
13
+ # GH#36984 if the user explicitly passes value=None, give it to them
14
+ ser = pd.Series([0, 0, ""], dtype=object)
15
+ result = ser.replace("", None)
16
+ expected = pd.Series([0, 0, None], dtype=object)
17
+ tm.assert_series_equal(result, expected)
18
+
19
+ # Cast column 2 to object to avoid implicit cast when setting entry to ""
20
+ df = pd.DataFrame(np.zeros((3, 3))).astype({2: object})
21
+ df.iloc[2, 2] = ""
22
+ result = df.replace("", None)
23
+ expected = pd.DataFrame(
24
+ {
25
+ 0: np.zeros(3),
26
+ 1: np.zeros(3),
27
+ 2: np.array([0.0, 0.0, None], dtype=object),
28
+ }
29
+ )
30
+ assert expected.iloc[2, 2] is None
31
+ tm.assert_frame_equal(result, expected)
32
+
33
+ # GH#19998 same thing with object dtype
34
+ ser = pd.Series([10, 20, 30, "a", "a", "b", "a"])
35
+ result = ser.replace("a", None)
36
+ expected = pd.Series([10, 20, 30, None, None, "b", None])
37
+ assert expected.iloc[-1] is None
38
+ tm.assert_series_equal(result, expected)
39
+
40
+ def test_replace_noop_doesnt_downcast(self):
41
+ # GH#44498
42
+ ser = pd.Series([None, None, pd.Timestamp("2021-12-16 17:31")], dtype=object)
43
+ res = ser.replace({np.nan: None}) # should be a no-op
44
+ tm.assert_series_equal(res, ser)
45
+ assert res.dtype == object
46
+
47
+ # same thing but different calling convention
48
+ res = ser.replace(np.nan, None)
49
+ tm.assert_series_equal(res, ser)
50
+ assert res.dtype == object
51
+
52
+ def test_replace(self):
53
+ N = 50
54
+ ser = pd.Series(np.random.default_rng(2).standard_normal(N))
55
+ ser[0:4] = np.nan
56
+ ser[6:10] = 0
57
+
58
+ # replace list with a single value
59
+ return_value = ser.replace([np.nan], -1, inplace=True)
60
+ assert return_value is None
61
+
62
+ exp = ser.fillna(-1)
63
+ tm.assert_series_equal(ser, exp)
64
+
65
+ rs = ser.replace(0.0, np.nan)
66
+ ser[ser == 0.0] = np.nan
67
+ tm.assert_series_equal(rs, ser)
68
+
69
+ ser = pd.Series(
70
+ np.fabs(np.random.default_rng(2).standard_normal(N)),
71
+ pd.date_range("2020-01-01", periods=N),
72
+ dtype=object,
73
+ )
74
+ ser[:5] = np.nan
75
+ ser[6:10] = "foo"
76
+ ser[20:30] = "bar"
77
+
78
+ # replace list with a single value
79
+ msg = "Downcasting behavior in `replace`"
80
+ with tm.assert_produces_warning(FutureWarning, match=msg):
81
+ rs = ser.replace([np.nan, "foo", "bar"], -1)
82
+
83
+ assert (rs[:5] == -1).all()
84
+ assert (rs[6:10] == -1).all()
85
+ assert (rs[20:30] == -1).all()
86
+ assert (pd.isna(ser[:5])).all()
87
+
88
+ # replace with different values
89
+ with tm.assert_produces_warning(FutureWarning, match=msg):
90
+ rs = ser.replace({np.nan: -1, "foo": -2, "bar": -3})
91
+
92
+ assert (rs[:5] == -1).all()
93
+ assert (rs[6:10] == -2).all()
94
+ assert (rs[20:30] == -3).all()
95
+ assert (pd.isna(ser[:5])).all()
96
+
97
+ # replace with different values with 2 lists
98
+ with tm.assert_produces_warning(FutureWarning, match=msg):
99
+ rs2 = ser.replace([np.nan, "foo", "bar"], [-1, -2, -3])
100
+ tm.assert_series_equal(rs, rs2)
101
+
102
+ # replace inplace
103
+ with tm.assert_produces_warning(FutureWarning, match=msg):
104
+ return_value = ser.replace([np.nan, "foo", "bar"], -1, inplace=True)
105
+ assert return_value is None
106
+
107
+ assert (ser[:5] == -1).all()
108
+ assert (ser[6:10] == -1).all()
109
+ assert (ser[20:30] == -1).all()
110
+
111
+ def test_replace_nan_with_inf(self):
112
+ ser = pd.Series([np.nan, 0, np.inf])
113
+ tm.assert_series_equal(ser.replace(np.nan, 0), ser.fillna(0))
114
+
115
+ ser = pd.Series([np.nan, 0, "foo", "bar", np.inf, None, pd.NaT])
116
+ tm.assert_series_equal(ser.replace(np.nan, 0), ser.fillna(0))
117
+ filled = ser.copy()
118
+ filled[4] = 0
119
+ tm.assert_series_equal(ser.replace(np.inf, 0), filled)
120
+
121
+ def test_replace_listlike_value_listlike_target(self, datetime_series):
122
+ ser = pd.Series(datetime_series.index)
123
+ tm.assert_series_equal(ser.replace(np.nan, 0), ser.fillna(0))
124
+
125
+ # malformed
126
+ msg = r"Replacement lists must match in length\. Expecting 3 got 2"
127
+ with pytest.raises(ValueError, match=msg):
128
+ ser.replace([1, 2, 3], [np.nan, 0])
129
+
130
+ # ser is dt64 so can't hold 1 or 2, so this replace is a no-op
131
+ result = ser.replace([1, 2], [np.nan, 0])
132
+ tm.assert_series_equal(result, ser)
133
+
134
+ ser = pd.Series([0, 1, 2, 3, 4])
135
+ result = ser.replace([0, 1, 2, 3, 4], [4, 3, 2, 1, 0])
136
+ tm.assert_series_equal(result, pd.Series([4, 3, 2, 1, 0]))
137
+
138
+ def test_replace_gh5319(self):
139
+ # API change from 0.12?
140
+ # GH 5319
141
+ ser = pd.Series([0, np.nan, 2, 3, 4])
142
+ expected = ser.ffill()
143
+ msg = (
144
+ "Series.replace without 'value' and with non-dict-like "
145
+ "'to_replace' is deprecated"
146
+ )
147
+ with tm.assert_produces_warning(FutureWarning, match=msg):
148
+ result = ser.replace([np.nan])
149
+ tm.assert_series_equal(result, expected)
150
+
151
+ ser = pd.Series([0, np.nan, 2, 3, 4])
152
+ expected = ser.ffill()
153
+ with tm.assert_produces_warning(FutureWarning, match=msg):
154
+ result = ser.replace(np.nan)
155
+ tm.assert_series_equal(result, expected)
156
+
157
+ def test_replace_datetime64(self):
158
+ # GH 5797
159
+ ser = pd.Series(pd.date_range("20130101", periods=5))
160
+ expected = ser.copy()
161
+ expected.loc[2] = pd.Timestamp("20120101")
162
+ result = ser.replace({pd.Timestamp("20130103"): pd.Timestamp("20120101")})
163
+ tm.assert_series_equal(result, expected)
164
+ result = ser.replace(pd.Timestamp("20130103"), pd.Timestamp("20120101"))
165
+ tm.assert_series_equal(result, expected)
166
+
167
+ def test_replace_nat_with_tz(self):
168
+ # GH 11792: Test with replacing NaT in a list with tz data
169
+ ts = pd.Timestamp("2015/01/01", tz="UTC")
170
+ s = pd.Series([pd.NaT, pd.Timestamp("2015/01/01", tz="UTC")])
171
+ result = s.replace([np.nan, pd.NaT], pd.Timestamp.min)
172
+ expected = pd.Series([pd.Timestamp.min, ts], dtype=object)
173
+ tm.assert_series_equal(expected, result)
174
+
175
+ def test_replace_timedelta_td64(self):
176
+ tdi = pd.timedelta_range(0, periods=5)
177
+ ser = pd.Series(tdi)
178
+
179
+ # Using a single dict argument means we go through replace_list
180
+ result = ser.replace({ser[1]: ser[3]})
181
+
182
+ expected = pd.Series([ser[0], ser[3], ser[2], ser[3], ser[4]])
183
+ tm.assert_series_equal(result, expected)
184
+
185
+ def test_replace_with_single_list(self):
186
+ ser = pd.Series([0, 1, 2, 3, 4])
187
+ msg2 = (
188
+ "Series.replace without 'value' and with non-dict-like "
189
+ "'to_replace' is deprecated"
190
+ )
191
+ with tm.assert_produces_warning(FutureWarning, match=msg2):
192
+ result = ser.replace([1, 2, 3])
193
+ tm.assert_series_equal(result, pd.Series([0, 0, 0, 0, 4]))
194
+
195
+ s = ser.copy()
196
+ with tm.assert_produces_warning(FutureWarning, match=msg2):
197
+ return_value = s.replace([1, 2, 3], inplace=True)
198
+ assert return_value is None
199
+ tm.assert_series_equal(s, pd.Series([0, 0, 0, 0, 4]))
200
+
201
+ # make sure things don't get corrupted when fillna call fails
202
+ s = ser.copy()
203
+ msg = (
204
+ r"Invalid fill method\. Expecting pad \(ffill\) or backfill "
205
+ r"\(bfill\)\. Got crash_cymbal"
206
+ )
207
+ msg3 = "The 'method' keyword in Series.replace is deprecated"
208
+ with pytest.raises(ValueError, match=msg):
209
+ with tm.assert_produces_warning(FutureWarning, match=msg3):
210
+ return_value = s.replace([1, 2, 3], inplace=True, method="crash_cymbal")
211
+ assert return_value is None
212
+ tm.assert_series_equal(s, ser)
213
+
214
+ def test_replace_mixed_types(self):
215
+ ser = pd.Series(np.arange(5), dtype="int64")
216
+
217
+ def check_replace(to_rep, val, expected):
218
+ sc = ser.copy()
219
+ result = ser.replace(to_rep, val)
220
+ return_value = sc.replace(to_rep, val, inplace=True)
221
+ assert return_value is None
222
+ tm.assert_series_equal(expected, result)
223
+ tm.assert_series_equal(expected, sc)
224
+
225
+ # 3.0 can still be held in our int64 series, so we do not upcast GH#44940
226
+ tr, v = [3], [3.0]
227
+ check_replace(tr, v, ser)
228
+ # Note this matches what we get with the scalars 3 and 3.0
229
+ check_replace(tr[0], v[0], ser)
230
+
231
+ # MUST upcast to float
232
+ e = pd.Series([0, 1, 2, 3.5, 4])
233
+ tr, v = [3], [3.5]
234
+ check_replace(tr, v, e)
235
+
236
+ # casts to object
237
+ e = pd.Series([0, 1, 2, 3.5, "a"])
238
+ tr, v = [3, 4], [3.5, "a"]
239
+ check_replace(tr, v, e)
240
+
241
+ # again casts to object
242
+ e = pd.Series([0, 1, 2, 3.5, pd.Timestamp("20130101")])
243
+ tr, v = [3, 4], [3.5, pd.Timestamp("20130101")]
244
+ check_replace(tr, v, e)
245
+
246
+ # casts to object
247
+ e = pd.Series([0, 1, 2, 3.5, True], dtype="object")
248
+ tr, v = [3, 4], [3.5, True]
249
+ check_replace(tr, v, e)
250
+
251
+ # test an object with dates + floats + integers + strings
252
+ dr = pd.Series(pd.date_range("1/1/2001", "1/10/2001", freq="D"))
253
+ result = dr.astype(object).replace([dr[0], dr[1], dr[2]], [1.0, 2, "a"])
254
+ expected = pd.Series([1.0, 2, "a"] + dr[3:].tolist(), dtype=object)
255
+ tm.assert_series_equal(result, expected)
256
+
257
+ def test_replace_bool_with_string_no_op(self):
258
+ s = pd.Series([True, False, True])
259
+ result = s.replace("fun", "in-the-sun")
260
+ tm.assert_series_equal(s, result)
261
+
262
+ def test_replace_bool_with_string(self):
263
+ # nonexistent elements
264
+ s = pd.Series([True, False, True])
265
+ result = s.replace(True, "2u")
266
+ expected = pd.Series(["2u", False, "2u"])
267
+ tm.assert_series_equal(expected, result)
268
+
269
+ def test_replace_bool_with_bool(self):
270
+ s = pd.Series([True, False, True])
271
+ result = s.replace(True, False)
272
+ expected = pd.Series([False] * len(s))
273
+ tm.assert_series_equal(expected, result)
274
+
275
+ def test_replace_with_dict_with_bool_keys(self):
276
+ s = pd.Series([True, False, True])
277
+ result = s.replace({"asdf": "asdb", True: "yes"})
278
+ expected = pd.Series(["yes", False, "yes"])
279
+ tm.assert_series_equal(result, expected)
280
+
281
+ def test_replace_Int_with_na(self, any_int_ea_dtype):
282
+ # GH 38267
283
+ result = pd.Series([0, None], dtype=any_int_ea_dtype).replace(0, pd.NA)
284
+ expected = pd.Series([pd.NA, pd.NA], dtype=any_int_ea_dtype)
285
+ tm.assert_series_equal(result, expected)
286
+ result = pd.Series([0, 1], dtype=any_int_ea_dtype).replace(0, pd.NA)
287
+ result.replace(1, pd.NA, inplace=True)
288
+ tm.assert_series_equal(result, expected)
289
+
290
+ def test_replace2(self):
291
+ N = 50
292
+ ser = pd.Series(
293
+ np.fabs(np.random.default_rng(2).standard_normal(N)),
294
+ pd.date_range("2020-01-01", periods=N),
295
+ dtype=object,
296
+ )
297
+ ser[:5] = np.nan
298
+ ser[6:10] = "foo"
299
+ ser[20:30] = "bar"
300
+
301
+ # replace list with a single value
302
+ msg = "Downcasting behavior in `replace`"
303
+ with tm.assert_produces_warning(FutureWarning, match=msg):
304
+ rs = ser.replace([np.nan, "foo", "bar"], -1)
305
+
306
+ assert (rs[:5] == -1).all()
307
+ assert (rs[6:10] == -1).all()
308
+ assert (rs[20:30] == -1).all()
309
+ assert (pd.isna(ser[:5])).all()
310
+
311
+ # replace with different values
312
+ with tm.assert_produces_warning(FutureWarning, match=msg):
313
+ rs = ser.replace({np.nan: -1, "foo": -2, "bar": -3})
314
+
315
+ assert (rs[:5] == -1).all()
316
+ assert (rs[6:10] == -2).all()
317
+ assert (rs[20:30] == -3).all()
318
+ assert (pd.isna(ser[:5])).all()
319
+
320
+ # replace with different values with 2 lists
321
+ with tm.assert_produces_warning(FutureWarning, match=msg):
322
+ rs2 = ser.replace([np.nan, "foo", "bar"], [-1, -2, -3])
323
+ tm.assert_series_equal(rs, rs2)
324
+
325
+ # replace inplace
326
+ with tm.assert_produces_warning(FutureWarning, match=msg):
327
+ return_value = ser.replace([np.nan, "foo", "bar"], -1, inplace=True)
328
+ assert return_value is None
329
+ assert (ser[:5] == -1).all()
330
+ assert (ser[6:10] == -1).all()
331
+ assert (ser[20:30] == -1).all()
332
+
333
+ @pytest.mark.parametrize("inplace", [True, False])
334
+ def test_replace_cascade(self, inplace):
335
+ # Test that replaced values are not replaced again
336
+ # GH #50778
337
+ ser = pd.Series([1, 2, 3])
338
+ expected = pd.Series([2, 3, 4])
339
+
340
+ res = ser.replace([1, 2, 3], [2, 3, 4], inplace=inplace)
341
+ if inplace:
342
+ tm.assert_series_equal(ser, expected)
343
+ else:
344
+ tm.assert_series_equal(res, expected)
345
+
346
+ def test_replace_with_dictlike_and_string_dtype(self, nullable_string_dtype):
347
+ # GH 32621, GH#44940
348
+ ser = pd.Series(["one", "two", np.nan], dtype=nullable_string_dtype)
349
+ expected = pd.Series(["1", "2", np.nan], dtype=nullable_string_dtype)
350
+ result = ser.replace({"one": "1", "two": "2"})
351
+ tm.assert_series_equal(expected, result)
352
+
353
+ def test_replace_with_empty_dictlike(self):
354
+ # GH 15289
355
+ s = pd.Series(list("abcd"))
356
+ tm.assert_series_equal(s, s.replace({}))
357
+
358
+ empty_series = pd.Series([])
359
+ tm.assert_series_equal(s, s.replace(empty_series))
360
+
361
+ def test_replace_string_with_number(self):
362
+ # GH 15743
363
+ s = pd.Series([1, 2, 3])
364
+ result = s.replace("2", np.nan)
365
+ expected = pd.Series([1, 2, 3])
366
+ tm.assert_series_equal(expected, result)
367
+
368
+ def test_replace_replacer_equals_replacement(self):
369
+ # GH 20656
370
+ # make sure all replacers are matching against original values
371
+ s = pd.Series(["a", "b"])
372
+ expected = pd.Series(["b", "a"])
373
+ result = s.replace({"a": "b", "b": "a"})
374
+ tm.assert_series_equal(expected, result)
375
+
376
+ def test_replace_unicode_with_number(self):
377
+ # GH 15743
378
+ s = pd.Series([1, 2, 3])
379
+ result = s.replace("2", np.nan)
380
+ expected = pd.Series([1, 2, 3])
381
+ tm.assert_series_equal(expected, result)
382
+
383
+ def test_replace_mixed_types_with_string(self):
384
+ # Testing mixed
385
+ s = pd.Series([1, 2, 3, "4", 4, 5])
386
+ msg = "Downcasting behavior in `replace`"
387
+ with tm.assert_produces_warning(FutureWarning, match=msg):
388
+ result = s.replace([2, "4"], np.nan)
389
+ expected = pd.Series([1, np.nan, 3, np.nan, 4, 5])
390
+ tm.assert_series_equal(expected, result)
391
+
392
+ @pytest.mark.parametrize(
393
+ "categorical, numeric",
394
+ [
395
+ (pd.Categorical(["A"], categories=["A", "B"]), [1]),
396
+ (pd.Categorical(["A", "B"], categories=["A", "B"]), [1, 2]),
397
+ ],
398
+ )
399
+ def test_replace_categorical(self, categorical, numeric, using_infer_string):
400
+ # GH 24971, GH#23305
401
+ ser = pd.Series(categorical)
402
+ msg = "Downcasting behavior in `replace`"
403
+ msg = "with CategoricalDtype is deprecated"
404
+ with tm.assert_produces_warning(FutureWarning, match=msg):
405
+ result = ser.replace({"A": 1, "B": 2})
406
+ expected = pd.Series(numeric).astype("category")
407
+ if 2 not in expected.cat.categories:
408
+ # i.e. categories should be [1, 2] even if there are no "B"s present
409
+ # GH#44940
410
+ expected = expected.cat.add_categories(2)
411
+ tm.assert_series_equal(expected, result)
412
+
413
+ @pytest.mark.parametrize(
414
+ "data, data_exp", [(["a", "b", "c"], ["b", "b", "c"]), (["a"], ["b"])]
415
+ )
416
+ def test_replace_categorical_inplace(self, data, data_exp):
417
+ # GH 53358
418
+ result = pd.Series(data, dtype="category")
419
+ msg = "with CategoricalDtype is deprecated"
420
+ with tm.assert_produces_warning(FutureWarning, match=msg):
421
+ result.replace(to_replace="a", value="b", inplace=True)
422
+ expected = pd.Series(data_exp, dtype="category")
423
+ tm.assert_series_equal(result, expected)
424
+
425
+ def test_replace_categorical_single(self):
426
+ # GH 26988
427
+ dti = pd.date_range("2016-01-01", periods=3, tz="US/Pacific")
428
+ s = pd.Series(dti)
429
+ c = s.astype("category")
430
+
431
+ expected = c.copy()
432
+ expected = expected.cat.add_categories("foo")
433
+ expected[2] = "foo"
434
+ expected = expected.cat.remove_unused_categories()
435
+ assert c[2] != "foo"
436
+
437
+ msg = "with CategoricalDtype is deprecated"
438
+ with tm.assert_produces_warning(FutureWarning, match=msg):
439
+ result = c.replace(c[2], "foo")
440
+ tm.assert_series_equal(expected, result)
441
+ assert c[2] != "foo" # ensure non-inplace call does not alter original
442
+
443
+ msg = "with CategoricalDtype is deprecated"
444
+ with tm.assert_produces_warning(FutureWarning, match=msg):
445
+ return_value = c.replace(c[2], "foo", inplace=True)
446
+ assert return_value is None
447
+ tm.assert_series_equal(expected, c)
448
+
449
+ first_value = c[0]
450
+ msg = "with CategoricalDtype is deprecated"
451
+ with tm.assert_produces_warning(FutureWarning, match=msg):
452
+ return_value = c.replace(c[1], c[0], inplace=True)
453
+ assert return_value is None
454
+ assert c[0] == c[1] == first_value # test replacing with existing value
455
+
456
+ def test_replace_with_no_overflowerror(self):
457
+ # GH 25616
458
+ # casts to object without Exception from OverflowError
459
+ s = pd.Series([0, 1, 2, 3, 4])
460
+ result = s.replace([3], ["100000000000000000000"])
461
+ expected = pd.Series([0, 1, 2, "100000000000000000000", 4])
462
+ tm.assert_series_equal(result, expected)
463
+
464
+ s = pd.Series([0, "100000000000000000000", "100000000000000000001"])
465
+ result = s.replace(["100000000000000000000"], [1])
466
+ expected = pd.Series([0, 1, "100000000000000000001"])
467
+ tm.assert_series_equal(result, expected)
468
+
469
+ @pytest.mark.parametrize(
470
+ "ser, to_replace, exp",
471
+ [
472
+ ([1, 2, 3], {1: 2, 2: 3, 3: 4}, [2, 3, 4]),
473
+ (["1", "2", "3"], {"1": "2", "2": "3", "3": "4"}, ["2", "3", "4"]),
474
+ ],
475
+ )
476
+ def test_replace_commutative(self, ser, to_replace, exp):
477
+ # GH 16051
478
+ # DataFrame.replace() overwrites when values are non-numeric
479
+
480
+ series = pd.Series(ser)
481
+
482
+ expected = pd.Series(exp)
483
+ result = series.replace(to_replace)
484
+
485
+ tm.assert_series_equal(result, expected)
486
+
487
+ @pytest.mark.parametrize(
488
+ "ser, exp", [([1, 2, 3], [1, True, 3]), (["x", 2, 3], ["x", True, 3])]
489
+ )
490
+ def test_replace_no_cast(self, ser, exp):
491
+ # GH 9113
492
+ # BUG: replace int64 dtype with bool coerces to int64
493
+
494
+ series = pd.Series(ser)
495
+ result = series.replace(2, True)
496
+ expected = pd.Series(exp)
497
+
498
+ tm.assert_series_equal(result, expected)
499
+
500
+ def test_replace_invalid_to_replace(self):
501
+ # GH 18634
502
+ # API: replace() should raise an exception if invalid argument is given
503
+ series = pd.Series(["a", "b", "c "])
504
+ msg = (
505
+ r"Expecting 'to_replace' to be either a scalar, array-like, "
506
+ r"dict or None, got invalid type.*"
507
+ )
508
+ msg2 = (
509
+ "Series.replace without 'value' and with non-dict-like "
510
+ "'to_replace' is deprecated"
511
+ )
512
+ with pytest.raises(TypeError, match=msg):
513
+ with tm.assert_produces_warning(FutureWarning, match=msg2):
514
+ series.replace(lambda x: x.strip())
515
+
516
+ @pytest.mark.parametrize("frame", [False, True])
517
+ def test_replace_nonbool_regex(self, frame):
518
+ obj = pd.Series(["a", "b", "c "])
519
+ if frame:
520
+ obj = obj.to_frame()
521
+
522
+ msg = "'to_replace' must be 'None' if 'regex' is not a bool"
523
+ with pytest.raises(ValueError, match=msg):
524
+ obj.replace(to_replace=["a"], regex="foo")
525
+
526
+ @pytest.mark.parametrize("frame", [False, True])
527
+ def test_replace_empty_copy(self, frame):
528
+ obj = pd.Series([], dtype=np.float64)
529
+ if frame:
530
+ obj = obj.to_frame()
531
+
532
+ res = obj.replace(4, 5, inplace=True)
533
+ assert res is None
534
+
535
+ res = obj.replace(4, 5, inplace=False)
536
+ tm.assert_equal(res, obj)
537
+ assert res is not obj
538
+
539
+ def test_replace_only_one_dictlike_arg(self, fixed_now_ts):
540
+ # GH#33340
541
+
542
+ ser = pd.Series([1, 2, "A", fixed_now_ts, True])
543
+ to_replace = {0: 1, 2: "A"}
544
+ value = "foo"
545
+ msg = "Series.replace cannot use dict-like to_replace and non-None value"
546
+ with pytest.raises(ValueError, match=msg):
547
+ ser.replace(to_replace, value)
548
+
549
+ to_replace = 1
550
+ value = {0: "foo", 2: "bar"}
551
+ msg = "Series.replace cannot use dict-value and non-None to_replace"
552
+ with pytest.raises(ValueError, match=msg):
553
+ ser.replace(to_replace, value)
554
+
555
+ def test_replace_extension_other(self, frame_or_series):
556
+ # https://github.com/pandas-dev/pandas/issues/34530
557
+ obj = frame_or_series(pd.array([1, 2, 3], dtype="Int64"))
558
+ result = obj.replace("", "") # no exception
559
+ # should not have changed dtype
560
+ tm.assert_equal(obj, result)
561
+
562
+ def _check_replace_with_method(self, ser: pd.Series):
563
+ df = ser.to_frame()
564
+
565
+ msg1 = "The 'method' keyword in Series.replace is deprecated"
566
+ with tm.assert_produces_warning(FutureWarning, match=msg1):
567
+ res = ser.replace(ser[1], method="pad")
568
+ expected = pd.Series([ser[0], ser[0]] + list(ser[2:]), dtype=ser.dtype)
569
+ tm.assert_series_equal(res, expected)
570
+
571
+ msg2 = "The 'method' keyword in DataFrame.replace is deprecated"
572
+ with tm.assert_produces_warning(FutureWarning, match=msg2):
573
+ res_df = df.replace(ser[1], method="pad")
574
+ tm.assert_frame_equal(res_df, expected.to_frame())
575
+
576
+ ser2 = ser.copy()
577
+ with tm.assert_produces_warning(FutureWarning, match=msg1):
578
+ res2 = ser2.replace(ser[1], method="pad", inplace=True)
579
+ assert res2 is None
580
+ tm.assert_series_equal(ser2, expected)
581
+
582
+ with tm.assert_produces_warning(FutureWarning, match=msg2):
583
+ res_df2 = df.replace(ser[1], method="pad", inplace=True)
584
+ assert res_df2 is None
585
+ tm.assert_frame_equal(df, expected.to_frame())
586
+
587
+ def test_replace_ea_dtype_with_method(self, any_numeric_ea_dtype):
588
+ arr = pd.array([1, 2, pd.NA, 4], dtype=any_numeric_ea_dtype)
589
+ ser = pd.Series(arr)
590
+
591
+ self._check_replace_with_method(ser)
592
+
593
+ @pytest.mark.parametrize("as_categorical", [True, False])
594
+ def test_replace_interval_with_method(self, as_categorical):
595
+ # in particular interval that can't hold NA
596
+
597
+ idx = pd.IntervalIndex.from_breaks(range(4))
598
+ ser = pd.Series(idx)
599
+ if as_categorical:
600
+ ser = ser.astype("category")
601
+
602
+ self._check_replace_with_method(ser)
603
+
604
+ @pytest.mark.parametrize("as_period", [True, False])
605
+ @pytest.mark.parametrize("as_categorical", [True, False])
606
+ def test_replace_datetimelike_with_method(self, as_period, as_categorical):
607
+ idx = pd.date_range("2016-01-01", periods=5, tz="US/Pacific")
608
+ if as_period:
609
+ idx = idx.tz_localize(None).to_period("D")
610
+
611
+ ser = pd.Series(idx)
612
+ ser.iloc[-2] = pd.NaT
613
+ if as_categorical:
614
+ ser = ser.astype("category")
615
+
616
+ self._check_replace_with_method(ser)
617
+
618
+ def test_replace_with_compiled_regex(self):
619
+ # https://github.com/pandas-dev/pandas/issues/35680
620
+ s = pd.Series(["a", "b", "c"])
621
+ regex = re.compile("^a$")
622
+ result = s.replace({regex: "z"}, regex=True)
623
+ expected = pd.Series(["z", "b", "c"])
624
+ tm.assert_series_equal(result, expected)
625
+
626
+ def test_pandas_replace_na(self):
627
+ # GH#43344
628
+ # GH#56599
629
+ ser = pd.Series(["AA", "BB", "CC", "DD", "EE", "", pd.NA, "AA"], dtype="string")
630
+ regex_mapping = {
631
+ "AA": "CC",
632
+ "BB": "CC",
633
+ "EE": "CC",
634
+ "CC": "CC-REPL",
635
+ }
636
+ result = ser.replace(regex_mapping, regex=True)
637
+ exp = pd.Series(
638
+ ["CC", "CC", "CC-REPL", "DD", "CC", "", pd.NA, "CC"], dtype="string"
639
+ )
640
+ tm.assert_series_equal(result, exp)
641
+
642
+ @pytest.mark.parametrize(
643
+ "dtype, input_data, to_replace, expected_data",
644
+ [
645
+ ("bool", [True, False], {True: False}, [False, False]),
646
+ ("int64", [1, 2], {1: 10, 2: 20}, [10, 20]),
647
+ ("Int64", [1, 2], {1: 10, 2: 20}, [10, 20]),
648
+ ("float64", [1.1, 2.2], {1.1: 10.1, 2.2: 20.5}, [10.1, 20.5]),
649
+ ("Float64", [1.1, 2.2], {1.1: 10.1, 2.2: 20.5}, [10.1, 20.5]),
650
+ ("string", ["one", "two"], {"one": "1", "two": "2"}, ["1", "2"]),
651
+ (
652
+ pd.IntervalDtype("int64"),
653
+ IntervalArray([pd.Interval(1, 2), pd.Interval(2, 3)]),
654
+ {pd.Interval(1, 2): pd.Interval(10, 20)},
655
+ IntervalArray([pd.Interval(10, 20), pd.Interval(2, 3)]),
656
+ ),
657
+ (
658
+ pd.IntervalDtype("float64"),
659
+ IntervalArray([pd.Interval(1.0, 2.7), pd.Interval(2.8, 3.1)]),
660
+ {pd.Interval(1.0, 2.7): pd.Interval(10.6, 20.8)},
661
+ IntervalArray([pd.Interval(10.6, 20.8), pd.Interval(2.8, 3.1)]),
662
+ ),
663
+ (
664
+ pd.PeriodDtype("M"),
665
+ [pd.Period("2020-05", freq="M")],
666
+ {pd.Period("2020-05", freq="M"): pd.Period("2020-06", freq="M")},
667
+ [pd.Period("2020-06", freq="M")],
668
+ ),
669
+ ],
670
+ )
671
+ def test_replace_dtype(self, dtype, input_data, to_replace, expected_data):
672
+ # GH#33484
673
+ ser = pd.Series(input_data, dtype=dtype)
674
+ result = ser.replace(to_replace)
675
+ expected = pd.Series(expected_data, dtype=dtype)
676
+ tm.assert_series_equal(result, expected)
677
+
678
+ def test_replace_string_dtype(self):
679
+ # GH#40732, GH#44940
680
+ ser = pd.Series(["one", "two", np.nan], dtype="string")
681
+ res = ser.replace({"one": "1", "two": "2"})
682
+ expected = pd.Series(["1", "2", np.nan], dtype="string")
683
+ tm.assert_series_equal(res, expected)
684
+
685
+ # GH#31644
686
+ ser2 = pd.Series(["A", np.nan], dtype="string")
687
+ res2 = ser2.replace("A", "B")
688
+ expected2 = pd.Series(["B", np.nan], dtype="string")
689
+ tm.assert_series_equal(res2, expected2)
690
+
691
+ ser3 = pd.Series(["A", "B"], dtype="string")
692
+ res3 = ser3.replace("A", pd.NA)
693
+ expected3 = pd.Series([pd.NA, "B"], dtype="string")
694
+ tm.assert_series_equal(res3, expected3)
695
+
696
+ def test_replace_string_dtype_list_to_replace(self):
697
+ # GH#41215, GH#44940
698
+ ser = pd.Series(["abc", "def"], dtype="string")
699
+ res = ser.replace(["abc", "any other string"], "xyz")
700
+ expected = pd.Series(["xyz", "def"], dtype="string")
701
+ tm.assert_series_equal(res, expected)
702
+
703
+ def test_replace_string_dtype_regex(self):
704
+ # GH#31644
705
+ ser = pd.Series(["A", "B"], dtype="string")
706
+ res = ser.replace(r".", "C", regex=True)
707
+ expected = pd.Series(["C", "C"], dtype="string")
708
+ tm.assert_series_equal(res, expected)
709
+
710
+ def test_replace_nullable_numeric(self):
711
+ # GH#40732, GH#44940
712
+
713
+ floats = pd.Series([1.0, 2.0, 3.999, 4.4], dtype=pd.Float64Dtype())
714
+ assert floats.replace({1.0: 9}).dtype == floats.dtype
715
+ assert floats.replace(1.0, 9).dtype == floats.dtype
716
+ assert floats.replace({1.0: 9.0}).dtype == floats.dtype
717
+ assert floats.replace(1.0, 9.0).dtype == floats.dtype
718
+
719
+ res = floats.replace(to_replace=[1.0, 2.0], value=[9.0, 10.0])
720
+ assert res.dtype == floats.dtype
721
+
722
+ ints = pd.Series([1, 2, 3, 4], dtype=pd.Int64Dtype())
723
+ assert ints.replace({1: 9}).dtype == ints.dtype
724
+ assert ints.replace(1, 9).dtype == ints.dtype
725
+ assert ints.replace({1: 9.0}).dtype == ints.dtype
726
+ assert ints.replace(1, 9.0).dtype == ints.dtype
727
+
728
+ # nullable (for now) raises instead of casting
729
+ with pytest.raises(TypeError, match="Invalid value"):
730
+ ints.replace({1: 9.5})
731
+ with pytest.raises(TypeError, match="Invalid value"):
732
+ ints.replace(1, 9.5)
733
+
734
+ @pytest.mark.parametrize("regex", [False, True])
735
+ def test_replace_regex_dtype_series(self, regex):
736
+ # GH-48644
737
+ series = pd.Series(["0"], dtype=object)
738
+ expected = pd.Series([1])
739
+ msg = "Downcasting behavior in `replace`"
740
+ with tm.assert_produces_warning(FutureWarning, match=msg):
741
+ result = series.replace(to_replace="0", value=1, regex=regex)
742
+ tm.assert_series_equal(result, expected)
743
+
744
+ @pytest.mark.parametrize("regex", [False, True])
745
+ def test_replace_regex_dtype_series_string(self, regex):
746
+ series = pd.Series(["0"], dtype="str")
747
+ expected = pd.Series([1], dtype="int64")
748
+ msg = "Downcasting behavior in `replace`"
749
+ with tm.assert_produces_warning(FutureWarning, match=msg):
750
+ result = series.replace(to_replace="0", value=1, regex=regex)
751
+ tm.assert_series_equal(result, expected)
752
+
753
+ def test_replace_different_int_types(self, any_int_numpy_dtype):
754
+ # GH#45311
755
+ labs = pd.Series([1, 1, 1, 0, 0, 2, 2, 2], dtype=any_int_numpy_dtype)
756
+
757
+ maps = pd.Series([0, 2, 1], dtype=any_int_numpy_dtype)
758
+ map_dict = dict(zip(maps.values, maps.index))
759
+
760
+ result = labs.replace(map_dict)
761
+ expected = labs.replace({0: 0, 2: 1, 1: 2})
762
+ tm.assert_series_equal(result, expected)
763
+
764
+ @pytest.mark.parametrize("val", [2, np.nan, 2.0])
765
+ def test_replace_value_none_dtype_numeric(self, val):
766
+ # GH#48231
767
+ ser = pd.Series([1, val])
768
+ result = ser.replace(val, None)
769
+ expected = pd.Series([1, None], dtype=object)
770
+ tm.assert_series_equal(result, expected)
771
+
772
+ def test_replace_change_dtype_series(self):
773
+ # GH#25797
774
+ df = pd.DataFrame({"Test": ["0.5", True, "0.6"]}, dtype=object)
775
+ df["Test"] = df["Test"].replace([True], [np.nan])
776
+ expected = pd.DataFrame({"Test": ["0.5", np.nan, "0.6"]}, dtype=object)
777
+ tm.assert_frame_equal(df, expected)
778
+
779
+ df = pd.DataFrame({"Test": ["0.5", None, "0.6"]}, dtype=object)
780
+ df["Test"] = df["Test"].replace([None], [np.nan])
781
+ tm.assert_frame_equal(df, expected)
782
+
783
+ df = pd.DataFrame({"Test": ["0.5", None, "0.6"]}, dtype=object)
784
+ df["Test"] = df["Test"].fillna(np.nan)
785
+ tm.assert_frame_equal(df, expected)
786
+
787
+ @pytest.mark.parametrize("dtype", ["object", "Int64"])
788
+ def test_replace_na_in_obj_column(self, dtype):
789
+ # GH#47480
790
+ ser = pd.Series([0, 1, pd.NA], dtype=dtype)
791
+ expected = pd.Series([0, 2, pd.NA], dtype=dtype)
792
+ result = ser.replace(to_replace=1, value=2)
793
+ tm.assert_series_equal(result, expected)
794
+
795
+ ser.replace(to_replace=1, value=2, inplace=True)
796
+ tm.assert_series_equal(ser, expected)
797
+
798
+ @pytest.mark.parametrize("val", [0, 0.5])
799
+ def test_replace_numeric_column_with_na(self, val):
800
+ # GH#50758
801
+ ser = pd.Series([val, 1])
802
+ expected = pd.Series([val, pd.NA])
803
+ result = ser.replace(to_replace=1, value=pd.NA)
804
+ tm.assert_series_equal(result, expected)
805
+
806
+ ser.replace(to_replace=1, value=pd.NA, inplace=True)
807
+ tm.assert_series_equal(ser, expected)
808
+
809
+ def test_replace_ea_float_with_bool(self):
810
+ # GH#55398
811
+ ser = pd.Series([0.0], dtype="Float64")
812
+ expected = ser.copy()
813
+ result = ser.replace(False, 1.0)
814
+ tm.assert_series_equal(result, expected)
815
+
816
+ ser = pd.Series([False], dtype="boolean")
817
+ expected = ser.copy()
818
+ result = ser.replace(0.0, True)
819
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_reset_index.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ import pandas as pd
7
+ from pandas import (
8
+ DataFrame,
9
+ Index,
10
+ MultiIndex,
11
+ RangeIndex,
12
+ Series,
13
+ date_range,
14
+ option_context,
15
+ )
16
+ import pandas._testing as tm
17
+
18
+
19
+ class TestResetIndex:
20
+ def test_reset_index_dti_round_trip(self):
21
+ dti = date_range(start="1/1/2001", end="6/1/2001", freq="D")._with_freq(None)
22
+ d1 = DataFrame({"v": np.random.default_rng(2).random(len(dti))}, index=dti)
23
+ d2 = d1.reset_index()
24
+ assert d2.dtypes.iloc[0] == np.dtype("M8[ns]")
25
+ d3 = d2.set_index("index")
26
+ tm.assert_frame_equal(d1, d3, check_names=False)
27
+
28
+ # GH#2329
29
+ stamp = datetime(2012, 11, 22)
30
+ df = DataFrame([[stamp, 12.1]], columns=["Date", "Value"])
31
+ df = df.set_index("Date")
32
+
33
+ assert df.index[0] == stamp
34
+ assert df.reset_index()["Date"].iloc[0] == stamp
35
+
36
+ def test_reset_index(self):
37
+ df = DataFrame(
38
+ 1.1 * np.arange(120).reshape((30, 4)),
39
+ columns=Index(list("ABCD"), dtype=object),
40
+ index=Index([f"i-{i}" for i in range(30)], dtype=object),
41
+ )[:5]
42
+ ser = df.stack(future_stack=True)
43
+ ser.index.names = ["hash", "category"]
44
+
45
+ ser.name = "value"
46
+ df = ser.reset_index()
47
+ assert "value" in df
48
+
49
+ df = ser.reset_index(name="value2")
50
+ assert "value2" in df
51
+
52
+ # check inplace
53
+ s = ser.reset_index(drop=True)
54
+ s2 = ser
55
+ return_value = s2.reset_index(drop=True, inplace=True)
56
+ assert return_value is None
57
+ tm.assert_series_equal(s, s2)
58
+
59
+ # level
60
+ index = MultiIndex(
61
+ levels=[["bar"], ["one", "two", "three"], [0, 1]],
62
+ codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1]],
63
+ )
64
+ s = Series(np.random.default_rng(2).standard_normal(6), index=index)
65
+ rs = s.reset_index(level=1)
66
+ assert len(rs.columns) == 2
67
+
68
+ rs = s.reset_index(level=[0, 2], drop=True)
69
+ tm.assert_index_equal(rs.index, Index(index.get_level_values(1)))
70
+ assert isinstance(rs, Series)
71
+
72
+ def test_reset_index_name(self):
73
+ s = Series([1, 2, 3], index=Index(range(3), name="x"))
74
+ assert s.reset_index().index.name is None
75
+ assert s.reset_index(drop=True).index.name is None
76
+
77
+ def test_reset_index_level(self):
78
+ df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=["A", "B", "C"])
79
+
80
+ for levels in ["A", "B"], [0, 1]:
81
+ # With MultiIndex
82
+ s = df.set_index(["A", "B"])["C"]
83
+
84
+ result = s.reset_index(level=levels[0])
85
+ tm.assert_frame_equal(result, df.set_index("B"))
86
+
87
+ result = s.reset_index(level=levels[:1])
88
+ tm.assert_frame_equal(result, df.set_index("B"))
89
+
90
+ result = s.reset_index(level=levels)
91
+ tm.assert_frame_equal(result, df)
92
+
93
+ result = df.set_index(["A", "B"]).reset_index(level=levels, drop=True)
94
+ tm.assert_frame_equal(result, df[["C"]])
95
+
96
+ with pytest.raises(KeyError, match="Level E "):
97
+ s.reset_index(level=["A", "E"])
98
+
99
+ # With single-level Index
100
+ s = df.set_index("A")["B"]
101
+
102
+ result = s.reset_index(level=levels[0])
103
+ tm.assert_frame_equal(result, df[["A", "B"]])
104
+
105
+ result = s.reset_index(level=levels[:1])
106
+ tm.assert_frame_equal(result, df[["A", "B"]])
107
+
108
+ result = s.reset_index(level=levels[0], drop=True)
109
+ tm.assert_series_equal(result, df["B"])
110
+
111
+ with pytest.raises(IndexError, match="Too many levels"):
112
+ s.reset_index(level=[0, 1, 2])
113
+
114
+ # Check that .reset_index([],drop=True) doesn't fail
115
+ result = Series(range(4)).reset_index([], drop=True)
116
+ expected = Series(range(4))
117
+ tm.assert_series_equal(result, expected)
118
+
119
+ def test_reset_index_range(self):
120
+ # GH 12071
121
+ s = Series(range(2), name="A", dtype="int64")
122
+ series_result = s.reset_index()
123
+ assert isinstance(series_result.index, RangeIndex)
124
+ series_expected = DataFrame(
125
+ [[0, 0], [1, 1]], columns=["index", "A"], index=RangeIndex(stop=2)
126
+ )
127
+ tm.assert_frame_equal(series_result, series_expected)
128
+
129
+ def test_reset_index_drop_errors(self):
130
+ # GH 20925
131
+
132
+ # KeyError raised for series index when passed level name is missing
133
+ s = Series(range(4))
134
+ with pytest.raises(KeyError, match="does not match index name"):
135
+ s.reset_index("wrong", drop=True)
136
+ with pytest.raises(KeyError, match="does not match index name"):
137
+ s.reset_index("wrong")
138
+
139
+ # KeyError raised for series when level to be dropped is missing
140
+ s = Series(range(4), index=MultiIndex.from_product([[1, 2]] * 2))
141
+ with pytest.raises(KeyError, match="not found"):
142
+ s.reset_index("wrong", drop=True)
143
+
144
+ def test_reset_index_with_drop(self):
145
+ arrays = [
146
+ ["bar", "bar", "baz", "baz", "qux", "qux", "foo", "foo"],
147
+ ["one", "two", "one", "two", "one", "two", "one", "two"],
148
+ ]
149
+ tuples = zip(*arrays)
150
+ index = MultiIndex.from_tuples(tuples)
151
+ data = np.random.default_rng(2).standard_normal(8)
152
+ ser = Series(data, index=index)
153
+ ser.iloc[3] = np.nan
154
+
155
+ deleveled = ser.reset_index()
156
+ assert isinstance(deleveled, DataFrame)
157
+ assert len(deleveled.columns) == len(ser.index.levels) + 1
158
+ assert deleveled.index.name == ser.index.name
159
+
160
+ deleveled = ser.reset_index(drop=True)
161
+ assert isinstance(deleveled, Series)
162
+ assert deleveled.index.name == ser.index.name
163
+
164
+ def test_reset_index_inplace_and_drop_ignore_name(self):
165
+ # GH#44575
166
+ ser = Series(range(2), name="old")
167
+ ser.reset_index(name="new", drop=True, inplace=True)
168
+ expected = Series(range(2), name="old")
169
+ tm.assert_series_equal(ser, expected)
170
+
171
+ def test_reset_index_drop_infer_string(self):
172
+ # GH#56160
173
+ pytest.importorskip("pyarrow")
174
+ ser = Series(["a", "b", "c"], dtype=object)
175
+ with option_context("future.infer_string", True):
176
+ result = ser.reset_index(drop=True)
177
+ tm.assert_series_equal(result, ser)
178
+
179
+
180
+ @pytest.mark.parametrize(
181
+ "array, dtype",
182
+ [
183
+ (["a", "b"], object),
184
+ (
185
+ pd.period_range("12-1-2000", periods=2, freq="Q-DEC"),
186
+ pd.PeriodDtype(freq="Q-DEC"),
187
+ ),
188
+ ],
189
+ )
190
+ def test_reset_index_dtypes_on_empty_series_with_multiindex(
191
+ array, dtype, using_infer_string
192
+ ):
193
+ # GH 19602 - Preserve dtype on empty Series with MultiIndex
194
+ idx = MultiIndex.from_product([[0, 1], [0.5, 1.0], array])
195
+ result = Series(dtype=object, index=idx)[:0].reset_index().dtypes
196
+ exp = "str" if using_infer_string else object
197
+ expected = Series(
198
+ {
199
+ "level_0": np.int64,
200
+ "level_1": np.float64,
201
+ "level_2": exp if dtype == object else dtype,
202
+ 0: object,
203
+ }
204
+ )
205
+ tm.assert_series_equal(result, expected)
206
+
207
+
208
+ @pytest.mark.parametrize(
209
+ "names, expected_names",
210
+ [
211
+ (["A", "A"], ["A", "A"]),
212
+ (["level_1", None], ["level_1", "level_1"]),
213
+ ],
214
+ )
215
+ @pytest.mark.parametrize("allow_duplicates", [False, True])
216
+ def test_column_name_duplicates(names, expected_names, allow_duplicates):
217
+ # GH#44755 reset_index with duplicate column labels
218
+ s = Series([1], index=MultiIndex.from_arrays([[1], [1]], names=names))
219
+ if allow_duplicates:
220
+ result = s.reset_index(allow_duplicates=True)
221
+ expected = DataFrame([[1, 1, 1]], columns=expected_names + [0])
222
+ tm.assert_frame_equal(result, expected)
223
+ else:
224
+ with pytest.raises(ValueError, match="cannot insert"):
225
+ s.reset_index()
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_round.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import Series
6
+ import pandas._testing as tm
7
+
8
+
9
+ class TestSeriesRound:
10
+ def test_round(self, datetime_series):
11
+ datetime_series.index.name = "index_name"
12
+ result = datetime_series.round(2)
13
+ expected = Series(
14
+ np.round(datetime_series.values, 2), index=datetime_series.index, name="ts"
15
+ )
16
+ tm.assert_series_equal(result, expected)
17
+ assert result.name == datetime_series.name
18
+
19
+ def test_round_numpy(self, any_float_dtype):
20
+ # See GH#12600
21
+ ser = Series([1.53, 1.36, 0.06], dtype=any_float_dtype)
22
+ out = np.round(ser, decimals=0)
23
+ expected = Series([2.0, 1.0, 0.0], dtype=any_float_dtype)
24
+ tm.assert_series_equal(out, expected)
25
+
26
+ msg = "the 'out' parameter is not supported"
27
+ with pytest.raises(ValueError, match=msg):
28
+ np.round(ser, decimals=0, out=ser)
29
+
30
+ def test_round_numpy_with_nan(self, any_float_dtype):
31
+ # See GH#14197
32
+ ser = Series([1.53, np.nan, 0.06], dtype=any_float_dtype)
33
+ with tm.assert_produces_warning(None):
34
+ result = ser.round()
35
+ expected = Series([2.0, np.nan, 0.0], dtype=any_float_dtype)
36
+ tm.assert_series_equal(result, expected)
37
+
38
+ def test_round_builtin(self, any_float_dtype):
39
+ ser = Series(
40
+ [1.123, 2.123, 3.123],
41
+ index=range(3),
42
+ dtype=any_float_dtype,
43
+ )
44
+ result = round(ser)
45
+ expected_rounded0 = Series(
46
+ [1.0, 2.0, 3.0], index=range(3), dtype=any_float_dtype
47
+ )
48
+ tm.assert_series_equal(result, expected_rounded0)
49
+
50
+ decimals = 2
51
+ expected_rounded = Series(
52
+ [1.12, 2.12, 3.12], index=range(3), dtype=any_float_dtype
53
+ )
54
+ result = round(ser, decimals)
55
+ tm.assert_series_equal(result, expected_rounded)
56
+
57
+ @pytest.mark.parametrize("method", ["round", "floor", "ceil"])
58
+ @pytest.mark.parametrize("freq", ["s", "5s", "min", "5min", "h", "5h"])
59
+ def test_round_nat(self, method, freq, unit):
60
+ # GH14940, GH#56158
61
+ ser = Series([pd.NaT], dtype=f"M8[{unit}]")
62
+ expected = Series(pd.NaT, dtype=f"M8[{unit}]")
63
+ round_method = getattr(ser.dt, method)
64
+ result = round_method(freq)
65
+ tm.assert_series_equal(result, expected)
66
+
67
+ def test_round_ea_boolean(self):
68
+ # GH#55936
69
+ ser = Series([True, False], dtype="boolean")
70
+ expected = ser.copy()
71
+ result = ser.round(2)
72
+ tm.assert_series_equal(result, expected)
73
+ result.iloc[0] = False
74
+ tm.assert_series_equal(ser, expected)
75
+
76
+ def test_round_dtype_object(self):
77
+ # GH#61206
78
+ ser = Series([0.2], dtype="object")
79
+ msg = "Expected numeric dtype, got object instead."
80
+ with pytest.raises(TypeError, match=msg):
81
+ ser.round()
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_searchsorted.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Series,
7
+ Timestamp,
8
+ date_range,
9
+ )
10
+ import pandas._testing as tm
11
+ from pandas.api.types import is_scalar
12
+
13
+
14
+ class TestSeriesSearchSorted:
15
+ def test_searchsorted(self):
16
+ ser = Series([1, 2, 3])
17
+
18
+ result = ser.searchsorted(1, side="left")
19
+ assert is_scalar(result)
20
+ assert result == 0
21
+
22
+ result = ser.searchsorted(1, side="right")
23
+ assert is_scalar(result)
24
+ assert result == 1
25
+
26
+ def test_searchsorted_numeric_dtypes_scalar(self):
27
+ ser = Series([1, 2, 90, 1000, 3e9])
28
+ res = ser.searchsorted(30)
29
+ assert is_scalar(res)
30
+ assert res == 2
31
+
32
+ res = ser.searchsorted([30])
33
+ exp = np.array([2], dtype=np.intp)
34
+ tm.assert_numpy_array_equal(res, exp)
35
+
36
+ def test_searchsorted_numeric_dtypes_vector(self):
37
+ ser = Series([1, 2, 90, 1000, 3e9])
38
+ res = ser.searchsorted([91, 2e6])
39
+ exp = np.array([3, 4], dtype=np.intp)
40
+ tm.assert_numpy_array_equal(res, exp)
41
+
42
+ def test_searchsorted_datetime64_scalar(self):
43
+ ser = Series(date_range("20120101", periods=10, freq="2D"))
44
+ val = Timestamp("20120102")
45
+ res = ser.searchsorted(val)
46
+ assert is_scalar(res)
47
+ assert res == 1
48
+
49
+ def test_searchsorted_datetime64_scalar_mixed_timezones(self):
50
+ # GH 30086
51
+ ser = Series(date_range("20120101", periods=10, freq="2D", tz="UTC"))
52
+ val = Timestamp("20120102", tz="America/New_York")
53
+ res = ser.searchsorted(val)
54
+ assert is_scalar(res)
55
+ assert res == 1
56
+
57
+ def test_searchsorted_datetime64_list(self):
58
+ ser = Series(date_range("20120101", periods=10, freq="2D"))
59
+ vals = [Timestamp("20120102"), Timestamp("20120104")]
60
+ res = ser.searchsorted(vals)
61
+ exp = np.array([1, 2], dtype=np.intp)
62
+ tm.assert_numpy_array_equal(res, exp)
63
+
64
+ def test_searchsorted_sorter(self):
65
+ # GH8490
66
+ ser = Series([3, 1, 2])
67
+ res = ser.searchsorted([0, 3], sorter=np.argsort(ser))
68
+ exp = np.array([0, 2], dtype=np.intp)
69
+ tm.assert_numpy_array_equal(res, exp)
70
+
71
+ def test_searchsorted_dataframe_fail(self):
72
+ # GH#49620
73
+ ser = Series([1, 2, 3, 4, 5])
74
+ vals = pd.DataFrame([[1, 2], [3, 4]])
75
+ msg = "Value must be 1-D array-like or scalar, DataFrame is not supported"
76
+ with pytest.raises(ValueError, match=msg):
77
+ ser.searchsorted(vals)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_set_name.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ from pandas import Series
4
+
5
+
6
+ class TestSetName:
7
+ def test_set_name(self):
8
+ ser = Series([1, 2, 3])
9
+ ser2 = ser._set_name("foo")
10
+ assert ser2.name == "foo"
11
+ assert ser.name is None
12
+ assert ser is not ser2
13
+
14
+ def test_set_name_attribute(self):
15
+ ser = Series([1, 2, 3])
16
+ ser2 = Series([1, 2, 3], name="bar")
17
+ for name in [7, 7.0, "name", datetime(2001, 1, 1), (1,), "\u05D0"]:
18
+ ser.name = name
19
+ assert ser.name == name
20
+ ser2.name = name
21
+ assert ser2.name == name
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_size.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import Series
4
+
5
+
6
+ @pytest.mark.parametrize(
7
+ "data, index, expected",
8
+ [
9
+ ([1, 2, 3], None, 3),
10
+ ({"a": 1, "b": 2, "c": 3}, None, 3),
11
+ ([1, 2, 3], ["x", "y", "z"], 3),
12
+ ([1, 2, 3, 4, 5], ["x", "y", "z", "w", "n"], 5),
13
+ ([1, 2, 3], None, 3),
14
+ ([1, 2, 3], ["x", "y", "z"], 3),
15
+ ([1, 2, 3, 4], ["x", "y", "z", "w"], 4),
16
+ ],
17
+ )
18
+ def test_series(data, index, expected):
19
+ # GH#52897
20
+ ser = Series(data, index=index)
21
+ assert ser.size == expected
22
+ assert isinstance(ser.size, int)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_sort_index.py ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ DatetimeIndex,
6
+ IntervalIndex,
7
+ MultiIndex,
8
+ Series,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ @pytest.fixture(params=["quicksort", "mergesort", "heapsort", "stable"])
14
+ def sort_kind(request):
15
+ return request.param
16
+
17
+
18
+ class TestSeriesSortIndex:
19
+ def test_sort_index_name(self, datetime_series):
20
+ result = datetime_series.sort_index(ascending=False)
21
+ assert result.name == datetime_series.name
22
+
23
+ def test_sort_index(self, datetime_series):
24
+ datetime_series.index = datetime_series.index._with_freq(None)
25
+
26
+ rindex = list(datetime_series.index)
27
+ np.random.default_rng(2).shuffle(rindex)
28
+
29
+ random_order = datetime_series.reindex(rindex)
30
+ sorted_series = random_order.sort_index()
31
+ tm.assert_series_equal(sorted_series, datetime_series)
32
+
33
+ # descending
34
+ sorted_series = random_order.sort_index(ascending=False)
35
+ tm.assert_series_equal(
36
+ sorted_series, datetime_series.reindex(datetime_series.index[::-1])
37
+ )
38
+
39
+ # compat on level
40
+ sorted_series = random_order.sort_index(level=0)
41
+ tm.assert_series_equal(sorted_series, datetime_series)
42
+
43
+ # compat on axis
44
+ sorted_series = random_order.sort_index(axis=0)
45
+ tm.assert_series_equal(sorted_series, datetime_series)
46
+
47
+ msg = "No axis named 1 for object type Series"
48
+ with pytest.raises(ValueError, match=msg):
49
+ random_order.sort_values(axis=1)
50
+
51
+ sorted_series = random_order.sort_index(level=0, axis=0)
52
+ tm.assert_series_equal(sorted_series, datetime_series)
53
+
54
+ with pytest.raises(ValueError, match=msg):
55
+ random_order.sort_index(level=0, axis=1)
56
+
57
+ def test_sort_index_inplace(self, datetime_series):
58
+ datetime_series.index = datetime_series.index._with_freq(None)
59
+
60
+ # For GH#11402
61
+ rindex = list(datetime_series.index)
62
+ np.random.default_rng(2).shuffle(rindex)
63
+
64
+ # descending
65
+ random_order = datetime_series.reindex(rindex)
66
+ result = random_order.sort_index(ascending=False, inplace=True)
67
+
68
+ assert result is None
69
+ expected = datetime_series.reindex(datetime_series.index[::-1])
70
+ expected.index = expected.index._with_freq(None)
71
+ tm.assert_series_equal(random_order, expected)
72
+
73
+ # ascending
74
+ random_order = datetime_series.reindex(rindex)
75
+ result = random_order.sort_index(ascending=True, inplace=True)
76
+
77
+ assert result is None
78
+ expected = datetime_series.copy()
79
+ expected.index = expected.index._with_freq(None)
80
+ tm.assert_series_equal(random_order, expected)
81
+
82
+ def test_sort_index_level(self):
83
+ mi = MultiIndex.from_tuples([[1, 1, 3], [1, 1, 1]], names=list("ABC"))
84
+ s = Series([1, 2], mi)
85
+ backwards = s.iloc[[1, 0]]
86
+
87
+ res = s.sort_index(level="A")
88
+ tm.assert_series_equal(backwards, res)
89
+
90
+ res = s.sort_index(level=["A", "B"])
91
+ tm.assert_series_equal(backwards, res)
92
+
93
+ res = s.sort_index(level="A", sort_remaining=False)
94
+ tm.assert_series_equal(s, res)
95
+
96
+ res = s.sort_index(level=["A", "B"], sort_remaining=False)
97
+ tm.assert_series_equal(s, res)
98
+
99
+ @pytest.mark.parametrize("level", ["A", 0]) # GH#21052
100
+ def test_sort_index_multiindex(self, level):
101
+ mi = MultiIndex.from_tuples([[1, 1, 3], [1, 1, 1]], names=list("ABC"))
102
+ s = Series([1, 2], mi)
103
+ backwards = s.iloc[[1, 0]]
104
+
105
+ # implicit sort_remaining=True
106
+ res = s.sort_index(level=level)
107
+ tm.assert_series_equal(backwards, res)
108
+
109
+ # GH#13496
110
+ # sort has no effect without remaining lvls
111
+ res = s.sort_index(level=level, sort_remaining=False)
112
+ tm.assert_series_equal(s, res)
113
+
114
+ def test_sort_index_kind(self, sort_kind):
115
+ # GH#14444 & GH#13589: Add support for sort algo choosing
116
+ series = Series(index=[3, 2, 1, 4, 3], dtype=object)
117
+ expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
118
+
119
+ index_sorted_series = series.sort_index(kind=sort_kind)
120
+ tm.assert_series_equal(expected_series, index_sorted_series)
121
+
122
+ def test_sort_index_na_position(self):
123
+ series = Series(index=[3, 2, 1, 4, 3, np.nan], dtype=object)
124
+ expected_series_first = Series(index=[np.nan, 1, 2, 3, 3, 4], dtype=object)
125
+
126
+ index_sorted_series = series.sort_index(na_position="first")
127
+ tm.assert_series_equal(expected_series_first, index_sorted_series)
128
+
129
+ expected_series_last = Series(index=[1, 2, 3, 3, 4, np.nan], dtype=object)
130
+
131
+ index_sorted_series = series.sort_index(na_position="last")
132
+ tm.assert_series_equal(expected_series_last, index_sorted_series)
133
+
134
+ def test_sort_index_intervals(self):
135
+ s = Series(
136
+ [np.nan, 1, 2, 3], IntervalIndex.from_arrays([0, 1, 2, 3], [1, 2, 3, 4])
137
+ )
138
+
139
+ result = s.sort_index()
140
+ expected = s
141
+ tm.assert_series_equal(result, expected)
142
+
143
+ result = s.sort_index(ascending=False)
144
+ expected = Series(
145
+ [3, 2, 1, np.nan], IntervalIndex.from_arrays([3, 2, 1, 0], [4, 3, 2, 1])
146
+ )
147
+ tm.assert_series_equal(result, expected)
148
+
149
+ @pytest.mark.parametrize("inplace", [True, False])
150
+ @pytest.mark.parametrize(
151
+ "original_list, sorted_list, ascending, ignore_index, output_index",
152
+ [
153
+ ([2, 3, 6, 1], [2, 3, 6, 1], True, True, [0, 1, 2, 3]),
154
+ ([2, 3, 6, 1], [2, 3, 6, 1], True, False, [0, 1, 2, 3]),
155
+ ([2, 3, 6, 1], [1, 6, 3, 2], False, True, [0, 1, 2, 3]),
156
+ ([2, 3, 6, 1], [1, 6, 3, 2], False, False, [3, 2, 1, 0]),
157
+ ],
158
+ )
159
+ def test_sort_index_ignore_index(
160
+ self, inplace, original_list, sorted_list, ascending, ignore_index, output_index
161
+ ):
162
+ # GH 30114
163
+ ser = Series(original_list)
164
+ expected = Series(sorted_list, index=output_index)
165
+ kwargs = {
166
+ "ascending": ascending,
167
+ "ignore_index": ignore_index,
168
+ "inplace": inplace,
169
+ }
170
+
171
+ if inplace:
172
+ result_ser = ser.copy()
173
+ result_ser.sort_index(**kwargs)
174
+ else:
175
+ result_ser = ser.sort_index(**kwargs)
176
+
177
+ tm.assert_series_equal(result_ser, expected)
178
+ tm.assert_series_equal(ser, Series(original_list))
179
+
180
+ def test_sort_index_ascending_list(self):
181
+ # GH#16934
182
+
183
+ # Set up a Series with a three level MultiIndex
184
+ arrays = [
185
+ ["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
186
+ ["one", "two", "one", "two", "one", "two", "one", "two"],
187
+ [4, 3, 2, 1, 4, 3, 2, 1],
188
+ ]
189
+ tuples = zip(*arrays)
190
+ mi = MultiIndex.from_tuples(tuples, names=["first", "second", "third"])
191
+ ser = Series(range(8), index=mi)
192
+
193
+ # Sort with boolean ascending
194
+ result = ser.sort_index(level=["third", "first"], ascending=False)
195
+ expected = ser.iloc[[4, 0, 5, 1, 6, 2, 7, 3]]
196
+ tm.assert_series_equal(result, expected)
197
+
198
+ # Sort with list of boolean ascending
199
+ result = ser.sort_index(level=["third", "first"], ascending=[False, True])
200
+ expected = ser.iloc[[0, 4, 1, 5, 2, 6, 3, 7]]
201
+ tm.assert_series_equal(result, expected)
202
+
203
+ @pytest.mark.parametrize(
204
+ "ascending",
205
+ [
206
+ None,
207
+ (True, None),
208
+ (False, "True"),
209
+ ],
210
+ )
211
+ def test_sort_index_ascending_bad_value_raises(self, ascending):
212
+ ser = Series(range(10), index=[0, 3, 2, 1, 4, 5, 7, 6, 8, 9])
213
+ match = 'For argument "ascending" expected type bool'
214
+ with pytest.raises(ValueError, match=match):
215
+ ser.sort_index(ascending=ascending)
216
+
217
+
218
+ class TestSeriesSortIndexKey:
219
+ def test_sort_index_multiindex_key(self):
220
+ mi = MultiIndex.from_tuples([[1, 1, 3], [1, 1, 1]], names=list("ABC"))
221
+ s = Series([1, 2], mi)
222
+ backwards = s.iloc[[1, 0]]
223
+
224
+ result = s.sort_index(level="C", key=lambda x: -x)
225
+ tm.assert_series_equal(s, result)
226
+
227
+ result = s.sort_index(level="C", key=lambda x: x) # nothing happens
228
+ tm.assert_series_equal(backwards, result)
229
+
230
+ def test_sort_index_multiindex_key_multi_level(self):
231
+ mi = MultiIndex.from_tuples([[1, 1, 3], [1, 1, 1]], names=list("ABC"))
232
+ s = Series([1, 2], mi)
233
+ backwards = s.iloc[[1, 0]]
234
+
235
+ result = s.sort_index(level=["A", "C"], key=lambda x: -x)
236
+ tm.assert_series_equal(s, result)
237
+
238
+ result = s.sort_index(level=["A", "C"], key=lambda x: x) # nothing happens
239
+ tm.assert_series_equal(backwards, result)
240
+
241
+ def test_sort_index_key(self):
242
+ series = Series(np.arange(6, dtype="int64"), index=list("aaBBca"))
243
+
244
+ result = series.sort_index()
245
+ expected = series.iloc[[2, 3, 0, 1, 5, 4]]
246
+ tm.assert_series_equal(result, expected)
247
+
248
+ result = series.sort_index(key=lambda x: x.str.lower())
249
+ expected = series.iloc[[0, 1, 5, 2, 3, 4]]
250
+ tm.assert_series_equal(result, expected)
251
+
252
+ result = series.sort_index(key=lambda x: x.str.lower(), ascending=False)
253
+ expected = series.iloc[[4, 2, 3, 0, 1, 5]]
254
+ tm.assert_series_equal(result, expected)
255
+
256
+ def test_sort_index_key_int(self):
257
+ series = Series(np.arange(6, dtype="int64"), index=np.arange(6, dtype="int64"))
258
+
259
+ result = series.sort_index()
260
+ tm.assert_series_equal(result, series)
261
+
262
+ result = series.sort_index(key=lambda x: -x)
263
+ expected = series.sort_index(ascending=False)
264
+ tm.assert_series_equal(result, expected)
265
+
266
+ result = series.sort_index(key=lambda x: 2 * x)
267
+ tm.assert_series_equal(result, series)
268
+
269
+ def test_sort_index_kind_key(self, sort_kind, sort_by_key):
270
+ # GH #14444 & #13589: Add support for sort algo choosing
271
+ series = Series(index=[3, 2, 1, 4, 3], dtype=object)
272
+ expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
273
+
274
+ index_sorted_series = series.sort_index(kind=sort_kind, key=sort_by_key)
275
+ tm.assert_series_equal(expected_series, index_sorted_series)
276
+
277
+ def test_sort_index_kind_neg_key(self, sort_kind):
278
+ # GH #14444 & #13589: Add support for sort algo choosing
279
+ series = Series(index=[3, 2, 1, 4, 3], dtype=object)
280
+ expected_series = Series(index=[4, 3, 3, 2, 1], dtype=object)
281
+
282
+ index_sorted_series = series.sort_index(kind=sort_kind, key=lambda x: -x)
283
+ tm.assert_series_equal(expected_series, index_sorted_series)
284
+
285
+ def test_sort_index_na_position_key(self, sort_by_key):
286
+ series = Series(index=[3, 2, 1, 4, 3, np.nan], dtype=object)
287
+ expected_series_first = Series(index=[np.nan, 1, 2, 3, 3, 4], dtype=object)
288
+
289
+ index_sorted_series = series.sort_index(na_position="first", key=sort_by_key)
290
+ tm.assert_series_equal(expected_series_first, index_sorted_series)
291
+
292
+ expected_series_last = Series(index=[1, 2, 3, 3, 4, np.nan], dtype=object)
293
+
294
+ index_sorted_series = series.sort_index(na_position="last", key=sort_by_key)
295
+ tm.assert_series_equal(expected_series_last, index_sorted_series)
296
+
297
+ def test_changes_length_raises(self):
298
+ s = Series([1, 2, 3])
299
+ with pytest.raises(ValueError, match="change the shape"):
300
+ s.sort_index(key=lambda x: x[:1])
301
+
302
+ def test_sort_values_key_type(self):
303
+ s = Series([1, 2, 3], DatetimeIndex(["2008-10-24", "2008-11-23", "2007-12-22"]))
304
+
305
+ result = s.sort_index(key=lambda x: x.month)
306
+ expected = s.iloc[[0, 1, 2]]
307
+ tm.assert_series_equal(result, expected)
308
+
309
+ result = s.sort_index(key=lambda x: x.day)
310
+ expected = s.iloc[[2, 1, 0]]
311
+ tm.assert_series_equal(result, expected)
312
+
313
+ result = s.sort_index(key=lambda x: x.year)
314
+ expected = s.iloc[[2, 0, 1]]
315
+ tm.assert_series_equal(result, expected)
316
+
317
+ result = s.sort_index(key=lambda x: x.month_name())
318
+ expected = s.iloc[[2, 1, 0]]
319
+ tm.assert_series_equal(result, expected)
320
+
321
+ @pytest.mark.parametrize(
322
+ "ascending",
323
+ [
324
+ [True, False],
325
+ [False, True],
326
+ ],
327
+ )
328
+ def test_sort_index_multi_already_monotonic(self, ascending):
329
+ # GH 56049
330
+ mi = MultiIndex.from_product([[1, 2], [3, 4]])
331
+ ser = Series(range(len(mi)), index=mi)
332
+ result = ser.sort_index(ascending=ascending)
333
+ if ascending == [True, False]:
334
+ expected = ser.take([1, 0, 3, 2])
335
+ elif ascending == [False, True]:
336
+ expected = ser.take([2, 3, 0, 1])
337
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_sort_values.py ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Categorical,
6
+ DataFrame,
7
+ Series,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ class TestSeriesSortValues:
13
+ def test_sort_values(self, datetime_series, using_copy_on_write):
14
+ # check indexes are reordered corresponding with the values
15
+ ser = Series([3, 2, 4, 1], ["A", "B", "C", "D"])
16
+ expected = Series([1, 2, 3, 4], ["D", "B", "A", "C"])
17
+ result = ser.sort_values()
18
+ tm.assert_series_equal(expected, result)
19
+
20
+ ts = datetime_series.copy()
21
+ ts[:5] = np.nan
22
+ vals = ts.values
23
+
24
+ result = ts.sort_values()
25
+ assert np.isnan(result[-5:]).all()
26
+ tm.assert_numpy_array_equal(result[:-5].values, np.sort(vals[5:]))
27
+
28
+ # na_position
29
+ result = ts.sort_values(na_position="first")
30
+ assert np.isnan(result[:5]).all()
31
+ tm.assert_numpy_array_equal(result[5:].values, np.sort(vals[5:]))
32
+
33
+ # something object-type
34
+ ser = Series(["A", "B"], [1, 2])
35
+ # no failure
36
+ ser.sort_values()
37
+
38
+ # ascending=False
39
+ ordered = ts.sort_values(ascending=False)
40
+ expected = np.sort(ts.dropna().values)[::-1]
41
+ tm.assert_almost_equal(expected, ordered.dropna().values)
42
+ ordered = ts.sort_values(ascending=False, na_position="first")
43
+ tm.assert_almost_equal(expected, ordered.dropna().values)
44
+
45
+ # ascending=[False] should behave the same as ascending=False
46
+ ordered = ts.sort_values(ascending=[False])
47
+ expected = ts.sort_values(ascending=False)
48
+ tm.assert_series_equal(expected, ordered)
49
+ ordered = ts.sort_values(ascending=[False], na_position="first")
50
+ expected = ts.sort_values(ascending=False, na_position="first")
51
+ tm.assert_series_equal(expected, ordered)
52
+
53
+ msg = 'For argument "ascending" expected type bool, received type NoneType.'
54
+ with pytest.raises(ValueError, match=msg):
55
+ ts.sort_values(ascending=None)
56
+ msg = r"Length of ascending \(0\) must be 1 for Series"
57
+ with pytest.raises(ValueError, match=msg):
58
+ ts.sort_values(ascending=[])
59
+ msg = r"Length of ascending \(3\) must be 1 for Series"
60
+ with pytest.raises(ValueError, match=msg):
61
+ ts.sort_values(ascending=[1, 2, 3])
62
+ msg = r"Length of ascending \(2\) must be 1 for Series"
63
+ with pytest.raises(ValueError, match=msg):
64
+ ts.sort_values(ascending=[False, False])
65
+ msg = 'For argument "ascending" expected type bool, received type str.'
66
+ with pytest.raises(ValueError, match=msg):
67
+ ts.sort_values(ascending="foobar")
68
+
69
+ # inplace=True
70
+ ts = datetime_series.copy()
71
+ return_value = ts.sort_values(ascending=False, inplace=True)
72
+ assert return_value is None
73
+ tm.assert_series_equal(ts, datetime_series.sort_values(ascending=False))
74
+ tm.assert_index_equal(
75
+ ts.index, datetime_series.sort_values(ascending=False).index
76
+ )
77
+
78
+ # GH#5856/5853
79
+ # Series.sort_values operating on a view
80
+ df = DataFrame(np.random.default_rng(2).standard_normal((10, 4)))
81
+ s = df.iloc[:, 0]
82
+
83
+ msg = (
84
+ "This Series is a view of some other array, to sort in-place "
85
+ "you must create a copy"
86
+ )
87
+ if using_copy_on_write:
88
+ s.sort_values(inplace=True)
89
+ tm.assert_series_equal(s, df.iloc[:, 0].sort_values())
90
+ else:
91
+ with pytest.raises(ValueError, match=msg):
92
+ s.sort_values(inplace=True)
93
+
94
+ def test_sort_values_categorical(self):
95
+ c = Categorical(["a", "b", "b", "a"], ordered=False)
96
+ cat = Series(c.copy())
97
+
98
+ # sort in the categories order
99
+ expected = Series(
100
+ Categorical(["a", "a", "b", "b"], ordered=False), index=[0, 3, 1, 2]
101
+ )
102
+ result = cat.sort_values()
103
+ tm.assert_series_equal(result, expected)
104
+
105
+ cat = Series(Categorical(["a", "c", "b", "d"], ordered=True))
106
+ res = cat.sort_values()
107
+ exp = np.array(["a", "b", "c", "d"], dtype=np.object_)
108
+ tm.assert_numpy_array_equal(res.__array__(), exp)
109
+
110
+ cat = Series(
111
+ Categorical(
112
+ ["a", "c", "b", "d"], categories=["a", "b", "c", "d"], ordered=True
113
+ )
114
+ )
115
+ res = cat.sort_values()
116
+ exp = np.array(["a", "b", "c", "d"], dtype=np.object_)
117
+ tm.assert_numpy_array_equal(res.__array__(), exp)
118
+
119
+ res = cat.sort_values(ascending=False)
120
+ exp = np.array(["d", "c", "b", "a"], dtype=np.object_)
121
+ tm.assert_numpy_array_equal(res.__array__(), exp)
122
+
123
+ raw_cat1 = Categorical(
124
+ ["a", "b", "c", "d"], categories=["a", "b", "c", "d"], ordered=False
125
+ )
126
+ raw_cat2 = Categorical(
127
+ ["a", "b", "c", "d"], categories=["d", "c", "b", "a"], ordered=True
128
+ )
129
+ s = ["a", "b", "c", "d"]
130
+ df = DataFrame(
131
+ {"unsort": raw_cat1, "sort": raw_cat2, "string": s, "values": [1, 2, 3, 4]}
132
+ )
133
+
134
+ # Cats must be sorted in a dataframe
135
+ res = df.sort_values(by=["string"], ascending=False)
136
+ exp = np.array(["d", "c", "b", "a"], dtype=np.object_)
137
+ tm.assert_numpy_array_equal(res["sort"].values.__array__(), exp)
138
+ assert res["sort"].dtype == "category"
139
+
140
+ res = df.sort_values(by=["sort"], ascending=False)
141
+ exp = df.sort_values(by=["string"], ascending=True)
142
+ tm.assert_series_equal(res["values"], exp["values"])
143
+ assert res["sort"].dtype == "category"
144
+ assert res["unsort"].dtype == "category"
145
+
146
+ # unordered cat, but we allow this
147
+ df.sort_values(by=["unsort"], ascending=False)
148
+
149
+ # multi-columns sort
150
+ # GH#7848
151
+ df = DataFrame(
152
+ {"id": [6, 5, 4, 3, 2, 1], "raw_grade": ["a", "b", "b", "a", "a", "e"]}
153
+ )
154
+ df["grade"] = Categorical(df["raw_grade"], ordered=True)
155
+ df["grade"] = df["grade"].cat.set_categories(["b", "e", "a"])
156
+
157
+ # sorts 'grade' according to the order of the categories
158
+ result = df.sort_values(by=["grade"])
159
+ expected = df.iloc[[1, 2, 5, 0, 3, 4]]
160
+ tm.assert_frame_equal(result, expected)
161
+
162
+ # multi
163
+ result = df.sort_values(by=["grade", "id"])
164
+ expected = df.iloc[[2, 1, 5, 4, 3, 0]]
165
+ tm.assert_frame_equal(result, expected)
166
+
167
+ @pytest.mark.parametrize("inplace", [True, False])
168
+ @pytest.mark.parametrize(
169
+ "original_list, sorted_list, ignore_index, output_index",
170
+ [
171
+ ([2, 3, 6, 1], [6, 3, 2, 1], True, [0, 1, 2, 3]),
172
+ ([2, 3, 6, 1], [6, 3, 2, 1], False, [2, 1, 0, 3]),
173
+ ],
174
+ )
175
+ def test_sort_values_ignore_index(
176
+ self, inplace, original_list, sorted_list, ignore_index, output_index
177
+ ):
178
+ # GH 30114
179
+ ser = Series(original_list)
180
+ expected = Series(sorted_list, index=output_index)
181
+ kwargs = {"ignore_index": ignore_index, "inplace": inplace}
182
+
183
+ if inplace:
184
+ result_ser = ser.copy()
185
+ result_ser.sort_values(ascending=False, **kwargs)
186
+ else:
187
+ result_ser = ser.sort_values(ascending=False, **kwargs)
188
+
189
+ tm.assert_series_equal(result_ser, expected)
190
+ tm.assert_series_equal(ser, Series(original_list))
191
+
192
+ def test_mergesort_descending_stability(self):
193
+ # GH 28697
194
+ s = Series([1, 2, 1, 3], ["first", "b", "second", "c"])
195
+ result = s.sort_values(ascending=False, kind="mergesort")
196
+ expected = Series([3, 2, 1, 1], ["c", "b", "first", "second"])
197
+ tm.assert_series_equal(result, expected)
198
+
199
+ def test_sort_values_validate_ascending_for_value_error(self):
200
+ # GH41634
201
+ ser = Series([23, 7, 21])
202
+
203
+ msg = 'For argument "ascending" expected type bool, received type str.'
204
+ with pytest.raises(ValueError, match=msg):
205
+ ser.sort_values(ascending="False")
206
+
207
+ @pytest.mark.parametrize("ascending", [False, 0, 1, True])
208
+ def test_sort_values_validate_ascending_functional(self, ascending):
209
+ # GH41634
210
+ ser = Series([23, 7, 21])
211
+ expected = np.sort(ser.values)
212
+
213
+ sorted_ser = ser.sort_values(ascending=ascending)
214
+ if not ascending:
215
+ expected = expected[::-1]
216
+
217
+ result = sorted_ser.values
218
+ tm.assert_numpy_array_equal(result, expected)
219
+
220
+
221
+ class TestSeriesSortingKey:
222
+ def test_sort_values_key(self):
223
+ series = Series(np.array(["Hello", "goodbye"]))
224
+
225
+ result = series.sort_values(axis=0)
226
+ expected = series
227
+ tm.assert_series_equal(result, expected)
228
+
229
+ result = series.sort_values(axis=0, key=lambda x: x.str.lower())
230
+ expected = series[::-1]
231
+ tm.assert_series_equal(result, expected)
232
+
233
+ def test_sort_values_key_nan(self):
234
+ series = Series(np.array([0, 5, np.nan, 3, 2, np.nan]))
235
+
236
+ result = series.sort_values(axis=0)
237
+ expected = series.iloc[[0, 4, 3, 1, 2, 5]]
238
+ tm.assert_series_equal(result, expected)
239
+
240
+ result = series.sort_values(axis=0, key=lambda x: x + 5)
241
+ expected = series.iloc[[0, 4, 3, 1, 2, 5]]
242
+ tm.assert_series_equal(result, expected)
243
+
244
+ result = series.sort_values(axis=0, key=lambda x: -x, ascending=False)
245
+ expected = series.iloc[[0, 4, 3, 1, 2, 5]]
246
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_csv.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ from io import StringIO
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ import pandas as pd
8
+ from pandas import Series
9
+ import pandas._testing as tm
10
+
11
+ from pandas.io.common import get_handle
12
+
13
+
14
+ class TestSeriesToCSV:
15
+ def read_csv(self, path, **kwargs):
16
+ params = {"index_col": 0, "header": None}
17
+ params.update(**kwargs)
18
+
19
+ header = params.get("header")
20
+ out = pd.read_csv(path, **params).squeeze("columns")
21
+
22
+ if header is None:
23
+ out.name = out.index.name = None
24
+
25
+ return out
26
+
27
+ def test_from_csv(self, datetime_series, string_series):
28
+ # freq doesn't round-trip
29
+ datetime_series.index = datetime_series.index._with_freq(None)
30
+
31
+ with tm.ensure_clean() as path:
32
+ datetime_series.to_csv(path, header=False)
33
+ ts = self.read_csv(path, parse_dates=True)
34
+ tm.assert_series_equal(datetime_series, ts, check_names=False)
35
+
36
+ assert ts.name is None
37
+ assert ts.index.name is None
38
+
39
+ # see gh-10483
40
+ datetime_series.to_csv(path, header=True)
41
+ ts_h = self.read_csv(path, header=0)
42
+ assert ts_h.name == "ts"
43
+
44
+ string_series.to_csv(path, header=False)
45
+ series = self.read_csv(path)
46
+ tm.assert_series_equal(string_series, series, check_names=False)
47
+
48
+ assert series.name is None
49
+ assert series.index.name is None
50
+
51
+ string_series.to_csv(path, header=True)
52
+ series_h = self.read_csv(path, header=0)
53
+ assert series_h.name == "series"
54
+
55
+ with open(path, "w", encoding="utf-8") as outfile:
56
+ outfile.write("1998-01-01|1.0\n1999-01-01|2.0")
57
+
58
+ series = self.read_csv(path, sep="|", parse_dates=True)
59
+ check_series = Series(
60
+ {datetime(1998, 1, 1): 1.0, datetime(1999, 1, 1): 2.0}
61
+ )
62
+ tm.assert_series_equal(check_series, series)
63
+
64
+ series = self.read_csv(path, sep="|", parse_dates=False)
65
+ check_series = Series({"1998-01-01": 1.0, "1999-01-01": 2.0})
66
+ tm.assert_series_equal(check_series, series)
67
+
68
+ def test_to_csv(self, datetime_series):
69
+ with tm.ensure_clean() as path:
70
+ datetime_series.to_csv(path, header=False)
71
+
72
+ with open(path, newline=None, encoding="utf-8") as f:
73
+ lines = f.readlines()
74
+ assert lines[1] != "\n"
75
+
76
+ datetime_series.to_csv(path, index=False, header=False)
77
+ arr = np.loadtxt(path)
78
+ tm.assert_almost_equal(arr, datetime_series.values)
79
+
80
+ def test_to_csv_unicode_index(self):
81
+ buf = StringIO()
82
+ s = Series(["\u05d0", "d2"], index=["\u05d0", "\u05d1"])
83
+
84
+ s.to_csv(buf, encoding="UTF-8", header=False)
85
+ buf.seek(0)
86
+
87
+ s2 = self.read_csv(buf, index_col=0, encoding="UTF-8")
88
+ tm.assert_series_equal(s, s2)
89
+
90
+ def test_to_csv_float_format(self):
91
+ with tm.ensure_clean() as filename:
92
+ ser = Series([0.123456, 0.234567, 0.567567])
93
+ ser.to_csv(filename, float_format="%.2f", header=False)
94
+
95
+ rs = self.read_csv(filename)
96
+ xp = Series([0.12, 0.23, 0.57])
97
+ tm.assert_series_equal(rs, xp)
98
+
99
+ def test_to_csv_list_entries(self):
100
+ s = Series(["jack and jill", "jesse and frank"])
101
+
102
+ split = s.str.split(r"\s+and\s+")
103
+
104
+ buf = StringIO()
105
+ split.to_csv(buf, header=False)
106
+
107
+ def test_to_csv_path_is_none(self):
108
+ # GH 8215
109
+ # Series.to_csv() was returning None, inconsistent with
110
+ # DataFrame.to_csv() which returned string
111
+ s = Series([1, 2, 3])
112
+ csv_str = s.to_csv(path_or_buf=None, header=False)
113
+ assert isinstance(csv_str, str)
114
+
115
+ @pytest.mark.parametrize(
116
+ "s,encoding",
117
+ [
118
+ (
119
+ Series([0.123456, 0.234567, 0.567567], index=["A", "B", "C"], name="X"),
120
+ None,
121
+ ),
122
+ # GH 21241, 21118
123
+ (Series(["abc", "def", "ghi"], name="X"), "ascii"),
124
+ (Series(["123", "你好", "世界"], name="中文"), "gb2312"),
125
+ (
126
+ Series(["123", "Γειά σου", "Κόσμε"], name="Ελληνικά"), # noqa: RUF001
127
+ "cp737",
128
+ ),
129
+ ],
130
+ )
131
+ def test_to_csv_compression(self, s, encoding, compression):
132
+ with tm.ensure_clean() as filename:
133
+ s.to_csv(filename, compression=compression, encoding=encoding, header=True)
134
+ # test the round trip - to_csv -> read_csv
135
+ result = pd.read_csv(
136
+ filename,
137
+ compression=compression,
138
+ encoding=encoding,
139
+ index_col=0,
140
+ ).squeeze("columns")
141
+ tm.assert_series_equal(s, result)
142
+
143
+ # test the round trip using file handle - to_csv -> read_csv
144
+ with get_handle(
145
+ filename, "w", compression=compression, encoding=encoding
146
+ ) as handles:
147
+ s.to_csv(handles.handle, encoding=encoding, header=True)
148
+
149
+ result = pd.read_csv(
150
+ filename,
151
+ compression=compression,
152
+ encoding=encoding,
153
+ index_col=0,
154
+ ).squeeze("columns")
155
+ tm.assert_series_equal(s, result)
156
+
157
+ # explicitly ensure file was compressed
158
+ with tm.decompress_file(filename, compression) as fh:
159
+ text = fh.read().decode(encoding or "utf8")
160
+ assert s.name in text
161
+
162
+ with tm.decompress_file(filename, compression) as fh:
163
+ tm.assert_series_equal(
164
+ s,
165
+ pd.read_csv(fh, index_col=0, encoding=encoding).squeeze("columns"),
166
+ )
167
+
168
+ def test_to_csv_interval_index(self, using_infer_string):
169
+ # GH 28210
170
+ s = Series(["foo", "bar", "baz"], index=pd.interval_range(0, 3))
171
+
172
+ with tm.ensure_clean("__tmp_to_csv_interval_index__.csv") as path:
173
+ s.to_csv(path, header=False)
174
+ result = self.read_csv(path, index_col=0)
175
+
176
+ # can't roundtrip intervalindex via read_csv so check string repr (GH 23595)
177
+ expected = s
178
+ expected.index = expected.index.astype("str")
179
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_dict.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import collections
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ from pandas import Series
7
+ import pandas._testing as tm
8
+
9
+
10
+ class TestSeriesToDict:
11
+ @pytest.mark.parametrize(
12
+ "mapping", (dict, collections.defaultdict(list), collections.OrderedDict)
13
+ )
14
+ def test_to_dict(self, mapping, datetime_series):
15
+ # GH#16122
16
+ result = Series(datetime_series.to_dict(into=mapping), name="ts")
17
+ expected = datetime_series.copy()
18
+ expected.index = expected.index._with_freq(None)
19
+ tm.assert_series_equal(result, expected)
20
+
21
+ from_method = Series(datetime_series.to_dict(into=collections.Counter))
22
+ from_constructor = Series(collections.Counter(datetime_series.items()))
23
+ tm.assert_series_equal(from_method, from_constructor)
24
+
25
+ @pytest.mark.parametrize(
26
+ "input",
27
+ (
28
+ {"a": np.int64(64), "b": 10},
29
+ {"a": np.int64(64), "b": 10, "c": "ABC"},
30
+ {"a": np.uint64(64), "b": 10, "c": "ABC"},
31
+ ),
32
+ )
33
+ def test_to_dict_return_types(self, input):
34
+ # GH25969
35
+
36
+ d = Series(input).to_dict()
37
+ assert isinstance(d["a"], int)
38
+ assert isinstance(d["b"], int)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_frame.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import (
4
+ DataFrame,
5
+ Index,
6
+ Series,
7
+ )
8
+ import pandas._testing as tm
9
+
10
+
11
+ class TestToFrame:
12
+ def test_to_frame_respects_name_none(self):
13
+ # GH#44212 if we explicitly pass name=None, then that should be respected,
14
+ # not changed to 0
15
+ # GH-45448 this is first deprecated & enforced in 2.0
16
+ ser = Series(range(3))
17
+ result = ser.to_frame(None)
18
+
19
+ exp_index = Index([None], dtype=object)
20
+ tm.assert_index_equal(result.columns, exp_index)
21
+
22
+ result = ser.rename("foo").to_frame(None)
23
+ exp_index = Index([None], dtype=object)
24
+ tm.assert_index_equal(result.columns, exp_index)
25
+
26
+ def test_to_frame(self, datetime_series):
27
+ datetime_series.name = None
28
+ rs = datetime_series.to_frame()
29
+ xp = DataFrame(datetime_series.values, index=datetime_series.index)
30
+ tm.assert_frame_equal(rs, xp)
31
+
32
+ datetime_series.name = "testname"
33
+ rs = datetime_series.to_frame()
34
+ xp = DataFrame(
35
+ {"testname": datetime_series.values}, index=datetime_series.index
36
+ )
37
+ tm.assert_frame_equal(rs, xp)
38
+
39
+ rs = datetime_series.to_frame(name="testdifferent")
40
+ xp = DataFrame(
41
+ {"testdifferent": datetime_series.values}, index=datetime_series.index
42
+ )
43
+ tm.assert_frame_equal(rs, xp)
44
+
45
+ @pytest.mark.filterwarnings(
46
+ "ignore:Passing a BlockManager|Passing a SingleBlockManager:DeprecationWarning"
47
+ )
48
+ def test_to_frame_expanddim(self):
49
+ # GH#9762
50
+
51
+ class SubclassedSeries(Series):
52
+ @property
53
+ def _constructor_expanddim(self):
54
+ return SubclassedFrame
55
+
56
+ class SubclassedFrame(DataFrame):
57
+ pass
58
+
59
+ ser = SubclassedSeries([1, 2, 3], name="X")
60
+ result = ser.to_frame()
61
+ assert isinstance(result, SubclassedFrame)
62
+ expected = SubclassedFrame({"X": [1, 2, 3]})
63
+ tm.assert_frame_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_to_numpy.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas.util._test_decorators as td
5
+
6
+ from pandas import (
7
+ NA,
8
+ Series,
9
+ Timedelta,
10
+ )
11
+ import pandas._testing as tm
12
+
13
+
14
+ @pytest.mark.parametrize("dtype", ["int64", "float64"])
15
+ def test_to_numpy_na_value(dtype):
16
+ # GH#48951
17
+ ser = Series([1, 2, NA, 4])
18
+ result = ser.to_numpy(dtype=dtype, na_value=0)
19
+ expected = np.array([1, 2, 0, 4], dtype=dtype)
20
+ tm.assert_numpy_array_equal(result, expected)
21
+
22
+
23
+ def test_to_numpy_cast_before_setting_na():
24
+ # GH#50600
25
+ ser = Series([1])
26
+ result = ser.to_numpy(dtype=np.float64, na_value=np.nan)
27
+ expected = np.array([1.0])
28
+ tm.assert_numpy_array_equal(result, expected)
29
+
30
+
31
+ @td.skip_if_no("pyarrow")
32
+ def test_to_numpy_arrow_dtype_given():
33
+ # GH#57121
34
+ ser = Series([1, NA], dtype="int64[pyarrow]")
35
+ result = ser.to_numpy(dtype="float64")
36
+ expected = np.array([1.0, np.nan])
37
+ tm.assert_numpy_array_equal(result, expected)
38
+
39
+
40
+ def test_astype_ea_int_to_td_ts():
41
+ # GH#57093
42
+ ser = Series([1, None], dtype="Int64")
43
+ result = ser.astype("m8[ns]")
44
+ expected = Series([1, Timedelta("nat")], dtype="m8[ns]")
45
+ tm.assert_series_equal(result, expected)
46
+
47
+ result = ser.astype("M8[ns]")
48
+ expected = Series([1, Timedelta("nat")], dtype="M8[ns]")
49
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_tolist.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ import pandas.util._test_decorators as td
4
+
5
+ from pandas import (
6
+ Interval,
7
+ Period,
8
+ Series,
9
+ Timedelta,
10
+ Timestamp,
11
+ )
12
+
13
+
14
+ @pytest.mark.parametrize(
15
+ "values, dtype, expected_dtype",
16
+ (
17
+ ([1], "int64", int),
18
+ ([1], "Int64", int),
19
+ ([1.0], "float64", float),
20
+ ([1.0], "Float64", float),
21
+ (["abc"], "object", str),
22
+ (["abc"], "string", str),
23
+ ([Interval(1, 3)], "interval", Interval),
24
+ ([Period("2000-01-01", "D")], "period[D]", Period),
25
+ ([Timedelta(days=1)], "timedelta64[ns]", Timedelta),
26
+ ([Timestamp("2000-01-01")], "datetime64[ns]", Timestamp),
27
+ pytest.param([1], "int64[pyarrow]", int, marks=td.skip_if_no("pyarrow")),
28
+ pytest.param([1.0], "float64[pyarrow]", float, marks=td.skip_if_no("pyarrow")),
29
+ pytest.param(["abc"], "string[pyarrow]", str, marks=td.skip_if_no("pyarrow")),
30
+ ),
31
+ )
32
+ def test_tolist_scalar_dtype(values, dtype, expected_dtype):
33
+ # GH49890
34
+ ser = Series(values, dtype=dtype)
35
+ result_dtype = type(ser.tolist()[0])
36
+ assert result_dtype == expected_dtype
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_truncate.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ import pytest
4
+
5
+ import pandas as pd
6
+ from pandas import (
7
+ Series,
8
+ date_range,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+
13
+ class TestTruncate:
14
+ def test_truncate_datetimeindex_tz(self):
15
+ # GH 9243
16
+ idx = date_range("4/1/2005", "4/30/2005", freq="D", tz="US/Pacific")
17
+ s = Series(range(len(idx)), index=idx)
18
+ with pytest.raises(TypeError, match="Cannot compare tz-naive"):
19
+ # GH#36148 as of 2.0 we require tzawareness compat
20
+ s.truncate(datetime(2005, 4, 2), datetime(2005, 4, 4))
21
+
22
+ lb = idx[1]
23
+ ub = idx[3]
24
+ result = s.truncate(lb.to_pydatetime(), ub.to_pydatetime())
25
+ expected = Series([1, 2, 3], index=idx[1:4])
26
+ tm.assert_series_equal(result, expected)
27
+
28
+ def test_truncate_periodindex(self):
29
+ # GH 17717
30
+ idx1 = pd.PeriodIndex(
31
+ [pd.Period("2017-09-02"), pd.Period("2017-09-02"), pd.Period("2017-09-03")]
32
+ )
33
+ series1 = Series([1, 2, 3], index=idx1)
34
+ result1 = series1.truncate(after="2017-09-02")
35
+
36
+ expected_idx1 = pd.PeriodIndex(
37
+ [pd.Period("2017-09-02"), pd.Period("2017-09-02")]
38
+ )
39
+ tm.assert_series_equal(result1, Series([1, 2], index=expected_idx1))
40
+
41
+ idx2 = pd.PeriodIndex(
42
+ [pd.Period("2017-09-03"), pd.Period("2017-09-02"), pd.Period("2017-09-03")]
43
+ )
44
+ series2 = Series([1, 2, 3], index=idx2)
45
+ result2 = series2.sort_index().truncate(after="2017-09-02")
46
+
47
+ expected_idx2 = pd.PeriodIndex([pd.Period("2017-09-02")])
48
+ tm.assert_series_equal(result2, Series([2], index=expected_idx2))
49
+
50
+ def test_truncate_one_element_series(self):
51
+ # GH 35544
52
+ series = Series([0.1], index=pd.DatetimeIndex(["2020-08-04"]))
53
+ before = pd.Timestamp("2020-08-02")
54
+ after = pd.Timestamp("2020-08-04")
55
+
56
+ result = series.truncate(before=before, after=after)
57
+
58
+ # the input Series and the expected Series are the same
59
+ tm.assert_series_equal(result, series)
60
+
61
+ def test_truncate_index_only_one_unique_value(self):
62
+ # GH 42365
63
+ obj = Series(0, index=date_range("2021-06-30", "2021-06-30")).repeat(5)
64
+
65
+ truncated = obj.truncate("2021-06-28", "2021-07-01")
66
+
67
+ tm.assert_series_equal(truncated, obj)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_tz_localize.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import timezone
2
+
3
+ import pytest
4
+ import pytz
5
+
6
+ from pandas._libs.tslibs import timezones
7
+
8
+ from pandas import (
9
+ DatetimeIndex,
10
+ NaT,
11
+ Series,
12
+ Timestamp,
13
+ date_range,
14
+ )
15
+ import pandas._testing as tm
16
+
17
+
18
+ class TestTZLocalize:
19
+ def test_series_tz_localize_ambiguous_bool(self):
20
+ # make sure that we are correctly accepting bool values as ambiguous
21
+
22
+ # GH#14402
23
+ ts = Timestamp("2015-11-01 01:00:03")
24
+ expected0 = Timestamp("2015-11-01 01:00:03-0500", tz="US/Central")
25
+ expected1 = Timestamp("2015-11-01 01:00:03-0600", tz="US/Central")
26
+
27
+ ser = Series([ts])
28
+ expected0 = Series([expected0])
29
+ expected1 = Series([expected1])
30
+
31
+ with tm.external_error_raised(pytz.AmbiguousTimeError):
32
+ ser.dt.tz_localize("US/Central")
33
+
34
+ result = ser.dt.tz_localize("US/Central", ambiguous=True)
35
+ tm.assert_series_equal(result, expected0)
36
+
37
+ result = ser.dt.tz_localize("US/Central", ambiguous=[True])
38
+ tm.assert_series_equal(result, expected0)
39
+
40
+ result = ser.dt.tz_localize("US/Central", ambiguous=False)
41
+ tm.assert_series_equal(result, expected1)
42
+
43
+ result = ser.dt.tz_localize("US/Central", ambiguous=[False])
44
+ tm.assert_series_equal(result, expected1)
45
+
46
+ def test_series_tz_localize_matching_index(self):
47
+ # Matching the index of the result with that of the original series
48
+ # GH 43080
49
+ dt_series = Series(
50
+ date_range(start="2021-01-01T02:00:00", periods=5, freq="1D"),
51
+ index=[2, 6, 7, 8, 11],
52
+ dtype="category",
53
+ )
54
+ result = dt_series.dt.tz_localize("Europe/Berlin")
55
+ expected = Series(
56
+ date_range(
57
+ start="2021-01-01T02:00:00", periods=5, freq="1D", tz="Europe/Berlin"
58
+ ),
59
+ index=[2, 6, 7, 8, 11],
60
+ )
61
+ tm.assert_series_equal(result, expected)
62
+
63
+ @pytest.mark.parametrize(
64
+ "method, exp",
65
+ [
66
+ ["shift_forward", "2015-03-29 03:00:00"],
67
+ ["shift_backward", "2015-03-29 01:59:59.999999999"],
68
+ ["NaT", NaT],
69
+ ["raise", None],
70
+ ["foo", "invalid"],
71
+ ],
72
+ )
73
+ def test_tz_localize_nonexistent(self, warsaw, method, exp, unit):
74
+ # GH 8917
75
+ tz = warsaw
76
+ n = 60
77
+ dti = date_range(start="2015-03-29 02:00:00", periods=n, freq="min", unit=unit)
78
+ ser = Series(1, index=dti)
79
+ df = ser.to_frame()
80
+
81
+ if method == "raise":
82
+ with tm.external_error_raised(pytz.NonExistentTimeError):
83
+ dti.tz_localize(tz, nonexistent=method)
84
+ with tm.external_error_raised(pytz.NonExistentTimeError):
85
+ ser.tz_localize(tz, nonexistent=method)
86
+ with tm.external_error_raised(pytz.NonExistentTimeError):
87
+ df.tz_localize(tz, nonexistent=method)
88
+
89
+ elif exp == "invalid":
90
+ msg = (
91
+ "The nonexistent argument must be one of "
92
+ "'raise', 'NaT', 'shift_forward', 'shift_backward' "
93
+ "or a timedelta object"
94
+ )
95
+ with pytest.raises(ValueError, match=msg):
96
+ dti.tz_localize(tz, nonexistent=method)
97
+ with pytest.raises(ValueError, match=msg):
98
+ ser.tz_localize(tz, nonexistent=method)
99
+ with pytest.raises(ValueError, match=msg):
100
+ df.tz_localize(tz, nonexistent=method)
101
+
102
+ else:
103
+ result = ser.tz_localize(tz, nonexistent=method)
104
+ expected = Series(1, index=DatetimeIndex([exp] * n, tz=tz).as_unit(unit))
105
+ tm.assert_series_equal(result, expected)
106
+
107
+ result = df.tz_localize(tz, nonexistent=method)
108
+ expected = expected.to_frame()
109
+ tm.assert_frame_equal(result, expected)
110
+
111
+ res_index = dti.tz_localize(tz, nonexistent=method)
112
+ tm.assert_index_equal(res_index, expected.index)
113
+
114
+ @pytest.mark.parametrize("tzstr", ["US/Eastern", "dateutil/US/Eastern"])
115
+ def test_series_tz_localize_empty(self, tzstr):
116
+ # GH#2248
117
+ ser = Series(dtype=object)
118
+
119
+ ser2 = ser.tz_localize("utc")
120
+ assert ser2.index.tz == timezone.utc
121
+
122
+ ser2 = ser.tz_localize(tzstr)
123
+ timezones.tz_compare(ser2.index.tz, timezones.maybe_get_tz(tzstr))
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_unique.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ from pandas import (
4
+ Categorical,
5
+ IntervalIndex,
6
+ Series,
7
+ date_range,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ class TestUnique:
13
+ def test_unique_uint64(self):
14
+ ser = Series([1, 2, 2**63, 2**63], dtype=np.uint64)
15
+ res = ser.unique()
16
+ exp = np.array([1, 2, 2**63], dtype=np.uint64)
17
+ tm.assert_numpy_array_equal(res, exp)
18
+
19
+ def test_unique_data_ownership(self):
20
+ # it works! GH#1807
21
+ Series(Series(["a", "c", "b"]).unique()).sort_values()
22
+
23
+ def test_unique(self):
24
+ # GH#714 also, dtype=float
25
+ ser = Series([1.2345] * 100)
26
+ ser[::2] = np.nan
27
+ result = ser.unique()
28
+ assert len(result) == 2
29
+
30
+ # explicit f4 dtype
31
+ ser = Series([1.2345] * 100, dtype="f4")
32
+ ser[::2] = np.nan
33
+ result = ser.unique()
34
+ assert len(result) == 2
35
+
36
+ def test_unique_nan_object_dtype(self):
37
+ # NAs in object arrays GH#714
38
+ ser = Series(["foo"] * 100, dtype="O")
39
+ ser[::2] = np.nan
40
+ result = ser.unique()
41
+ assert len(result) == 2
42
+
43
+ def test_unique_none(self):
44
+ # decision about None
45
+ ser = Series([1, 2, 3, None, None, None], dtype=object)
46
+ result = ser.unique()
47
+ expected = np.array([1, 2, 3, None], dtype=object)
48
+ tm.assert_numpy_array_equal(result, expected)
49
+
50
+ def test_unique_categorical(self):
51
+ # GH#18051
52
+ cat = Categorical([])
53
+ ser = Series(cat)
54
+ result = ser.unique()
55
+ tm.assert_categorical_equal(result, cat)
56
+
57
+ cat = Categorical([np.nan])
58
+ ser = Series(cat)
59
+ result = ser.unique()
60
+ tm.assert_categorical_equal(result, cat)
61
+
62
+ def test_tz_unique(self):
63
+ # GH 46128
64
+ dti1 = date_range("2016-01-01", periods=3)
65
+ ii1 = IntervalIndex.from_breaks(dti1)
66
+ ser1 = Series(ii1)
67
+ uni1 = ser1.unique()
68
+ tm.assert_interval_array_equal(ser1.array, uni1)
69
+
70
+ dti2 = date_range("2016-01-01", periods=3, tz="US/Eastern")
71
+ ii2 = IntervalIndex.from_breaks(dti2)
72
+ ser2 = Series(ii2)
73
+ uni2 = ser2.unique()
74
+ tm.assert_interval_array_equal(ser2.array, uni2)
75
+
76
+ assert uni1.dtype != uni2.dtype
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_unstack.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ DataFrame,
7
+ Index,
8
+ MultiIndex,
9
+ Series,
10
+ date_range,
11
+ )
12
+ import pandas._testing as tm
13
+
14
+
15
+ def test_unstack_preserves_object():
16
+ mi = MultiIndex.from_product([["bar", "foo"], ["one", "two"]])
17
+
18
+ ser = Series(np.arange(4.0), index=mi, dtype=object)
19
+
20
+ res1 = ser.unstack()
21
+ assert (res1.dtypes == object).all()
22
+
23
+ res2 = ser.unstack(level=0)
24
+ assert (res2.dtypes == object).all()
25
+
26
+
27
+ def test_unstack():
28
+ index = MultiIndex(
29
+ levels=[["bar", "foo"], ["one", "three", "two"]],
30
+ codes=[[1, 1, 0, 0], [0, 1, 0, 2]],
31
+ )
32
+
33
+ s = Series(np.arange(4.0), index=index)
34
+ unstacked = s.unstack()
35
+
36
+ expected = DataFrame(
37
+ [[2.0, np.nan, 3.0], [0.0, 1.0, np.nan]],
38
+ index=["bar", "foo"],
39
+ columns=["one", "three", "two"],
40
+ )
41
+
42
+ tm.assert_frame_equal(unstacked, expected)
43
+
44
+ unstacked = s.unstack(level=0)
45
+ tm.assert_frame_equal(unstacked, expected.T)
46
+
47
+ index = MultiIndex(
48
+ levels=[["bar"], ["one", "two", "three"], [0, 1]],
49
+ codes=[[0, 0, 0, 0, 0, 0], [0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1]],
50
+ )
51
+ s = Series(np.random.default_rng(2).standard_normal(6), index=index)
52
+ exp_index = MultiIndex(
53
+ levels=[["one", "two", "three"], [0, 1]],
54
+ codes=[[0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1]],
55
+ )
56
+ expected = DataFrame({"bar": s.values}, index=exp_index).sort_index(level=0)
57
+ unstacked = s.unstack(0).sort_index()
58
+ tm.assert_frame_equal(unstacked, expected)
59
+
60
+ # GH5873
61
+ idx = MultiIndex.from_arrays([[101, 102], [3.5, np.nan]])
62
+ ts = Series([1, 2], index=idx)
63
+ left = ts.unstack()
64
+ right = DataFrame(
65
+ [[np.nan, 1], [2, np.nan]], index=[101, 102], columns=[np.nan, 3.5]
66
+ )
67
+ tm.assert_frame_equal(left, right)
68
+
69
+ idx = MultiIndex.from_arrays(
70
+ [
71
+ ["cat", "cat", "cat", "dog", "dog"],
72
+ ["a", "a", "b", "a", "b"],
73
+ [1, 2, 1, 1, np.nan],
74
+ ]
75
+ )
76
+ ts = Series([1.0, 1.1, 1.2, 1.3, 1.4], index=idx)
77
+ right = DataFrame(
78
+ [[1.0, 1.3], [1.1, np.nan], [np.nan, 1.4], [1.2, np.nan]],
79
+ columns=["cat", "dog"],
80
+ )
81
+ tpls = [("a", 1), ("a", 2), ("b", np.nan), ("b", 1)]
82
+ right.index = MultiIndex.from_tuples(tpls)
83
+ tm.assert_frame_equal(ts.unstack(level=0), right)
84
+
85
+
86
+ def test_unstack_tuplename_in_multiindex():
87
+ # GH 19966
88
+ idx = MultiIndex.from_product(
89
+ [["a", "b", "c"], [1, 2, 3]], names=[("A", "a"), ("B", "b")]
90
+ )
91
+ ser = Series(1, index=idx)
92
+ result = ser.unstack(("A", "a"))
93
+
94
+ expected = DataFrame(
95
+ [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
96
+ columns=MultiIndex.from_tuples([("a",), ("b",), ("c",)], names=[("A", "a")]),
97
+ index=Index([1, 2, 3], name=("B", "b")),
98
+ )
99
+ tm.assert_frame_equal(result, expected)
100
+
101
+
102
+ @pytest.mark.parametrize(
103
+ "unstack_idx, expected_values, expected_index, expected_columns",
104
+ [
105
+ (
106
+ ("A", "a"),
107
+ [[1, 1], [1, 1], [1, 1], [1, 1]],
108
+ MultiIndex.from_tuples([(1, 3), (1, 4), (2, 3), (2, 4)], names=["B", "C"]),
109
+ MultiIndex.from_tuples([("a",), ("b",)], names=[("A", "a")]),
110
+ ),
111
+ (
112
+ (("A", "a"), "B"),
113
+ [[1, 1, 1, 1], [1, 1, 1, 1]],
114
+ Index([3, 4], name="C"),
115
+ MultiIndex.from_tuples(
116
+ [("a", 1), ("a", 2), ("b", 1), ("b", 2)], names=[("A", "a"), "B"]
117
+ ),
118
+ ),
119
+ ],
120
+ )
121
+ def test_unstack_mixed_type_name_in_multiindex(
122
+ unstack_idx, expected_values, expected_index, expected_columns
123
+ ):
124
+ # GH 19966
125
+ idx = MultiIndex.from_product(
126
+ [["a", "b"], [1, 2], [3, 4]], names=[("A", "a"), "B", "C"]
127
+ )
128
+ ser = Series(1, index=idx)
129
+ result = ser.unstack(unstack_idx)
130
+
131
+ expected = DataFrame(
132
+ expected_values, columns=expected_columns, index=expected_index
133
+ )
134
+ tm.assert_frame_equal(result, expected)
135
+
136
+
137
+ def test_unstack_multi_index_categorical_values():
138
+ df = DataFrame(
139
+ np.random.default_rng(2).standard_normal((10, 4)),
140
+ columns=Index(list("ABCD")),
141
+ index=date_range("2000-01-01", periods=10, freq="B"),
142
+ )
143
+ mi = df.stack(future_stack=True).index.rename(["major", "minor"])
144
+ ser = Series(["foo"] * len(mi), index=mi, name="category", dtype="category")
145
+
146
+ result = ser.unstack()
147
+
148
+ dti = ser.index.levels[0]
149
+ c = pd.Categorical(["foo"] * len(dti))
150
+ expected = DataFrame(
151
+ {"A": c.copy(), "B": c.copy(), "C": c.copy(), "D": c.copy()},
152
+ columns=Index(list("ABCD"), name="minor"),
153
+ index=dti.rename("major"),
154
+ )
155
+ tm.assert_frame_equal(result, expected)
156
+
157
+
158
+ def test_unstack_mixed_level_names():
159
+ # GH#48763
160
+ arrays = [["a", "a"], [1, 2], ["red", "blue"]]
161
+ idx = MultiIndex.from_arrays(arrays, names=("x", 0, "y"))
162
+ ser = Series([1, 2], index=idx)
163
+ result = ser.unstack("x")
164
+ expected = DataFrame(
165
+ [[1], [2]],
166
+ columns=Index(["a"], name="x"),
167
+ index=MultiIndex.from_tuples([(1, "red"), (2, "blue")], names=[0, "y"]),
168
+ )
169
+ tm.assert_frame_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_update.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas.compat import WARNING_CHECK_DISABLED
5
+ import pandas.util._test_decorators as td
6
+
7
+ from pandas import (
8
+ CategoricalDtype,
9
+ DataFrame,
10
+ NaT,
11
+ Series,
12
+ Timestamp,
13
+ )
14
+ import pandas._testing as tm
15
+
16
+
17
+ class TestUpdate:
18
+ def test_update(self, using_copy_on_write):
19
+ s = Series([1.5, np.nan, 3.0, 4.0, np.nan])
20
+ s2 = Series([np.nan, 3.5, np.nan, 5.0])
21
+ s.update(s2)
22
+
23
+ expected = Series([1.5, 3.5, 3.0, 5.0, np.nan])
24
+ tm.assert_series_equal(s, expected)
25
+
26
+ # GH 3217
27
+ df = DataFrame([{"a": 1}, {"a": 3, "b": 2}])
28
+ df["c"] = np.nan
29
+ # Cast to object to avoid upcast when setting "foo"
30
+ df["c"] = df["c"].astype(object)
31
+ df_orig = df.copy()
32
+
33
+ if using_copy_on_write:
34
+ with tm.raises_chained_assignment_error():
35
+ df["c"].update(Series(["foo"], index=[0]))
36
+ expected = df_orig
37
+ else:
38
+ with tm.assert_produces_warning(
39
+ FutureWarning if not WARNING_CHECK_DISABLED else None,
40
+ match="inplace method",
41
+ ):
42
+ df["c"].update(Series(["foo"], index=[0]))
43
+ expected = DataFrame(
44
+ [[1, np.nan, "foo"], [3, 2.0, np.nan]], columns=["a", "b", "c"]
45
+ )
46
+ expected["c"] = expected["c"].astype(object)
47
+ tm.assert_frame_equal(df, expected)
48
+
49
+ @pytest.mark.parametrize(
50
+ "other, dtype, expected, warn",
51
+ [
52
+ # other is int
53
+ ([61, 63], "int32", Series([10, 61, 12], dtype="int32"), None),
54
+ ([61, 63], "int64", Series([10, 61, 12]), None),
55
+ ([61, 63], float, Series([10.0, 61.0, 12.0]), None),
56
+ ([61, 63], object, Series([10, 61, 12], dtype=object), None),
57
+ # other is float, but can be cast to int
58
+ ([61.0, 63.0], "int32", Series([10, 61, 12], dtype="int32"), None),
59
+ ([61.0, 63.0], "int64", Series([10, 61, 12]), None),
60
+ ([61.0, 63.0], float, Series([10.0, 61.0, 12.0]), None),
61
+ ([61.0, 63.0], object, Series([10, 61.0, 12], dtype=object), None),
62
+ # others is float, cannot be cast to int
63
+ ([61.1, 63.1], "int32", Series([10.0, 61.1, 12.0]), FutureWarning),
64
+ ([61.1, 63.1], "int64", Series([10.0, 61.1, 12.0]), FutureWarning),
65
+ ([61.1, 63.1], float, Series([10.0, 61.1, 12.0]), None),
66
+ ([61.1, 63.1], object, Series([10, 61.1, 12], dtype=object), None),
67
+ # other is object, cannot be cast
68
+ ([(61,), (63,)], "int32", Series([10, (61,), 12]), FutureWarning),
69
+ ([(61,), (63,)], "int64", Series([10, (61,), 12]), FutureWarning),
70
+ ([(61,), (63,)], float, Series([10.0, (61,), 12.0]), FutureWarning),
71
+ ([(61,), (63,)], object, Series([10, (61,), 12]), None),
72
+ ],
73
+ )
74
+ def test_update_dtypes(self, other, dtype, expected, warn):
75
+ ser = Series([10, 11, 12], dtype=dtype)
76
+ other = Series(other, index=[1, 3])
77
+ with tm.assert_produces_warning(warn, match="item of incompatible dtype"):
78
+ ser.update(other)
79
+
80
+ tm.assert_series_equal(ser, expected)
81
+
82
+ @pytest.mark.parametrize(
83
+ "series, other, expected",
84
+ [
85
+ # update by key
86
+ (
87
+ Series({"a": 1, "b": 2, "c": 3, "d": 4}),
88
+ {"b": 5, "c": np.nan},
89
+ Series({"a": 1, "b": 5, "c": 3, "d": 4}),
90
+ ),
91
+ # update by position
92
+ (Series([1, 2, 3, 4]), [np.nan, 5, 1], Series([1, 5, 1, 4])),
93
+ ],
94
+ )
95
+ def test_update_from_non_series(self, series, other, expected):
96
+ # GH 33215
97
+ series.update(other)
98
+ tm.assert_series_equal(series, expected)
99
+
100
+ @pytest.mark.parametrize(
101
+ "data, other, expected, dtype",
102
+ [
103
+ (["a", None], [None, "b"], ["a", "b"], "string[python]"),
104
+ pytest.param(
105
+ ["a", None],
106
+ [None, "b"],
107
+ ["a", "b"],
108
+ "string[pyarrow]",
109
+ marks=td.skip_if_no("pyarrow"),
110
+ ),
111
+ ([1, None], [None, 2], [1, 2], "Int64"),
112
+ ([True, None], [None, False], [True, False], "boolean"),
113
+ (
114
+ ["a", None],
115
+ [None, "b"],
116
+ ["a", "b"],
117
+ CategoricalDtype(categories=["a", "b"]),
118
+ ),
119
+ (
120
+ [Timestamp(year=2020, month=1, day=1, tz="Europe/London"), NaT],
121
+ [NaT, Timestamp(year=2020, month=1, day=1, tz="Europe/London")],
122
+ [Timestamp(year=2020, month=1, day=1, tz="Europe/London")] * 2,
123
+ "datetime64[ns, Europe/London]",
124
+ ),
125
+ ],
126
+ )
127
+ def test_update_extension_array_series(self, data, other, expected, dtype):
128
+ result = Series(data, dtype=dtype)
129
+ other = Series(other, dtype=dtype)
130
+ expected = Series(expected, dtype=dtype)
131
+
132
+ result.update(other)
133
+ tm.assert_series_equal(result, expected)
134
+
135
+ def test_update_with_categorical_type(self):
136
+ # GH 25744
137
+ dtype = CategoricalDtype(["a", "b", "c", "d"])
138
+ s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=dtype)
139
+ s2 = Series(["b", "a"], index=[1, 2], dtype=dtype)
140
+ s1.update(s2)
141
+ result = s1
142
+ expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype)
143
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_value_counts.py ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ import pandas as pd
5
+ from pandas import (
6
+ Categorical,
7
+ CategoricalIndex,
8
+ Index,
9
+ Series,
10
+ )
11
+ import pandas._testing as tm
12
+
13
+
14
+ class TestSeriesValueCounts:
15
+ def test_value_counts_datetime(self, unit):
16
+ # most dtypes are tested in tests/base
17
+ values = [
18
+ pd.Timestamp("2011-01-01 09:00"),
19
+ pd.Timestamp("2011-01-01 10:00"),
20
+ pd.Timestamp("2011-01-01 11:00"),
21
+ pd.Timestamp("2011-01-01 09:00"),
22
+ pd.Timestamp("2011-01-01 09:00"),
23
+ pd.Timestamp("2011-01-01 11:00"),
24
+ ]
25
+
26
+ exp_idx = pd.DatetimeIndex(
27
+ ["2011-01-01 09:00", "2011-01-01 11:00", "2011-01-01 10:00"],
28
+ name="xxx",
29
+ ).as_unit(unit)
30
+ exp = Series([3, 2, 1], index=exp_idx, name="count")
31
+
32
+ ser = Series(values, name="xxx").dt.as_unit(unit)
33
+ tm.assert_series_equal(ser.value_counts(), exp)
34
+ # check DatetimeIndex outputs the same result
35
+ idx = pd.DatetimeIndex(values, name="xxx").as_unit(unit)
36
+ tm.assert_series_equal(idx.value_counts(), exp)
37
+
38
+ # normalize
39
+ exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="proportion")
40
+ tm.assert_series_equal(ser.value_counts(normalize=True), exp)
41
+ tm.assert_series_equal(idx.value_counts(normalize=True), exp)
42
+
43
+ def test_value_counts_datetime_tz(self, unit):
44
+ values = [
45
+ pd.Timestamp("2011-01-01 09:00", tz="US/Eastern"),
46
+ pd.Timestamp("2011-01-01 10:00", tz="US/Eastern"),
47
+ pd.Timestamp("2011-01-01 11:00", tz="US/Eastern"),
48
+ pd.Timestamp("2011-01-01 09:00", tz="US/Eastern"),
49
+ pd.Timestamp("2011-01-01 09:00", tz="US/Eastern"),
50
+ pd.Timestamp("2011-01-01 11:00", tz="US/Eastern"),
51
+ ]
52
+
53
+ exp_idx = pd.DatetimeIndex(
54
+ ["2011-01-01 09:00", "2011-01-01 11:00", "2011-01-01 10:00"],
55
+ tz="US/Eastern",
56
+ name="xxx",
57
+ ).as_unit(unit)
58
+ exp = Series([3, 2, 1], index=exp_idx, name="count")
59
+
60
+ ser = Series(values, name="xxx").dt.as_unit(unit)
61
+ tm.assert_series_equal(ser.value_counts(), exp)
62
+ idx = pd.DatetimeIndex(values, name="xxx").as_unit(unit)
63
+ tm.assert_series_equal(idx.value_counts(), exp)
64
+
65
+ exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="proportion")
66
+ tm.assert_series_equal(ser.value_counts(normalize=True), exp)
67
+ tm.assert_series_equal(idx.value_counts(normalize=True), exp)
68
+
69
+ def test_value_counts_period(self):
70
+ values = [
71
+ pd.Period("2011-01", freq="M"),
72
+ pd.Period("2011-02", freq="M"),
73
+ pd.Period("2011-03", freq="M"),
74
+ pd.Period("2011-01", freq="M"),
75
+ pd.Period("2011-01", freq="M"),
76
+ pd.Period("2011-03", freq="M"),
77
+ ]
78
+
79
+ exp_idx = pd.PeriodIndex(
80
+ ["2011-01", "2011-03", "2011-02"], freq="M", name="xxx"
81
+ )
82
+ exp = Series([3, 2, 1], index=exp_idx, name="count")
83
+
84
+ ser = Series(values, name="xxx")
85
+ tm.assert_series_equal(ser.value_counts(), exp)
86
+ # check DatetimeIndex outputs the same result
87
+ idx = pd.PeriodIndex(values, name="xxx")
88
+ tm.assert_series_equal(idx.value_counts(), exp)
89
+
90
+ # normalize
91
+ exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="proportion")
92
+ tm.assert_series_equal(ser.value_counts(normalize=True), exp)
93
+ tm.assert_series_equal(idx.value_counts(normalize=True), exp)
94
+
95
+ def test_value_counts_categorical_ordered(self):
96
+ # most dtypes are tested in tests/base
97
+ values = Categorical([1, 2, 3, 1, 1, 3], ordered=True)
98
+
99
+ exp_idx = CategoricalIndex(
100
+ [1, 3, 2], categories=[1, 2, 3], ordered=True, name="xxx"
101
+ )
102
+ exp = Series([3, 2, 1], index=exp_idx, name="count")
103
+
104
+ ser = Series(values, name="xxx")
105
+ tm.assert_series_equal(ser.value_counts(), exp)
106
+ # check CategoricalIndex outputs the same result
107
+ idx = CategoricalIndex(values, name="xxx")
108
+ tm.assert_series_equal(idx.value_counts(), exp)
109
+
110
+ # normalize
111
+ exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="proportion")
112
+ tm.assert_series_equal(ser.value_counts(normalize=True), exp)
113
+ tm.assert_series_equal(idx.value_counts(normalize=True), exp)
114
+
115
+ def test_value_counts_categorical_not_ordered(self):
116
+ values = Categorical([1, 2, 3, 1, 1, 3], ordered=False)
117
+
118
+ exp_idx = CategoricalIndex(
119
+ [1, 3, 2], categories=[1, 2, 3], ordered=False, name="xxx"
120
+ )
121
+ exp = Series([3, 2, 1], index=exp_idx, name="count")
122
+
123
+ ser = Series(values, name="xxx")
124
+ tm.assert_series_equal(ser.value_counts(), exp)
125
+ # check CategoricalIndex outputs the same result
126
+ idx = CategoricalIndex(values, name="xxx")
127
+ tm.assert_series_equal(idx.value_counts(), exp)
128
+
129
+ # normalize
130
+ exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="proportion")
131
+ tm.assert_series_equal(ser.value_counts(normalize=True), exp)
132
+ tm.assert_series_equal(idx.value_counts(normalize=True), exp)
133
+
134
+ def test_value_counts_categorical(self):
135
+ # GH#12835
136
+ cats = Categorical(list("abcccb"), categories=list("cabd"))
137
+ ser = Series(cats, name="xxx")
138
+ res = ser.value_counts(sort=False)
139
+
140
+ exp_index = CategoricalIndex(
141
+ list("cabd"), categories=cats.categories, name="xxx"
142
+ )
143
+ exp = Series([3, 1, 2, 0], name="count", index=exp_index)
144
+ tm.assert_series_equal(res, exp)
145
+
146
+ res = ser.value_counts(sort=True)
147
+
148
+ exp_index = CategoricalIndex(
149
+ list("cbad"), categories=cats.categories, name="xxx"
150
+ )
151
+ exp = Series([3, 2, 1, 0], name="count", index=exp_index)
152
+ tm.assert_series_equal(res, exp)
153
+
154
+ # check object dtype handles the Series.name as the same
155
+ # (tested in tests/base)
156
+ ser = Series(["a", "b", "c", "c", "c", "b"], name="xxx")
157
+ res = ser.value_counts()
158
+ exp = Series([3, 2, 1], name="count", index=Index(["c", "b", "a"], name="xxx"))
159
+ tm.assert_series_equal(res, exp)
160
+
161
+ def test_value_counts_categorical_with_nan(self):
162
+ # see GH#9443
163
+
164
+ # sanity check
165
+ ser = Series(["a", "b", "a"], dtype="category")
166
+ exp = Series([2, 1], index=CategoricalIndex(["a", "b"]), name="count")
167
+
168
+ res = ser.value_counts(dropna=True)
169
+ tm.assert_series_equal(res, exp)
170
+
171
+ res = ser.value_counts(dropna=True)
172
+ tm.assert_series_equal(res, exp)
173
+
174
+ # same Series via two different constructions --> same behaviour
175
+ series = [
176
+ Series(["a", "b", None, "a", None, None], dtype="category"),
177
+ Series(
178
+ Categorical(["a", "b", None, "a", None, None], categories=["a", "b"])
179
+ ),
180
+ ]
181
+
182
+ for ser in series:
183
+ # None is a NaN value, so we exclude its count here
184
+ exp = Series([2, 1], index=CategoricalIndex(["a", "b"]), name="count")
185
+ res = ser.value_counts(dropna=True)
186
+ tm.assert_series_equal(res, exp)
187
+
188
+ # we don't exclude the count of None and sort by counts
189
+ exp = Series(
190
+ [3, 2, 1], index=CategoricalIndex([np.nan, "a", "b"]), name="count"
191
+ )
192
+ res = ser.value_counts(dropna=False)
193
+ tm.assert_series_equal(res, exp)
194
+
195
+ # When we aren't sorting by counts, and np.nan isn't a
196
+ # category, it should be last.
197
+ exp = Series(
198
+ [2, 1, 3], index=CategoricalIndex(["a", "b", np.nan]), name="count"
199
+ )
200
+ res = ser.value_counts(dropna=False, sort=False)
201
+ tm.assert_series_equal(res, exp)
202
+
203
+ @pytest.mark.parametrize(
204
+ "ser, dropna, exp",
205
+ [
206
+ (
207
+ Series([False, True, True, pd.NA]),
208
+ False,
209
+ Series([2, 1, 1], index=[True, False, pd.NA], name="count"),
210
+ ),
211
+ (
212
+ Series([False, True, True, pd.NA]),
213
+ True,
214
+ Series([2, 1], index=Index([True, False], dtype=object), name="count"),
215
+ ),
216
+ (
217
+ Series(range(3), index=[True, False, np.nan]).index,
218
+ False,
219
+ Series([1, 1, 1], index=[True, False, np.nan], name="count"),
220
+ ),
221
+ ],
222
+ )
223
+ def test_value_counts_bool_with_nan(self, ser, dropna, exp):
224
+ # GH32146
225
+ out = ser.value_counts(dropna=dropna)
226
+ tm.assert_series_equal(out, exp)
227
+
228
+ @pytest.mark.parametrize(
229
+ "input_array,expected",
230
+ [
231
+ (
232
+ [1 + 1j, 1 + 1j, 1, 3j, 3j, 3j],
233
+ Series(
234
+ [3, 2, 1],
235
+ index=Index([3j, 1 + 1j, 1], dtype=np.complex128),
236
+ name="count",
237
+ ),
238
+ ),
239
+ (
240
+ np.array([1 + 1j, 1 + 1j, 1, 3j, 3j, 3j], dtype=np.complex64),
241
+ Series(
242
+ [3, 2, 1],
243
+ index=Index([3j, 1 + 1j, 1], dtype=np.complex64),
244
+ name="count",
245
+ ),
246
+ ),
247
+ ],
248
+ )
249
+ def test_value_counts_complex_numbers(self, input_array, expected):
250
+ # GH 17927
251
+ result = Series(input_array).value_counts()
252
+ tm.assert_series_equal(result, expected)
253
+
254
+ def test_value_counts_masked(self):
255
+ # GH#54984
256
+ dtype = "Int64"
257
+ ser = Series([1, 2, None, 2, None, 3], dtype=dtype)
258
+ result = ser.value_counts(dropna=False)
259
+ expected = Series(
260
+ [2, 2, 1, 1],
261
+ index=Index([2, None, 1, 3], dtype=dtype),
262
+ dtype=dtype,
263
+ name="count",
264
+ )
265
+ tm.assert_series_equal(result, expected)
266
+
267
+ result = ser.value_counts(dropna=True)
268
+ expected = Series(
269
+ [2, 1, 1], index=Index([2, 1, 3], dtype=dtype), dtype=dtype, name="count"
270
+ )
271
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_values.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ IntervalIndex,
6
+ Series,
7
+ period_range,
8
+ )
9
+ import pandas._testing as tm
10
+
11
+
12
+ class TestValues:
13
+ @pytest.mark.parametrize(
14
+ "data",
15
+ [
16
+ period_range("2000", periods=4),
17
+ IntervalIndex.from_breaks([1, 2, 3, 4]),
18
+ ],
19
+ )
20
+ def test_values_object_extension_dtypes(self, data):
21
+ # https://github.com/pandas-dev/pandas/issues/23995
22
+ result = Series(data).values
23
+ expected = np.array(data.astype(object))
24
+ tm.assert_numpy_array_equal(result, expected)
25
+
26
+ def test_values(self, datetime_series):
27
+ tm.assert_almost_equal(
28
+ datetime_series.values, list(datetime_series), check_dtype=False
29
+ )
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/series/methods/test_view.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ Index,
6
+ Series,
7
+ array,
8
+ date_range,
9
+ )
10
+ import pandas._testing as tm
11
+
12
+ pytestmark = pytest.mark.filterwarnings(
13
+ "ignore:Series.view is deprecated and will be removed in a future version.:FutureWarning" # noqa: E501
14
+ )
15
+
16
+
17
+ class TestView:
18
+ def test_view_i8_to_datetimelike(self):
19
+ dti = date_range("2000", periods=4, tz="US/Central")
20
+ ser = Series(dti.asi8)
21
+
22
+ result = ser.view(dti.dtype)
23
+ tm.assert_datetime_array_equal(result._values, dti._data._with_freq(None))
24
+
25
+ pi = dti.tz_localize(None).to_period("D")
26
+ ser = Series(pi.asi8)
27
+ result = ser.view(pi.dtype)
28
+ tm.assert_period_array_equal(result._values, pi._data)
29
+
30
+ def test_view_tz(self):
31
+ # GH#24024
32
+ ser = Series(date_range("2000", periods=4, tz="US/Central"))
33
+ result = ser.view("i8")
34
+ expected = Series(
35
+ [
36
+ 946706400000000000,
37
+ 946792800000000000,
38
+ 946879200000000000,
39
+ 946965600000000000,
40
+ ]
41
+ )
42
+ tm.assert_series_equal(result, expected)
43
+
44
+ @pytest.mark.parametrize(
45
+ "first", ["m8[ns]", "M8[ns]", "M8[ns, US/Central]", "period[D]"]
46
+ )
47
+ @pytest.mark.parametrize(
48
+ "second", ["m8[ns]", "M8[ns]", "M8[ns, US/Central]", "period[D]"]
49
+ )
50
+ @pytest.mark.parametrize("box", [Series, Index, array])
51
+ def test_view_between_datetimelike(self, first, second, box):
52
+ dti = date_range("2016-01-01", periods=3)
53
+
54
+ orig = box(dti)
55
+ obj = orig.view(first)
56
+ assert obj.dtype == first
57
+ tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8)
58
+
59
+ res = obj.view(second)
60
+ assert res.dtype == second
61
+ tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/__init__.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ import pandas as pd
4
+
5
+
6
+ def is_object_or_nan_string_dtype(dtype):
7
+ """
8
+ Check if string-like dtype is following NaN semantics, i.e. is object
9
+ dtype or a NaN-variant of the StringDtype.
10
+ """
11
+ return (isinstance(dtype, np.dtype) and dtype == "object") or (
12
+ dtype.na_value is np.nan
13
+ )
14
+
15
+
16
+ def _convert_na_value(ser, expected):
17
+ if ser.dtype != object:
18
+ if ser.dtype.na_value is np.nan:
19
+ expected = expected.fillna(np.nan)
20
+ else:
21
+ # GH#18463
22
+ expected = expected.fillna(pd.NA)
23
+ return expected
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/conftest.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+
3
+ from pandas import Series
4
+ from pandas.core.strings.accessor import StringMethods
5
+
6
+ _any_string_method = [
7
+ ("cat", (), {"sep": ","}),
8
+ ("cat", (Series(list("zyx")),), {"sep": ",", "join": "left"}),
9
+ ("center", (10,), {}),
10
+ ("contains", ("a",), {}),
11
+ ("count", ("a",), {}),
12
+ ("decode", ("UTF-8",), {}),
13
+ ("encode", ("UTF-8",), {}),
14
+ ("endswith", ("a",), {}),
15
+ ("endswith", ((),), {}),
16
+ ("endswith", (("a",),), {}),
17
+ ("endswith", (("a", "b"),), {}),
18
+ ("endswith", (("a", "MISSING"),), {}),
19
+ ("endswith", ("a",), {"na": True}),
20
+ ("endswith", ("a",), {"na": False}),
21
+ ("extract", ("([a-z]*)",), {"expand": False}),
22
+ ("extract", ("([a-z]*)",), {"expand": True}),
23
+ ("extractall", ("([a-z]*)",), {}),
24
+ ("find", ("a",), {}),
25
+ ("findall", ("a",), {}),
26
+ ("get", (0,), {}),
27
+ # because "index" (and "rindex") fail intentionally
28
+ # if the string is not found, search only for empty string
29
+ ("index", ("",), {}),
30
+ ("join", (",",), {}),
31
+ ("ljust", (10,), {}),
32
+ ("match", ("a",), {}),
33
+ ("fullmatch", ("a",), {}),
34
+ ("normalize", ("NFC",), {}),
35
+ ("pad", (10,), {}),
36
+ ("partition", (" ",), {"expand": False}),
37
+ ("partition", (" ",), {"expand": True}),
38
+ ("repeat", (3,), {}),
39
+ ("replace", ("a", "z"), {}),
40
+ ("rfind", ("a",), {}),
41
+ ("rindex", ("",), {}),
42
+ ("rjust", (10,), {}),
43
+ ("rpartition", (" ",), {"expand": False}),
44
+ ("rpartition", (" ",), {"expand": True}),
45
+ ("slice", (0, 1), {}),
46
+ ("slice_replace", (0, 1, "z"), {}),
47
+ ("split", (" ",), {"expand": False}),
48
+ ("split", (" ",), {"expand": True}),
49
+ ("startswith", ("a",), {}),
50
+ ("startswith", (("a",),), {}),
51
+ ("startswith", (("a", "b"),), {}),
52
+ ("startswith", (("a", "MISSING"),), {}),
53
+ ("startswith", ((),), {}),
54
+ ("startswith", ("a",), {"na": True}),
55
+ ("startswith", ("a",), {"na": False}),
56
+ ("removeprefix", ("a",), {}),
57
+ ("removesuffix", ("a",), {}),
58
+ # translating unicode points of "a" to "d"
59
+ ("translate", ({97: 100},), {}),
60
+ ("wrap", (2,), {}),
61
+ ("zfill", (10,), {}),
62
+ ] + list(
63
+ zip(
64
+ [
65
+ # methods without positional arguments: zip with empty tuple and empty dict
66
+ "capitalize",
67
+ "cat",
68
+ "get_dummies",
69
+ "isalnum",
70
+ "isalpha",
71
+ "isdecimal",
72
+ "isdigit",
73
+ "islower",
74
+ "isnumeric",
75
+ "isspace",
76
+ "istitle",
77
+ "isupper",
78
+ "len",
79
+ "lower",
80
+ "lstrip",
81
+ "partition",
82
+ "rpartition",
83
+ "rsplit",
84
+ "rstrip",
85
+ "slice",
86
+ "slice_replace",
87
+ "split",
88
+ "strip",
89
+ "swapcase",
90
+ "title",
91
+ "upper",
92
+ "casefold",
93
+ ],
94
+ [()] * 100,
95
+ [{}] * 100,
96
+ )
97
+ )
98
+ ids, _, _ = zip(*_any_string_method) # use method name as fixture-id
99
+ missing_methods = {f for f in dir(StringMethods) if not f.startswith("_")} - set(ids)
100
+
101
+ # test that the above list captures all methods of StringMethods
102
+ assert not missing_methods
103
+
104
+
105
+ @pytest.fixture(params=_any_string_method, ids=ids)
106
+ def any_string_method(request):
107
+ """
108
+ Fixture for all public methods of `StringMethods`
109
+
110
+ This fixture returns a tuple of the method name and sample arguments
111
+ necessary to call the method.
112
+
113
+ Returns
114
+ -------
115
+ method_name : str
116
+ The name of the method in `StringMethods`
117
+ args : tuple
118
+ Sample values for the positional arguments
119
+ kwargs : dict
120
+ Sample values for the keyword arguments
121
+
122
+ Examples
123
+ --------
124
+ >>> def test_something(any_string_method):
125
+ ... s = Series(['a', 'b', np.nan, 'd'])
126
+ ...
127
+ ... method_name, args, kwargs = any_string_method
128
+ ... method = getattr(s.str, method_name)
129
+ ... # will not raise
130
+ ... method(*args, **kwargs)
131
+ """
132
+ return request.param
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_api.py ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pytest
3
+
4
+ from pandas import (
5
+ CategoricalDtype,
6
+ DataFrame,
7
+ Index,
8
+ MultiIndex,
9
+ Series,
10
+ _testing as tm,
11
+ option_context,
12
+ )
13
+ from pandas.core.strings.accessor import StringMethods
14
+
15
+ # subset of the full set from pandas/conftest.py
16
+ _any_allowed_skipna_inferred_dtype = [
17
+ ("string", ["a", np.nan, "c"]),
18
+ ("bytes", [b"a", np.nan, b"c"]),
19
+ ("empty", [np.nan, np.nan, np.nan]),
20
+ ("empty", []),
21
+ ("mixed-integer", ["a", np.nan, 2]),
22
+ ]
23
+ ids, _ = zip(*_any_allowed_skipna_inferred_dtype) # use inferred type as id
24
+
25
+
26
+ @pytest.fixture(params=_any_allowed_skipna_inferred_dtype, ids=ids)
27
+ def any_allowed_skipna_inferred_dtype(request):
28
+ """
29
+ Fixture for all (inferred) dtypes allowed in StringMethods.__init__
30
+
31
+ The covered (inferred) types are:
32
+ * 'string'
33
+ * 'empty'
34
+ * 'bytes'
35
+ * 'mixed'
36
+ * 'mixed-integer'
37
+
38
+ Returns
39
+ -------
40
+ inferred_dtype : str
41
+ The string for the inferred dtype from _libs.lib.infer_dtype
42
+ values : np.ndarray
43
+ An array of object dtype that will be inferred to have
44
+ `inferred_dtype`
45
+
46
+ Examples
47
+ --------
48
+ >>> from pandas._libs import lib
49
+ >>>
50
+ >>> def test_something(any_allowed_skipna_inferred_dtype):
51
+ ... inferred_dtype, values = any_allowed_skipna_inferred_dtype
52
+ ... # will pass
53
+ ... assert lib.infer_dtype(values, skipna=True) == inferred_dtype
54
+ ...
55
+ ... # constructor for .str-accessor will also pass
56
+ ... Series(values).str
57
+ """
58
+ inferred_dtype, values = request.param
59
+ values = np.array(values, dtype=object) # object dtype to avoid casting
60
+
61
+ # correctness of inference tested in tests/dtypes/test_inference.py
62
+ return inferred_dtype, values
63
+
64
+
65
+ def test_api(any_string_dtype):
66
+ # GH 6106, GH 9322
67
+ assert Series.str is StringMethods
68
+ assert isinstance(Series([""], dtype=any_string_dtype).str, StringMethods)
69
+
70
+
71
+ def test_api_mi_raises():
72
+ # GH 23679
73
+ mi = MultiIndex.from_arrays([["a", "b", "c"]])
74
+ msg = "Can only use .str accessor with Index, not MultiIndex"
75
+ with pytest.raises(AttributeError, match=msg):
76
+ mi.str
77
+ assert not hasattr(mi, "str")
78
+
79
+
80
+ @pytest.mark.parametrize("dtype", [object, "category"])
81
+ def test_api_per_dtype(index_or_series, dtype, any_skipna_inferred_dtype):
82
+ # one instance of parametrized fixture
83
+ box = index_or_series
84
+ inferred_dtype, values = any_skipna_inferred_dtype
85
+
86
+ t = box(values, dtype=dtype) # explicit dtype to avoid casting
87
+
88
+ types_passing_constructor = [
89
+ "string",
90
+ "unicode",
91
+ "empty",
92
+ "bytes",
93
+ "mixed",
94
+ "mixed-integer",
95
+ ]
96
+ if inferred_dtype in types_passing_constructor:
97
+ # GH 6106
98
+ assert isinstance(t.str, StringMethods)
99
+ else:
100
+ # GH 9184, GH 23011, GH 23163
101
+ msg = "Can only use .str accessor with string values.*"
102
+ with pytest.raises(AttributeError, match=msg):
103
+ t.str
104
+ assert not hasattr(t, "str")
105
+
106
+
107
+ @pytest.mark.parametrize("dtype", [object, "category"])
108
+ def test_api_per_method(
109
+ index_or_series,
110
+ dtype,
111
+ any_allowed_skipna_inferred_dtype,
112
+ any_string_method,
113
+ request,
114
+ using_infer_string,
115
+ ):
116
+ # this test does not check correctness of the different methods,
117
+ # just that the methods work on the specified (inferred) dtypes,
118
+ # and raise on all others
119
+ box = index_or_series
120
+
121
+ # one instance of each parametrized fixture
122
+ inferred_dtype, values = any_allowed_skipna_inferred_dtype
123
+ method_name, args, kwargs = any_string_method
124
+
125
+ reason = None
126
+ if box is Index and values.size == 0:
127
+ if method_name in ["partition", "rpartition"] and kwargs.get("expand", True):
128
+ raises = TypeError
129
+ reason = "Method cannot deal with empty Index"
130
+ elif method_name == "split" and kwargs.get("expand", None):
131
+ raises = TypeError
132
+ reason = "Split fails on empty Series when expand=True"
133
+ elif method_name == "get_dummies":
134
+ raises = ValueError
135
+ reason = "Need to fortify get_dummies corner cases"
136
+
137
+ elif (
138
+ box is Index
139
+ and inferred_dtype == "empty"
140
+ and dtype == object
141
+ and method_name == "get_dummies"
142
+ ):
143
+ raises = ValueError
144
+ reason = "Need to fortify get_dummies corner cases"
145
+
146
+ if reason is not None:
147
+ mark = pytest.mark.xfail(raises=raises, reason=reason)
148
+ request.applymarker(mark)
149
+
150
+ t = box(values, dtype=dtype) # explicit dtype to avoid casting
151
+ method = getattr(t.str, method_name)
152
+
153
+ if using_infer_string and dtype == "category":
154
+ string_allowed = method_name not in ["decode"]
155
+ else:
156
+ string_allowed = True
157
+ bytes_allowed = method_name in ["decode", "get", "len", "slice"]
158
+ # as of v0.23.4, all methods except 'cat' are very lenient with the
159
+ # allowed data types, just returning NaN for entries that error.
160
+ # This could be changed with an 'errors'-kwarg to the `str`-accessor,
161
+ # see discussion in GH 13877
162
+ mixed_allowed = method_name not in ["cat"]
163
+
164
+ allowed_types = (
165
+ ["empty"]
166
+ + ["string", "unicode"] * string_allowed
167
+ + ["bytes"] * bytes_allowed
168
+ + ["mixed", "mixed-integer"] * mixed_allowed
169
+ )
170
+
171
+ if inferred_dtype in allowed_types:
172
+ # xref GH 23555, GH 23556
173
+ with option_context("future.no_silent_downcasting", True):
174
+ method(*args, **kwargs) # works!
175
+ else:
176
+ # GH 23011, GH 23163
177
+ msg = (
178
+ f"Cannot use .str.{method_name} with values of "
179
+ f"inferred dtype {repr(inferred_dtype)}."
180
+ "|a bytes-like object is required, not 'str'"
181
+ )
182
+ with pytest.raises(TypeError, match=msg):
183
+ method(*args, **kwargs)
184
+
185
+
186
+ def test_api_for_categorical(any_string_method, any_string_dtype):
187
+ # https://github.com/pandas-dev/pandas/issues/10661
188
+ s = Series(list("aabb"), dtype=any_string_dtype)
189
+ s = s + " " + s
190
+ c = s.astype("category")
191
+ c = c.astype(CategoricalDtype(c.dtype.categories.astype("object")))
192
+ assert isinstance(c.str, StringMethods)
193
+
194
+ method_name, args, kwargs = any_string_method
195
+
196
+ result = getattr(c.str, method_name)(*args, **kwargs)
197
+ expected = getattr(s.astype("object").str, method_name)(*args, **kwargs)
198
+
199
+ if isinstance(result, DataFrame):
200
+ tm.assert_frame_equal(result, expected)
201
+ elif isinstance(result, Series):
202
+ tm.assert_series_equal(result, expected)
203
+ else:
204
+ # str.cat(others=None) returns string, for example
205
+ assert result == expected
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_case_justify.py ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import operator
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ from pandas import (
8
+ Series,
9
+ _testing as tm,
10
+ )
11
+
12
+
13
+ def test_title(any_string_dtype):
14
+ s = Series(["FOO", "BAR", np.nan, "Blah", "blurg"], dtype=any_string_dtype)
15
+ result = s.str.title()
16
+ expected = Series(["Foo", "Bar", np.nan, "Blah", "Blurg"], dtype=any_string_dtype)
17
+ tm.assert_series_equal(result, expected)
18
+
19
+
20
+ def test_title_mixed_object():
21
+ s = Series(["FOO", np.nan, "bar", True, datetime.today(), "blah", None, 1, 2.0])
22
+ result = s.str.title()
23
+ expected = Series(
24
+ ["Foo", np.nan, "Bar", np.nan, np.nan, "Blah", None, np.nan, np.nan],
25
+ dtype=object,
26
+ )
27
+ tm.assert_almost_equal(result, expected)
28
+
29
+
30
+ def test_lower_upper(any_string_dtype):
31
+ s = Series(["om", np.nan, "nom", "nom"], dtype=any_string_dtype)
32
+
33
+ result = s.str.upper()
34
+ expected = Series(["OM", np.nan, "NOM", "NOM"], dtype=any_string_dtype)
35
+ tm.assert_series_equal(result, expected)
36
+
37
+ result = result.str.lower()
38
+ tm.assert_series_equal(result, s)
39
+
40
+
41
+ def test_lower_upper_mixed_object():
42
+ s = Series(["a", np.nan, "b", True, datetime.today(), "foo", None, 1, 2.0])
43
+
44
+ result = s.str.upper()
45
+ expected = Series(
46
+ ["A", np.nan, "B", np.nan, np.nan, "FOO", None, np.nan, np.nan], dtype=object
47
+ )
48
+ tm.assert_series_equal(result, expected)
49
+
50
+ result = s.str.lower()
51
+ expected = Series(
52
+ ["a", np.nan, "b", np.nan, np.nan, "foo", None, np.nan, np.nan], dtype=object
53
+ )
54
+ tm.assert_series_equal(result, expected)
55
+
56
+
57
+ @pytest.mark.parametrize(
58
+ "data, expected",
59
+ [
60
+ (
61
+ ["FOO", "BAR", np.nan, "Blah", "blurg"],
62
+ ["Foo", "Bar", np.nan, "Blah", "Blurg"],
63
+ ),
64
+ (["a", "b", "c"], ["A", "B", "C"]),
65
+ (["a b", "a bc. de"], ["A b", "A bc. de"]),
66
+ ],
67
+ )
68
+ def test_capitalize(data, expected, any_string_dtype):
69
+ s = Series(data, dtype=any_string_dtype)
70
+ result = s.str.capitalize()
71
+ expected = Series(expected, dtype=any_string_dtype)
72
+ tm.assert_series_equal(result, expected)
73
+
74
+
75
+ def test_capitalize_mixed_object():
76
+ s = Series(["FOO", np.nan, "bar", True, datetime.today(), "blah", None, 1, 2.0])
77
+ result = s.str.capitalize()
78
+ expected = Series(
79
+ ["Foo", np.nan, "Bar", np.nan, np.nan, "Blah", None, np.nan, np.nan],
80
+ dtype=object,
81
+ )
82
+ tm.assert_series_equal(result, expected)
83
+
84
+
85
+ def test_swapcase(any_string_dtype):
86
+ s = Series(["FOO", "BAR", np.nan, "Blah", "blurg"], dtype=any_string_dtype)
87
+ result = s.str.swapcase()
88
+ expected = Series(["foo", "bar", np.nan, "bLAH", "BLURG"], dtype=any_string_dtype)
89
+ tm.assert_series_equal(result, expected)
90
+
91
+
92
+ def test_swapcase_mixed_object():
93
+ s = Series(["FOO", np.nan, "bar", True, datetime.today(), "Blah", None, 1, 2.0])
94
+ result = s.str.swapcase()
95
+ expected = Series(
96
+ ["foo", np.nan, "BAR", np.nan, np.nan, "bLAH", None, np.nan, np.nan],
97
+ dtype=object,
98
+ )
99
+ tm.assert_series_equal(result, expected)
100
+
101
+
102
+ def test_casefold():
103
+ # GH25405
104
+ expected = Series(["ss", np.nan, "case", "ssd"])
105
+ s = Series(["ß", np.nan, "case", "ßd"])
106
+ result = s.str.casefold()
107
+
108
+ tm.assert_series_equal(result, expected)
109
+
110
+
111
+ def test_casemethods(any_string_dtype):
112
+ values = ["aaa", "bbb", "CCC", "Dddd", "eEEE"]
113
+ s = Series(values, dtype=any_string_dtype)
114
+ assert s.str.lower().tolist() == [v.lower() for v in values]
115
+ assert s.str.upper().tolist() == [v.upper() for v in values]
116
+ assert s.str.title().tolist() == [v.title() for v in values]
117
+ assert s.str.capitalize().tolist() == [v.capitalize() for v in values]
118
+ assert s.str.swapcase().tolist() == [v.swapcase() for v in values]
119
+
120
+
121
+ def test_pad(any_string_dtype):
122
+ s = Series(["a", "b", np.nan, "c", np.nan, "eeeeee"], dtype=any_string_dtype)
123
+
124
+ result = s.str.pad(5, side="left")
125
+ expected = Series(
126
+ [" a", " b", np.nan, " c", np.nan, "eeeeee"], dtype=any_string_dtype
127
+ )
128
+ tm.assert_series_equal(result, expected)
129
+
130
+ result = s.str.pad(5, side="right")
131
+ expected = Series(
132
+ ["a ", "b ", np.nan, "c ", np.nan, "eeeeee"], dtype=any_string_dtype
133
+ )
134
+ tm.assert_series_equal(result, expected)
135
+
136
+ result = s.str.pad(5, side="both")
137
+ expected = Series(
138
+ [" a ", " b ", np.nan, " c ", np.nan, "eeeeee"], dtype=any_string_dtype
139
+ )
140
+ tm.assert_series_equal(result, expected)
141
+
142
+
143
+ def test_pad_mixed_object():
144
+ s = Series(["a", np.nan, "b", True, datetime.today(), "ee", None, 1, 2.0])
145
+
146
+ result = s.str.pad(5, side="left")
147
+ expected = Series(
148
+ [" a", np.nan, " b", np.nan, np.nan, " ee", None, np.nan, np.nan],
149
+ dtype=object,
150
+ )
151
+ tm.assert_series_equal(result, expected)
152
+
153
+ result = s.str.pad(5, side="right")
154
+ expected = Series(
155
+ ["a ", np.nan, "b ", np.nan, np.nan, "ee ", None, np.nan, np.nan],
156
+ dtype=object,
157
+ )
158
+ tm.assert_series_equal(result, expected)
159
+
160
+ result = s.str.pad(5, side="both")
161
+ expected = Series(
162
+ [" a ", np.nan, " b ", np.nan, np.nan, " ee ", None, np.nan, np.nan],
163
+ dtype=object,
164
+ )
165
+ tm.assert_series_equal(result, expected)
166
+
167
+
168
+ def test_pad_fillchar(any_string_dtype):
169
+ s = Series(["a", "b", np.nan, "c", np.nan, "eeeeee"], dtype=any_string_dtype)
170
+
171
+ result = s.str.pad(5, side="left", fillchar="X")
172
+ expected = Series(
173
+ ["XXXXa", "XXXXb", np.nan, "XXXXc", np.nan, "eeeeee"], dtype=any_string_dtype
174
+ )
175
+ tm.assert_series_equal(result, expected)
176
+
177
+ result = s.str.pad(5, side="right", fillchar="X")
178
+ expected = Series(
179
+ ["aXXXX", "bXXXX", np.nan, "cXXXX", np.nan, "eeeeee"], dtype=any_string_dtype
180
+ )
181
+ tm.assert_series_equal(result, expected)
182
+
183
+ result = s.str.pad(5, side="both", fillchar="X")
184
+ expected = Series(
185
+ ["XXaXX", "XXbXX", np.nan, "XXcXX", np.nan, "eeeeee"], dtype=any_string_dtype
186
+ )
187
+ tm.assert_series_equal(result, expected)
188
+
189
+
190
+ def test_pad_fillchar_bad_arg_raises(any_string_dtype):
191
+ s = Series(["a", "b", np.nan, "c", np.nan, "eeeeee"], dtype=any_string_dtype)
192
+
193
+ msg = "fillchar must be a character, not str"
194
+ with pytest.raises(TypeError, match=msg):
195
+ s.str.pad(5, fillchar="XY")
196
+
197
+ msg = "fillchar must be a character, not int"
198
+ with pytest.raises(TypeError, match=msg):
199
+ s.str.pad(5, fillchar=5)
200
+
201
+
202
+ @pytest.mark.parametrize("method_name", ["center", "ljust", "rjust", "zfill", "pad"])
203
+ def test_pad_width_bad_arg_raises(method_name, any_string_dtype):
204
+ # see gh-13598
205
+ s = Series(["1", "22", "a", "bb"], dtype=any_string_dtype)
206
+ op = operator.methodcaller(method_name, "f")
207
+
208
+ msg = "width must be of integer type, not str"
209
+ with pytest.raises(TypeError, match=msg):
210
+ op(s.str)
211
+
212
+
213
+ def test_center_ljust_rjust(any_string_dtype):
214
+ s = Series(["a", "b", np.nan, "c", np.nan, "eeeeee"], dtype=any_string_dtype)
215
+
216
+ result = s.str.center(5)
217
+ expected = Series(
218
+ [" a ", " b ", np.nan, " c ", np.nan, "eeeeee"], dtype=any_string_dtype
219
+ )
220
+ tm.assert_series_equal(result, expected)
221
+
222
+ result = s.str.ljust(5)
223
+ expected = Series(
224
+ ["a ", "b ", np.nan, "c ", np.nan, "eeeeee"], dtype=any_string_dtype
225
+ )
226
+ tm.assert_series_equal(result, expected)
227
+
228
+ result = s.str.rjust(5)
229
+ expected = Series(
230
+ [" a", " b", np.nan, " c", np.nan, "eeeeee"], dtype=any_string_dtype
231
+ )
232
+ tm.assert_series_equal(result, expected)
233
+
234
+
235
+ def test_center_ljust_rjust_mixed_object():
236
+ s = Series(["a", np.nan, "b", True, datetime.today(), "c", "eee", None, 1, 2.0])
237
+
238
+ result = s.str.center(5)
239
+ expected = Series(
240
+ [
241
+ " a ",
242
+ np.nan,
243
+ " b ",
244
+ np.nan,
245
+ np.nan,
246
+ " c ",
247
+ " eee ",
248
+ None,
249
+ np.nan,
250
+ np.nan,
251
+ ],
252
+ dtype=object,
253
+ )
254
+ tm.assert_series_equal(result, expected)
255
+
256
+ result = s.str.ljust(5)
257
+ expected = Series(
258
+ [
259
+ "a ",
260
+ np.nan,
261
+ "b ",
262
+ np.nan,
263
+ np.nan,
264
+ "c ",
265
+ "eee ",
266
+ None,
267
+ np.nan,
268
+ np.nan,
269
+ ],
270
+ dtype=object,
271
+ )
272
+ tm.assert_series_equal(result, expected)
273
+
274
+ result = s.str.rjust(5)
275
+ expected = Series(
276
+ [
277
+ " a",
278
+ np.nan,
279
+ " b",
280
+ np.nan,
281
+ np.nan,
282
+ " c",
283
+ " eee",
284
+ None,
285
+ np.nan,
286
+ np.nan,
287
+ ],
288
+ dtype=object,
289
+ )
290
+ tm.assert_series_equal(result, expected)
291
+
292
+
293
+ def test_center_ljust_rjust_fillchar(any_string_dtype):
294
+ # GH#54533, GH#54792
295
+ s = Series(["a", "bb", "cccc", "ddddd", "eeeeee"], dtype=any_string_dtype)
296
+
297
+ result = s.str.center(5, fillchar="X")
298
+ expected = Series(
299
+ ["XXaXX", "XXbbX", "Xcccc", "ddddd", "eeeeee"], dtype=any_string_dtype
300
+ )
301
+ tm.assert_series_equal(result, expected)
302
+ expected = np.array([v.center(5, "X") for v in np.array(s)], dtype=np.object_)
303
+ tm.assert_numpy_array_equal(np.array(result, dtype=np.object_), expected)
304
+
305
+ result = s.str.ljust(5, fillchar="X")
306
+ expected = Series(
307
+ ["aXXXX", "bbXXX", "ccccX", "ddddd", "eeeeee"], dtype=any_string_dtype
308
+ )
309
+ tm.assert_series_equal(result, expected)
310
+ expected = np.array([v.ljust(5, "X") for v in np.array(s)], dtype=np.object_)
311
+ tm.assert_numpy_array_equal(np.array(result, dtype=np.object_), expected)
312
+
313
+ result = s.str.rjust(5, fillchar="X")
314
+ expected = Series(
315
+ ["XXXXa", "XXXbb", "Xcccc", "ddddd", "eeeeee"], dtype=any_string_dtype
316
+ )
317
+ tm.assert_series_equal(result, expected)
318
+ expected = np.array([v.rjust(5, "X") for v in np.array(s)], dtype=np.object_)
319
+ tm.assert_numpy_array_equal(np.array(result, dtype=np.object_), expected)
320
+
321
+
322
+ def test_center_ljust_rjust_fillchar_bad_arg_raises(any_string_dtype):
323
+ s = Series(["a", "bb", "cccc", "ddddd", "eeeeee"], dtype=any_string_dtype)
324
+
325
+ # If fillchar is not a character, normal str raises TypeError
326
+ # 'aaa'.ljust(5, 'XY')
327
+ # TypeError: must be char, not str
328
+ template = "fillchar must be a character, not {dtype}"
329
+
330
+ with pytest.raises(TypeError, match=template.format(dtype="str")):
331
+ s.str.center(5, fillchar="XY")
332
+
333
+ with pytest.raises(TypeError, match=template.format(dtype="str")):
334
+ s.str.ljust(5, fillchar="XY")
335
+
336
+ with pytest.raises(TypeError, match=template.format(dtype="str")):
337
+ s.str.rjust(5, fillchar="XY")
338
+
339
+ with pytest.raises(TypeError, match=template.format(dtype="int")):
340
+ s.str.center(5, fillchar=1)
341
+
342
+ with pytest.raises(TypeError, match=template.format(dtype="int")):
343
+ s.str.ljust(5, fillchar=1)
344
+
345
+ with pytest.raises(TypeError, match=template.format(dtype="int")):
346
+ s.str.rjust(5, fillchar=1)
347
+
348
+
349
+ def test_zfill(any_string_dtype):
350
+ s = Series(["1", "22", "aaa", "333", "45678"], dtype=any_string_dtype)
351
+
352
+ result = s.str.zfill(5)
353
+ expected = Series(
354
+ ["00001", "00022", "00aaa", "00333", "45678"], dtype=any_string_dtype
355
+ )
356
+ tm.assert_series_equal(result, expected)
357
+ expected = np.array([v.zfill(5) for v in np.array(s)], dtype=np.object_)
358
+ tm.assert_numpy_array_equal(np.array(result, dtype=np.object_), expected)
359
+
360
+ result = s.str.zfill(3)
361
+ expected = Series(["001", "022", "aaa", "333", "45678"], dtype=any_string_dtype)
362
+ tm.assert_series_equal(result, expected)
363
+ expected = np.array([v.zfill(3) for v in np.array(s)], dtype=np.object_)
364
+ tm.assert_numpy_array_equal(np.array(result, dtype=np.object_), expected)
365
+
366
+ s = Series(["1", np.nan, "aaa", np.nan, "45678"], dtype=any_string_dtype)
367
+ result = s.str.zfill(5)
368
+ expected = Series(
369
+ ["00001", np.nan, "00aaa", np.nan, "45678"], dtype=any_string_dtype
370
+ )
371
+ tm.assert_series_equal(result, expected)
372
+
373
+
374
+ def test_wrap(any_string_dtype):
375
+ # test values are: two words less than width, two words equal to width,
376
+ # two words greater than width, one word less than width, one word
377
+ # equal to width, one word greater than width, multiple tokens with
378
+ # trailing whitespace equal to width
379
+ s = Series(
380
+ [
381
+ "hello world",
382
+ "hello world!",
383
+ "hello world!!",
384
+ "abcdefabcde",
385
+ "abcdefabcdef",
386
+ "abcdefabcdefa",
387
+ "ab ab ab ab ",
388
+ "ab ab ab ab a",
389
+ "\t",
390
+ ],
391
+ dtype=any_string_dtype,
392
+ )
393
+
394
+ # expected values
395
+ expected = Series(
396
+ [
397
+ "hello world",
398
+ "hello world!",
399
+ "hello\nworld!!",
400
+ "abcdefabcde",
401
+ "abcdefabcdef",
402
+ "abcdefabcdef\na",
403
+ "ab ab ab ab",
404
+ "ab ab ab ab\na",
405
+ "",
406
+ ],
407
+ dtype=any_string_dtype,
408
+ )
409
+
410
+ result = s.str.wrap(12, break_long_words=True)
411
+ tm.assert_series_equal(result, expected)
412
+
413
+
414
+ def test_wrap_unicode(any_string_dtype):
415
+ # test with pre and post whitespace (non-unicode), NaN, and non-ascii Unicode
416
+ s = Series(
417
+ [" pre ", np.nan, "\xac\u20ac\U00008000 abadcafe"], dtype=any_string_dtype
418
+ )
419
+ expected = Series(
420
+ [" pre", np.nan, "\xac\u20ac\U00008000 ab\nadcafe"], dtype=any_string_dtype
421
+ )
422
+ result = s.str.wrap(6)
423
+ tm.assert_series_equal(result, expected)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_cat.py ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ import pandas.util._test_decorators as td
7
+
8
+ from pandas import (
9
+ DataFrame,
10
+ Index,
11
+ MultiIndex,
12
+ Series,
13
+ _testing as tm,
14
+ concat,
15
+ option_context,
16
+ )
17
+
18
+
19
+ @pytest.mark.parametrize("other", [None, Series, Index])
20
+ def test_str_cat_name(index_or_series, other):
21
+ # GH 21053
22
+ box = index_or_series
23
+ values = ["a", "b"]
24
+ if other:
25
+ other = other(values)
26
+ else:
27
+ other = values
28
+ result = box(values, name="name").str.cat(other, sep=",")
29
+ assert result.name == "name"
30
+
31
+
32
+ @pytest.mark.parametrize(
33
+ "infer_string", [False, pytest.param(True, marks=td.skip_if_no("pyarrow"))]
34
+ )
35
+ def test_str_cat(index_or_series, infer_string):
36
+ with option_context("future.infer_string", infer_string):
37
+ box = index_or_series
38
+ # test_cat above tests "str_cat" from ndarray;
39
+ # here testing "str.cat" from Series/Index to ndarray/list
40
+ s = box(["a", "a", "b", "b", "c", np.nan])
41
+
42
+ # single array
43
+ result = s.str.cat()
44
+ expected = "aabbc"
45
+ assert result == expected
46
+
47
+ result = s.str.cat(na_rep="-")
48
+ expected = "aabbc-"
49
+ assert result == expected
50
+
51
+ result = s.str.cat(sep="_", na_rep="NA")
52
+ expected = "a_a_b_b_c_NA"
53
+ assert result == expected
54
+
55
+ t = np.array(["a", np.nan, "b", "d", "foo", np.nan], dtype=object)
56
+ expected = box(["aa", "a-", "bb", "bd", "cfoo", "--"])
57
+
58
+ # Series/Index with array
59
+ result = s.str.cat(t, na_rep="-")
60
+ tm.assert_equal(result, expected)
61
+
62
+ # Series/Index with list
63
+ result = s.str.cat(list(t), na_rep="-")
64
+ tm.assert_equal(result, expected)
65
+
66
+ # errors for incorrect lengths
67
+ rgx = r"If `others` contains arrays or lists \(or other list-likes.*"
68
+ z = Series(["1", "2", "3"])
69
+
70
+ with pytest.raises(ValueError, match=rgx):
71
+ s.str.cat(z.values)
72
+
73
+ with pytest.raises(ValueError, match=rgx):
74
+ s.str.cat(list(z))
75
+
76
+
77
+ def test_str_cat_raises_intuitive_error(index_or_series):
78
+ # GH 11334
79
+ box = index_or_series
80
+ s = box(["a", "b", "c", "d"])
81
+ message = "Did you mean to supply a `sep` keyword?"
82
+ with pytest.raises(ValueError, match=message):
83
+ s.str.cat("|")
84
+ with pytest.raises(ValueError, match=message):
85
+ s.str.cat(" ")
86
+
87
+
88
+ @pytest.mark.parametrize(
89
+ "infer_string", [False, pytest.param(True, marks=td.skip_if_no("pyarrow"))]
90
+ )
91
+ @pytest.mark.parametrize("sep", ["", None])
92
+ @pytest.mark.parametrize("dtype_target", ["object", "category"])
93
+ @pytest.mark.parametrize("dtype_caller", ["object", "category"])
94
+ def test_str_cat_categorical(
95
+ index_or_series, dtype_caller, dtype_target, sep, infer_string
96
+ ):
97
+ box = index_or_series
98
+
99
+ with option_context("future.infer_string", infer_string):
100
+ s = Index(["a", "a", "b", "a"], dtype=dtype_caller)
101
+ s = s if box == Index else Series(s, index=s, dtype=s.dtype)
102
+ t = Index(["b", "a", "b", "c"], dtype=dtype_target)
103
+
104
+ expected = Index(
105
+ ["ab", "aa", "bb", "ac"], dtype=object if dtype_caller == "object" else None
106
+ )
107
+ expected = (
108
+ expected
109
+ if box == Index
110
+ else Series(
111
+ expected, index=Index(s, dtype=dtype_caller), dtype=expected.dtype
112
+ )
113
+ )
114
+
115
+ # Series/Index with unaligned Index -> t.values
116
+ result = s.str.cat(t.values, sep=sep)
117
+ tm.assert_equal(result, expected)
118
+
119
+ # Series/Index with Series having matching Index
120
+ t = Series(t.values, index=Index(s, dtype=dtype_caller))
121
+ result = s.str.cat(t, sep=sep)
122
+ tm.assert_equal(result, expected)
123
+
124
+ # Series/Index with Series.values
125
+ result = s.str.cat(t.values, sep=sep)
126
+ tm.assert_equal(result, expected)
127
+
128
+ # Series/Index with Series having different Index
129
+ t = Series(t.values, index=t.values)
130
+ expected = Index(
131
+ ["aa", "aa", "bb", "bb", "aa"],
132
+ dtype=object if dtype_caller == "object" else None,
133
+ )
134
+ dtype = object if dtype_caller == "object" else s.dtype.categories.dtype
135
+ expected = (
136
+ expected
137
+ if box == Index
138
+ else Series(
139
+ expected,
140
+ index=Index(expected.str[:1], dtype=dtype),
141
+ dtype=expected.dtype,
142
+ )
143
+ )
144
+
145
+ result = s.str.cat(t, sep=sep)
146
+ tm.assert_equal(result, expected)
147
+
148
+
149
+ @pytest.mark.parametrize(
150
+ "data",
151
+ [[1, 2, 3], [0.1, 0.2, 0.3], [1, 2, "b"]],
152
+ ids=["integers", "floats", "mixed"],
153
+ )
154
+ # without dtype=object, np.array would cast [1, 2, 'b'] to ['1', '2', 'b']
155
+ @pytest.mark.parametrize(
156
+ "box",
157
+ [Series, Index, list, lambda x: np.array(x, dtype=object)],
158
+ ids=["Series", "Index", "list", "np.array"],
159
+ )
160
+ def test_str_cat_wrong_dtype_raises(box, data):
161
+ # GH 22722
162
+ s = Series(["a", "b", "c"])
163
+ t = box(data)
164
+
165
+ msg = "Concatenation requires list-likes containing only strings.*"
166
+ with pytest.raises(TypeError, match=msg):
167
+ # need to use outer and na_rep, as otherwise Index would not raise
168
+ s.str.cat(t, join="outer", na_rep="-")
169
+
170
+
171
+ def test_str_cat_mixed_inputs(index_or_series):
172
+ box = index_or_series
173
+ s = Index(["a", "b", "c", "d"])
174
+ s = s if box == Index else Series(s, index=s)
175
+
176
+ t = Series(["A", "B", "C", "D"], index=s.values)
177
+ d = concat([t, Series(s, index=s)], axis=1)
178
+
179
+ expected = Index(["aAa", "bBb", "cCc", "dDd"])
180
+ expected = expected if box == Index else Series(expected.values, index=s.values)
181
+
182
+ # Series/Index with DataFrame
183
+ result = s.str.cat(d)
184
+ tm.assert_equal(result, expected)
185
+
186
+ # Series/Index with two-dimensional ndarray
187
+ result = s.str.cat(d.values)
188
+ tm.assert_equal(result, expected)
189
+
190
+ # Series/Index with list of Series
191
+ result = s.str.cat([t, s])
192
+ tm.assert_equal(result, expected)
193
+
194
+ # Series/Index with mixed list of Series/array
195
+ result = s.str.cat([t, s.values])
196
+ tm.assert_equal(result, expected)
197
+
198
+ # Series/Index with list of Series; different indexes
199
+ t.index = ["b", "c", "d", "a"]
200
+ expected = box(["aDa", "bAb", "cBc", "dCd"])
201
+ expected = expected if box == Index else Series(expected.values, index=s.values)
202
+ result = s.str.cat([t, s])
203
+ tm.assert_equal(result, expected)
204
+
205
+ # Series/Index with mixed list; different index
206
+ result = s.str.cat([t, s.values])
207
+ tm.assert_equal(result, expected)
208
+
209
+ # Series/Index with DataFrame; different indexes
210
+ d.index = ["b", "c", "d", "a"]
211
+ expected = box(["aDd", "bAa", "cBb", "dCc"])
212
+ expected = expected if box == Index else Series(expected.values, index=s.values)
213
+ result = s.str.cat(d)
214
+ tm.assert_equal(result, expected)
215
+
216
+ # errors for incorrect lengths
217
+ rgx = r"If `others` contains arrays or lists \(or other list-likes.*"
218
+ z = Series(["1", "2", "3"])
219
+ e = concat([z, z], axis=1)
220
+
221
+ # two-dimensional ndarray
222
+ with pytest.raises(ValueError, match=rgx):
223
+ s.str.cat(e.values)
224
+
225
+ # list of list-likes
226
+ with pytest.raises(ValueError, match=rgx):
227
+ s.str.cat([z.values, s.values])
228
+
229
+ # mixed list of Series/list-like
230
+ with pytest.raises(ValueError, match=rgx):
231
+ s.str.cat([z.values, s])
232
+
233
+ # errors for incorrect arguments in list-like
234
+ rgx = "others must be Series, Index, DataFrame,.*"
235
+ # make sure None/NaN do not crash checks in _get_series_list
236
+ u = Series(["a", np.nan, "c", None])
237
+
238
+ # mix of string and Series
239
+ with pytest.raises(TypeError, match=rgx):
240
+ s.str.cat([u, "u"])
241
+
242
+ # DataFrame in list
243
+ with pytest.raises(TypeError, match=rgx):
244
+ s.str.cat([u, d])
245
+
246
+ # 2-dim ndarray in list
247
+ with pytest.raises(TypeError, match=rgx):
248
+ s.str.cat([u, d.values])
249
+
250
+ # nested lists
251
+ with pytest.raises(TypeError, match=rgx):
252
+ s.str.cat([u, [u, d]])
253
+
254
+ # forbidden input type: set
255
+ # GH 23009
256
+ with pytest.raises(TypeError, match=rgx):
257
+ s.str.cat(set(u))
258
+
259
+ # forbidden input type: set in list
260
+ # GH 23009
261
+ with pytest.raises(TypeError, match=rgx):
262
+ s.str.cat([u, set(u)])
263
+
264
+ # other forbidden input type, e.g. int
265
+ with pytest.raises(TypeError, match=rgx):
266
+ s.str.cat(1)
267
+
268
+ # nested list-likes
269
+ with pytest.raises(TypeError, match=rgx):
270
+ s.str.cat(iter([t.values, list(s)]))
271
+
272
+
273
+ @pytest.mark.parametrize("join", ["left", "outer", "inner", "right"])
274
+ def test_str_cat_align_indexed(index_or_series, join):
275
+ # https://github.com/pandas-dev/pandas/issues/18657
276
+ box = index_or_series
277
+
278
+ s = Series(["a", "b", "c", "d"], index=["a", "b", "c", "d"])
279
+ t = Series(["D", "A", "E", "B"], index=["d", "a", "e", "b"])
280
+ sa, ta = s.align(t, join=join)
281
+ # result after manual alignment of inputs
282
+ expected = sa.str.cat(ta, na_rep="-")
283
+
284
+ if box == Index:
285
+ s = Index(s)
286
+ sa = Index(sa)
287
+ expected = Index(expected)
288
+
289
+ result = s.str.cat(t, join=join, na_rep="-")
290
+ tm.assert_equal(result, expected)
291
+
292
+
293
+ @pytest.mark.parametrize("join", ["left", "outer", "inner", "right"])
294
+ def test_str_cat_align_mixed_inputs(join):
295
+ s = Series(["a", "b", "c", "d"])
296
+ t = Series(["d", "a", "e", "b"], index=[3, 0, 4, 1])
297
+ d = concat([t, t], axis=1)
298
+
299
+ expected_outer = Series(["aaa", "bbb", "c--", "ddd", "-ee"])
300
+ expected = expected_outer.loc[s.index.join(t.index, how=join)]
301
+
302
+ # list of Series
303
+ result = s.str.cat([t, t], join=join, na_rep="-")
304
+ tm.assert_series_equal(result, expected)
305
+
306
+ # DataFrame
307
+ result = s.str.cat(d, join=join, na_rep="-")
308
+ tm.assert_series_equal(result, expected)
309
+
310
+ # mixed list of indexed/unindexed
311
+ u = np.array(["A", "B", "C", "D"])
312
+ expected_outer = Series(["aaA", "bbB", "c-C", "ddD", "-e-"])
313
+ # joint index of rhs [t, u]; u will be forced have index of s
314
+ rhs_idx = (
315
+ t.index.intersection(s.index)
316
+ if join == "inner"
317
+ else t.index.union(s.index)
318
+ if join == "outer"
319
+ else t.index.append(s.index.difference(t.index))
320
+ )
321
+
322
+ expected = expected_outer.loc[s.index.join(rhs_idx, how=join)]
323
+ result = s.str.cat([t, u], join=join, na_rep="-")
324
+ tm.assert_series_equal(result, expected)
325
+
326
+ with pytest.raises(TypeError, match="others must be Series,.*"):
327
+ # nested lists are forbidden
328
+ s.str.cat([t, list(u)], join=join)
329
+
330
+ # errors for incorrect lengths
331
+ rgx = r"If `others` contains arrays or lists \(or other list-likes.*"
332
+ z = Series(["1", "2", "3"]).values
333
+
334
+ # unindexed object of wrong length
335
+ with pytest.raises(ValueError, match=rgx):
336
+ s.str.cat(z, join=join)
337
+
338
+ # unindexed object of wrong length in list
339
+ with pytest.raises(ValueError, match=rgx):
340
+ s.str.cat([t, z], join=join)
341
+
342
+
343
+ def test_str_cat_all_na(index_or_series, index_or_series2):
344
+ # GH 24044
345
+ box = index_or_series
346
+ other = index_or_series2
347
+
348
+ # check that all NaNs in caller / target work
349
+ s = Index(["a", "b", "c", "d"])
350
+ s = s if box == Index else Series(s, index=s)
351
+ t = other([np.nan] * 4, dtype=object)
352
+ # add index of s for alignment
353
+ t = t if other == Index else Series(t, index=s)
354
+
355
+ # all-NA target
356
+ if box == Series:
357
+ expected = Series([np.nan] * 4, index=s.index, dtype=s.dtype)
358
+ else: # box == Index
359
+ # TODO: Strimg option, this should return string dtype
360
+ expected = Index([np.nan] * 4, dtype=object)
361
+ result = s.str.cat(t, join="left")
362
+ tm.assert_equal(result, expected)
363
+
364
+ # all-NA caller (only for Series)
365
+ if other == Series:
366
+ expected = Series([np.nan] * 4, dtype=object, index=t.index)
367
+ result = t.str.cat(s, join="left")
368
+ tm.assert_series_equal(result, expected)
369
+
370
+
371
+ def test_str_cat_special_cases():
372
+ s = Series(["a", "b", "c", "d"])
373
+ t = Series(["d", "a", "e", "b"], index=[3, 0, 4, 1])
374
+
375
+ # iterator of elements with different types
376
+ expected = Series(["aaa", "bbb", "c-c", "ddd", "-e-"])
377
+ result = s.str.cat(iter([t, s.values]), join="outer", na_rep="-")
378
+ tm.assert_series_equal(result, expected)
379
+
380
+ # right-align with different indexes in others
381
+ expected = Series(["aa-", "d-d"], index=[0, 3])
382
+ result = s.str.cat([t.loc[[0]], t.loc[[3]]], join="right", na_rep="-")
383
+ tm.assert_series_equal(result, expected)
384
+
385
+
386
+ def test_cat_on_filtered_index():
387
+ df = DataFrame(
388
+ index=MultiIndex.from_product(
389
+ [[2011, 2012], [1, 2, 3]], names=["year", "month"]
390
+ )
391
+ )
392
+
393
+ df = df.reset_index()
394
+ df = df[df.month > 1]
395
+
396
+ str_year = df.year.astype("str")
397
+ str_month = df.month.astype("str")
398
+ str_both = str_year.str.cat(str_month, sep=" ")
399
+
400
+ assert str_both.loc[1] == "2011 2"
401
+
402
+ str_multiple = str_year.str.cat([str_month, str_month], sep=" ")
403
+
404
+ assert str_multiple.loc[1] == "2011 2 2"
405
+
406
+
407
+ @pytest.mark.parametrize("klass", [tuple, list, np.array, Series, Index])
408
+ def test_cat_different_classes(klass):
409
+ # https://github.com/pandas-dev/pandas/issues/33425
410
+ s = Series(["a", "b", "c"])
411
+ result = s.str.cat(klass(["x", "y", "z"]))
412
+ expected = Series(["ax", "by", "cz"])
413
+ tm.assert_series_equal(result, expected)
414
+
415
+
416
+ def test_cat_on_series_dot_str():
417
+ # GH 28277
418
+ ps = Series(["AbC", "de", "FGHI", "j", "kLLLm"])
419
+
420
+ message = re.escape(
421
+ "others must be Series, Index, DataFrame, np.ndarray "
422
+ "or list-like (either containing only strings or "
423
+ "containing only objects of type Series/Index/"
424
+ "np.ndarray[1-dim])"
425
+ )
426
+ with pytest.raises(TypeError, match=message):
427
+ ps.str.cat(others=ps.str)
code/LaDi-RL-old-qwen-cod/LaDi-RL-old-qwen-cod/venv/lib64/python3.10/site-packages/pandas/tests/strings/test_extract.py ADDED
@@ -0,0 +1,724 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import re
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ from pandas.core.dtypes.dtypes import ArrowDtype
8
+
9
+ from pandas import (
10
+ DataFrame,
11
+ Index,
12
+ MultiIndex,
13
+ Series,
14
+ _testing as tm,
15
+ )
16
+
17
+
18
+ def test_extract_expand_kwarg_wrong_type_raises(any_string_dtype):
19
+ # TODO: should this raise TypeError
20
+ values = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
21
+ with pytest.raises(ValueError, match="expand must be True or False"):
22
+ values.str.extract(".*(BAD[_]+).*(BAD)", expand=None)
23
+
24
+
25
+ def test_extract_expand_kwarg(any_string_dtype):
26
+ s = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
27
+ expected = DataFrame(["BAD__", np.nan, np.nan], dtype=any_string_dtype)
28
+
29
+ result = s.str.extract(".*(BAD[_]+).*")
30
+ tm.assert_frame_equal(result, expected)
31
+
32
+ result = s.str.extract(".*(BAD[_]+).*", expand=True)
33
+ tm.assert_frame_equal(result, expected)
34
+
35
+ expected = DataFrame(
36
+ [["BAD__", "BAD"], [np.nan, np.nan], [np.nan, np.nan]], dtype=any_string_dtype
37
+ )
38
+ result = s.str.extract(".*(BAD[_]+).*(BAD)", expand=False)
39
+ tm.assert_frame_equal(result, expected)
40
+
41
+
42
+ def test_extract_expand_False_mixed_object():
43
+ ser = Series(
44
+ ["aBAD_BAD", np.nan, "BAD_b_BAD", True, datetime.today(), "foo", None, 1, 2.0]
45
+ )
46
+
47
+ # two groups
48
+ result = ser.str.extract(".*(BAD[_]+).*(BAD)", expand=False)
49
+ er = [np.nan, np.nan] # empty row
50
+ expected = DataFrame(
51
+ [["BAD_", "BAD"], er, ["BAD_", "BAD"], er, er, er, er, er, er], dtype=object
52
+ )
53
+ tm.assert_frame_equal(result, expected)
54
+
55
+ # single group
56
+ result = ser.str.extract(".*(BAD[_]+).*BAD", expand=False)
57
+ expected = Series(
58
+ ["BAD_", np.nan, "BAD_", np.nan, np.nan, np.nan, None, np.nan, np.nan],
59
+ dtype=object,
60
+ )
61
+ tm.assert_series_equal(result, expected)
62
+
63
+
64
+ def test_extract_expand_index_raises():
65
+ # GH9980
66
+ # Index only works with one regex group since
67
+ # multi-group would expand to a frame
68
+ idx = Index(["A1", "A2", "A3", "A4", "B5"])
69
+ msg = "only one regex group is supported with Index"
70
+ with pytest.raises(ValueError, match=msg):
71
+ idx.str.extract("([AB])([123])", expand=False)
72
+
73
+
74
+ def test_extract_expand_no_capture_groups_raises(index_or_series, any_string_dtype):
75
+ s_or_idx = index_or_series(["A1", "B2", "C3"], dtype=any_string_dtype)
76
+ msg = "pattern contains no capture groups"
77
+
78
+ # no groups
79
+ with pytest.raises(ValueError, match=msg):
80
+ s_or_idx.str.extract("[ABC][123]", expand=False)
81
+
82
+ # only non-capturing groups
83
+ with pytest.raises(ValueError, match=msg):
84
+ s_or_idx.str.extract("(?:[AB]).*", expand=False)
85
+
86
+
87
+ def test_extract_expand_single_capture_group(index_or_series, any_string_dtype):
88
+ # single group renames series/index properly
89
+ s_or_idx = index_or_series(["A1", "A2"], dtype=any_string_dtype)
90
+ result = s_or_idx.str.extract(r"(?P<uno>A)\d", expand=False)
91
+
92
+ expected = index_or_series(["A", "A"], name="uno", dtype=any_string_dtype)
93
+ if index_or_series == Series:
94
+ tm.assert_series_equal(result, expected)
95
+ else:
96
+ tm.assert_index_equal(result, expected)
97
+
98
+
99
+ def test_extract_expand_capture_groups(any_string_dtype):
100
+ s = Series(["A1", "B2", "C3"], dtype=any_string_dtype)
101
+ # one group, no matches
102
+ result = s.str.extract("(_)", expand=False)
103
+ expected = Series([np.nan, np.nan, np.nan], dtype=any_string_dtype)
104
+ tm.assert_series_equal(result, expected)
105
+
106
+ # two groups, no matches
107
+ result = s.str.extract("(_)(_)", expand=False)
108
+ expected = DataFrame(
109
+ [[np.nan, np.nan], [np.nan, np.nan], [np.nan, np.nan]], dtype=any_string_dtype
110
+ )
111
+ tm.assert_frame_equal(result, expected)
112
+
113
+ # one group, some matches
114
+ result = s.str.extract("([AB])[123]", expand=False)
115
+ expected = Series(["A", "B", np.nan], dtype=any_string_dtype)
116
+ tm.assert_series_equal(result, expected)
117
+
118
+ # two groups, some matches
119
+ result = s.str.extract("([AB])([123])", expand=False)
120
+ expected = DataFrame(
121
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]], dtype=any_string_dtype
122
+ )
123
+ tm.assert_frame_equal(result, expected)
124
+
125
+ # one named group
126
+ result = s.str.extract("(?P<letter>[AB])", expand=False)
127
+ expected = Series(["A", "B", np.nan], name="letter", dtype=any_string_dtype)
128
+ tm.assert_series_equal(result, expected)
129
+
130
+ # two named groups
131
+ result = s.str.extract("(?P<letter>[AB])(?P<number>[123])", expand=False)
132
+ expected = DataFrame(
133
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]],
134
+ columns=["letter", "number"],
135
+ dtype=any_string_dtype,
136
+ )
137
+ tm.assert_frame_equal(result, expected)
138
+
139
+ # mix named and unnamed groups
140
+ result = s.str.extract("([AB])(?P<number>[123])", expand=False)
141
+ expected = DataFrame(
142
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]],
143
+ columns=[0, "number"],
144
+ dtype=any_string_dtype,
145
+ )
146
+ tm.assert_frame_equal(result, expected)
147
+
148
+ # one normal group, one non-capturing group
149
+ result = s.str.extract("([AB])(?:[123])", expand=False)
150
+ expected = Series(["A", "B", np.nan], dtype=any_string_dtype)
151
+ tm.assert_series_equal(result, expected)
152
+
153
+ # two normal groups, one non-capturing group
154
+ s = Series(["A11", "B22", "C33"], dtype=any_string_dtype)
155
+ result = s.str.extract("([AB])([123])(?:[123])", expand=False)
156
+ expected = DataFrame(
157
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]], dtype=any_string_dtype
158
+ )
159
+ tm.assert_frame_equal(result, expected)
160
+
161
+ # one optional group followed by one normal group
162
+ s = Series(["A1", "B2", "3"], dtype=any_string_dtype)
163
+ result = s.str.extract("(?P<letter>[AB])?(?P<number>[123])", expand=False)
164
+ expected = DataFrame(
165
+ [["A", "1"], ["B", "2"], [np.nan, "3"]],
166
+ columns=["letter", "number"],
167
+ dtype=any_string_dtype,
168
+ )
169
+ tm.assert_frame_equal(result, expected)
170
+
171
+ # one normal group followed by one optional group
172
+ s = Series(["A1", "B2", "C"], dtype=any_string_dtype)
173
+ result = s.str.extract("(?P<letter>[ABC])(?P<number>[123])?", expand=False)
174
+ expected = DataFrame(
175
+ [["A", "1"], ["B", "2"], ["C", np.nan]],
176
+ columns=["letter", "number"],
177
+ dtype=any_string_dtype,
178
+ )
179
+ tm.assert_frame_equal(result, expected)
180
+
181
+
182
+ def test_extract_expand_capture_groups_index(index, any_string_dtype):
183
+ # https://github.com/pandas-dev/pandas/issues/6348
184
+ # not passing index to the extractor
185
+ data = ["A1", "B2", "C"]
186
+
187
+ if len(index) == 0:
188
+ pytest.skip("Test requires len(index) > 0")
189
+ while len(index) < len(data):
190
+ index = index.repeat(2)
191
+
192
+ index = index[: len(data)]
193
+ ser = Series(data, index=index, dtype=any_string_dtype)
194
+
195
+ result = ser.str.extract(r"(\d)", expand=False)
196
+ expected = Series(["1", "2", np.nan], index=index, dtype=any_string_dtype)
197
+ tm.assert_series_equal(result, expected)
198
+
199
+ result = ser.str.extract(r"(?P<letter>\D)(?P<number>\d)?", expand=False)
200
+ expected = DataFrame(
201
+ [["A", "1"], ["B", "2"], ["C", np.nan]],
202
+ columns=["letter", "number"],
203
+ index=index,
204
+ dtype=any_string_dtype,
205
+ )
206
+ tm.assert_frame_equal(result, expected)
207
+
208
+
209
+ def test_extract_single_series_name_is_preserved(any_string_dtype):
210
+ s = Series(["a3", "b3", "c2"], name="bob", dtype=any_string_dtype)
211
+ result = s.str.extract(r"(?P<sue>[a-z])", expand=False)
212
+ expected = Series(["a", "b", "c"], name="sue", dtype=any_string_dtype)
213
+ tm.assert_series_equal(result, expected)
214
+
215
+
216
+ def test_extract_expand_True(any_string_dtype):
217
+ # Contains tests like those in test_match and some others.
218
+ s = Series(["fooBAD__barBAD", np.nan, "foo"], dtype=any_string_dtype)
219
+
220
+ result = s.str.extract(".*(BAD[_]+).*(BAD)", expand=True)
221
+ expected = DataFrame(
222
+ [["BAD__", "BAD"], [np.nan, np.nan], [np.nan, np.nan]], dtype=any_string_dtype
223
+ )
224
+ tm.assert_frame_equal(result, expected)
225
+
226
+
227
+ def test_extract_expand_True_mixed_object():
228
+ er = [np.nan, np.nan] # empty row
229
+ mixed = Series(
230
+ [
231
+ "aBAD_BAD",
232
+ np.nan,
233
+ "BAD_b_BAD",
234
+ True,
235
+ datetime.today(),
236
+ "foo",
237
+ None,
238
+ 1,
239
+ 2.0,
240
+ ]
241
+ )
242
+
243
+ result = mixed.str.extract(".*(BAD[_]+).*(BAD)", expand=True)
244
+ expected = DataFrame(
245
+ [["BAD_", "BAD"], er, ["BAD_", "BAD"], er, er, er, er, er, er], dtype=object
246
+ )
247
+ tm.assert_frame_equal(result, expected)
248
+
249
+
250
+ def test_extract_expand_True_single_capture_group_raises(
251
+ index_or_series, any_string_dtype
252
+ ):
253
+ # these should work for both Series and Index
254
+ # no groups
255
+ s_or_idx = index_or_series(["A1", "B2", "C3"], dtype=any_string_dtype)
256
+ msg = "pattern contains no capture groups"
257
+ with pytest.raises(ValueError, match=msg):
258
+ s_or_idx.str.extract("[ABC][123]", expand=True)
259
+
260
+ # only non-capturing groups
261
+ with pytest.raises(ValueError, match=msg):
262
+ s_or_idx.str.extract("(?:[AB]).*", expand=True)
263
+
264
+
265
+ def test_extract_expand_True_single_capture_group(index_or_series, any_string_dtype):
266
+ # single group renames series/index properly
267
+ s_or_idx = index_or_series(["A1", "A2"], dtype=any_string_dtype)
268
+ result = s_or_idx.str.extract(r"(?P<uno>A)\d", expand=True)
269
+ expected = DataFrame({"uno": ["A", "A"]}, dtype=any_string_dtype)
270
+ tm.assert_frame_equal(result, expected)
271
+
272
+
273
+ @pytest.mark.parametrize("name", [None, "series_name"])
274
+ def test_extract_series(name, any_string_dtype):
275
+ # extract should give the same result whether or not the series has a name.
276
+ s = Series(["A1", "B2", "C3"], name=name, dtype=any_string_dtype)
277
+
278
+ # one group, no matches
279
+ result = s.str.extract("(_)", expand=True)
280
+ expected = DataFrame([np.nan, np.nan, np.nan], dtype=any_string_dtype)
281
+ tm.assert_frame_equal(result, expected)
282
+
283
+ # two groups, no matches
284
+ result = s.str.extract("(_)(_)", expand=True)
285
+ expected = DataFrame(
286
+ [[np.nan, np.nan], [np.nan, np.nan], [np.nan, np.nan]], dtype=any_string_dtype
287
+ )
288
+ tm.assert_frame_equal(result, expected)
289
+
290
+ # one group, some matches
291
+ result = s.str.extract("([AB])[123]", expand=True)
292
+ expected = DataFrame(["A", "B", np.nan], dtype=any_string_dtype)
293
+ tm.assert_frame_equal(result, expected)
294
+
295
+ # two groups, some matches
296
+ result = s.str.extract("([AB])([123])", expand=True)
297
+ expected = DataFrame(
298
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]], dtype=any_string_dtype
299
+ )
300
+ tm.assert_frame_equal(result, expected)
301
+
302
+ # one named group
303
+ result = s.str.extract("(?P<letter>[AB])", expand=True)
304
+ expected = DataFrame({"letter": ["A", "B", np.nan]}, dtype=any_string_dtype)
305
+ tm.assert_frame_equal(result, expected)
306
+
307
+ # two named groups
308
+ result = s.str.extract("(?P<letter>[AB])(?P<number>[123])", expand=True)
309
+ expected = DataFrame(
310
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]],
311
+ columns=["letter", "number"],
312
+ dtype=any_string_dtype,
313
+ )
314
+ tm.assert_frame_equal(result, expected)
315
+
316
+ # mix named and unnamed groups
317
+ result = s.str.extract("([AB])(?P<number>[123])", expand=True)
318
+ expected = DataFrame(
319
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]],
320
+ columns=[0, "number"],
321
+ dtype=any_string_dtype,
322
+ )
323
+ tm.assert_frame_equal(result, expected)
324
+
325
+ # one normal group, one non-capturing group
326
+ result = s.str.extract("([AB])(?:[123])", expand=True)
327
+ expected = DataFrame(["A", "B", np.nan], dtype=any_string_dtype)
328
+ tm.assert_frame_equal(result, expected)
329
+
330
+
331
+ def test_extract_optional_groups(any_string_dtype):
332
+ # two normal groups, one non-capturing group
333
+ s = Series(["A11", "B22", "C33"], dtype=any_string_dtype)
334
+ result = s.str.extract("([AB])([123])(?:[123])", expand=True)
335
+ expected = DataFrame(
336
+ [["A", "1"], ["B", "2"], [np.nan, np.nan]], dtype=any_string_dtype
337
+ )
338
+ tm.assert_frame_equal(result, expected)
339
+
340
+ # one optional group followed by one normal group
341
+ s = Series(["A1", "B2", "3"], dtype=any_string_dtype)
342
+ result = s.str.extract("(?P<letter>[AB])?(?P<number>[123])", expand=True)
343
+ expected = DataFrame(
344
+ [["A", "1"], ["B", "2"], [np.nan, "3"]],
345
+ columns=["letter", "number"],
346
+ dtype=any_string_dtype,
347
+ )
348
+ tm.assert_frame_equal(result, expected)
349
+
350
+ # one normal group followed by one optional group
351
+ s = Series(["A1", "B2", "C"], dtype=any_string_dtype)
352
+ result = s.str.extract("(?P<letter>[ABC])(?P<number>[123])?", expand=True)
353
+ expected = DataFrame(
354
+ [["A", "1"], ["B", "2"], ["C", np.nan]],
355
+ columns=["letter", "number"],
356
+ dtype=any_string_dtype,
357
+ )
358
+ tm.assert_frame_equal(result, expected)
359
+
360
+
361
+ def test_extract_dataframe_capture_groups_index(index, any_string_dtype):
362
+ # GH6348
363
+ # not passing index to the extractor
364
+
365
+ data = ["A1", "B2", "C"]
366
+
367
+ if len(index) < len(data):
368
+ pytest.skip(f"Index needs more than {len(data)} values")
369
+
370
+ index = index[: len(data)]
371
+ s = Series(data, index=index, dtype=any_string_dtype)
372
+
373
+ result = s.str.extract(r"(\d)", expand=True)
374
+ expected = DataFrame(["1", "2", np.nan], index=index, dtype=any_string_dtype)
375
+ tm.assert_frame_equal(result, expected)
376
+
377
+ result = s.str.extract(r"(?P<letter>\D)(?P<number>\d)?", expand=True)
378
+ expected = DataFrame(
379
+ [["A", "1"], ["B", "2"], ["C", np.nan]],
380
+ columns=["letter", "number"],
381
+ index=index,
382
+ dtype=any_string_dtype,
383
+ )
384
+ tm.assert_frame_equal(result, expected)
385
+
386
+
387
+ def test_extract_single_group_returns_frame(any_string_dtype):
388
+ # GH11386 extract should always return DataFrame, even when
389
+ # there is only one group. Prior to v0.18.0, extract returned
390
+ # Series when there was only one group in the regex.
391
+ s = Series(["a3", "b3", "c2"], name="series_name", dtype=any_string_dtype)
392
+ result = s.str.extract(r"(?P<letter>[a-z])", expand=True)
393
+ expected = DataFrame({"letter": ["a", "b", "c"]}, dtype=any_string_dtype)
394
+ tm.assert_frame_equal(result, expected)
395
+
396
+
397
+ def test_extractall(any_string_dtype):
398
+ data = [
399
+ "dave@google.com",
400
+ "tdhock5@gmail.com",
401
+ "maudelaperriere@gmail.com",
402
+ "rob@gmail.com some text steve@gmail.com",
403
+ "a@b.com some text c@d.com and e@f.com",
404
+ np.nan,
405
+ "",
406
+ ]
407
+ expected_tuples = [
408
+ ("dave", "google", "com"),
409
+ ("tdhock5", "gmail", "com"),
410
+ ("maudelaperriere", "gmail", "com"),
411
+ ("rob", "gmail", "com"),
412
+ ("steve", "gmail", "com"),
413
+ ("a", "b", "com"),
414
+ ("c", "d", "com"),
415
+ ("e", "f", "com"),
416
+ ]
417
+ pat = r"""
418
+ (?P<user>[a-z0-9]+)
419
+ @
420
+ (?P<domain>[a-z]+)
421
+ \.
422
+ (?P<tld>[a-z]{2,4})
423
+ """
424
+ expected_columns = ["user", "domain", "tld"]
425
+ s = Series(data, dtype=any_string_dtype)
426
+ # extractall should return a DataFrame with one row for each match, indexed by the
427
+ # subject from which the match came.
428
+ expected_index = MultiIndex.from_tuples(
429
+ [(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (4, 0), (4, 1), (4, 2)],
430
+ names=(None, "match"),
431
+ )
432
+ expected = DataFrame(
433
+ expected_tuples, expected_index, expected_columns, dtype=any_string_dtype
434
+ )
435
+ result = s.str.extractall(pat, flags=re.VERBOSE)
436
+ tm.assert_frame_equal(result, expected)
437
+
438
+ # The index of the input Series should be used to construct the index of the output
439
+ # DataFrame:
440
+ mi = MultiIndex.from_tuples(
441
+ [
442
+ ("single", "Dave"),
443
+ ("single", "Toby"),
444
+ ("single", "Maude"),
445
+ ("multiple", "robAndSteve"),
446
+ ("multiple", "abcdef"),
447
+ ("none", "missing"),
448
+ ("none", "empty"),
449
+ ]
450
+ )
451
+ s = Series(data, index=mi, dtype=any_string_dtype)
452
+ expected_index = MultiIndex.from_tuples(
453
+ [
454
+ ("single", "Dave", 0),
455
+ ("single", "Toby", 0),
456
+ ("single", "Maude", 0),
457
+ ("multiple", "robAndSteve", 0),
458
+ ("multiple", "robAndSteve", 1),
459
+ ("multiple", "abcdef", 0),
460
+ ("multiple", "abcdef", 1),
461
+ ("multiple", "abcdef", 2),
462
+ ],
463
+ names=(None, None, "match"),
464
+ )
465
+ expected = DataFrame(
466
+ expected_tuples, expected_index, expected_columns, dtype=any_string_dtype
467
+ )
468
+ result = s.str.extractall(pat, flags=re.VERBOSE)
469
+ tm.assert_frame_equal(result, expected)
470
+
471
+ # MultiIndexed subject with names.
472
+ s = Series(data, index=mi, dtype=any_string_dtype)
473
+ s.index.names = ("matches", "description")
474
+ expected_index.names = ("matches", "description", "match")
475
+ expected = DataFrame(
476
+ expected_tuples, expected_index, expected_columns, dtype=any_string_dtype
477
+ )
478
+ result = s.str.extractall(pat, flags=re.VERBOSE)
479
+ tm.assert_frame_equal(result, expected)
480
+
481
+
482
+ @pytest.mark.parametrize(
483
+ "pat,expected_names",
484
+ [
485
+ # optional groups.
486
+ ("(?P<letter>[AB])?(?P<number>[123])", ["letter", "number"]),
487
+ # only one of two groups has a name.
488
+ ("([AB])?(?P<number>[123])", [0, "number"]),
489
+ ],
490
+ )
491
+ def test_extractall_column_names(pat, expected_names, any_string_dtype):
492
+ s = Series(["", "A1", "32"], dtype=any_string_dtype)
493
+
494
+ result = s.str.extractall(pat)
495
+ expected = DataFrame(
496
+ [("A", "1"), (np.nan, "3"), (np.nan, "2")],
497
+ index=MultiIndex.from_tuples([(1, 0), (2, 0), (2, 1)], names=(None, "match")),
498
+ columns=expected_names,
499
+ dtype=any_string_dtype,
500
+ )
501
+ tm.assert_frame_equal(result, expected)
502
+
503
+
504
+ def test_extractall_single_group(any_string_dtype):
505
+ s = Series(["a3", "b3", "d4c2"], name="series_name", dtype=any_string_dtype)
506
+ expected_index = MultiIndex.from_tuples(
507
+ [(0, 0), (1, 0), (2, 0), (2, 1)], names=(None, "match")
508
+ )
509
+
510
+ # extractall(one named group) returns DataFrame with one named column.
511
+ result = s.str.extractall(r"(?P<letter>[a-z])")
512
+ expected = DataFrame(
513
+ {"letter": ["a", "b", "d", "c"]}, index=expected_index, dtype=any_string_dtype
514
+ )
515
+ tm.assert_frame_equal(result, expected)
516
+
517
+ # extractall(one un-named group) returns DataFrame with one un-named column.
518
+ result = s.str.extractall(r"([a-z])")
519
+ expected = DataFrame(
520
+ ["a", "b", "d", "c"], index=expected_index, dtype=any_string_dtype
521
+ )
522
+ tm.assert_frame_equal(result, expected)
523
+
524
+
525
+ def test_extractall_single_group_with_quantifier(any_string_dtype):
526
+ # GH#13382
527
+ # extractall(one un-named group with quantifier) returns DataFrame with one un-named
528
+ # column.
529
+ s = Series(["ab3", "abc3", "d4cd2"], name="series_name", dtype=any_string_dtype)
530
+ result = s.str.extractall(r"([a-z]+)")
531
+ expected = DataFrame(
532
+ ["ab", "abc", "d", "cd"],
533
+ index=MultiIndex.from_tuples(
534
+ [(0, 0), (1, 0), (2, 0), (2, 1)], names=(None, "match")
535
+ ),
536
+ dtype=any_string_dtype,
537
+ )
538
+ tm.assert_frame_equal(result, expected)
539
+
540
+
541
+ @pytest.mark.parametrize(
542
+ "data, names",
543
+ [
544
+ ([], (None,)),
545
+ ([], ("i1",)),
546
+ ([], (None, "i2")),
547
+ ([], ("i1", "i2")),
548
+ (["a3", "b3", "d4c2"], (None,)),
549
+ (["a3", "b3", "d4c2"], ("i1", "i2")),
550
+ (["a3", "b3", "d4c2"], (None, "i2")),
551
+ (["a3", "b3", "d4c2"], ("i1", "i2")),
552
+ ],
553
+ )
554
+ def test_extractall_no_matches(data, names, any_string_dtype):
555
+ # GH19075 extractall with no matches should return a valid MultiIndex
556
+ n = len(data)
557
+ if len(names) == 1:
558
+ index = Index(range(n), name=names[0])
559
+ else:
560
+ tuples = (tuple([i] * (n - 1)) for i in range(n))
561
+ index = MultiIndex.from_tuples(tuples, names=names)
562
+ s = Series(data, name="series_name", index=index, dtype=any_string_dtype)
563
+ expected_index = MultiIndex.from_tuples([], names=(names + ("match",)))
564
+
565
+ # one un-named group.
566
+ result = s.str.extractall("(z)")
567
+ expected = DataFrame(columns=[0], index=expected_index, dtype=any_string_dtype)
568
+ tm.assert_frame_equal(result, expected)
569
+
570
+ # two un-named groups.
571
+ result = s.str.extractall("(z)(z)")
572
+ expected = DataFrame(columns=[0, 1], index=expected_index, dtype=any_string_dtype)
573
+ tm.assert_frame_equal(result, expected)
574
+
575
+ # one named group.
576
+ result = s.str.extractall("(?P<first>z)")
577
+ expected = DataFrame(
578
+ columns=["first"], index=expected_index, dtype=any_string_dtype
579
+ )
580
+ tm.assert_frame_equal(result, expected)
581
+
582
+ # two named groups.
583
+ result = s.str.extractall("(?P<first>z)(?P<second>z)")
584
+ expected = DataFrame(
585
+ columns=["first", "second"], index=expected_index, dtype=any_string_dtype
586
+ )
587
+ tm.assert_frame_equal(result, expected)
588
+
589
+ # one named, one un-named.
590
+ result = s.str.extractall("(z)(?P<second>z)")
591
+ expected = DataFrame(
592
+ columns=[0, "second"], index=expected_index, dtype=any_string_dtype
593
+ )
594
+ tm.assert_frame_equal(result, expected)
595
+
596
+
597
+ def test_extractall_stringindex(any_string_dtype):
598
+ s = Series(["a1a2", "b1", "c1"], name="xxx", dtype=any_string_dtype)
599
+ result = s.str.extractall(r"[ab](?P<digit>\d)")
600
+ expected = DataFrame(
601
+ {"digit": ["1", "2", "1"]},
602
+ index=MultiIndex.from_tuples([(0, 0), (0, 1), (1, 0)], names=[None, "match"]),
603
+ dtype=any_string_dtype,
604
+ )
605
+ tm.assert_frame_equal(result, expected)
606
+
607
+ # index should return the same result as the default index without name thus
608
+ # index.name doesn't affect to the result
609
+ if any_string_dtype == "object":
610
+ for idx in [
611
+ Index(["a1a2", "b1", "c1"], dtype=object),
612
+ Index(["a1a2", "b1", "c1"], name="xxx", dtype=object),
613
+ ]:
614
+ result = idx.str.extractall(r"[ab](?P<digit>\d)")
615
+ tm.assert_frame_equal(result, expected)
616
+
617
+ s = Series(
618
+ ["a1a2", "b1", "c1"],
619
+ name="s_name",
620
+ index=Index(["XX", "yy", "zz"], name="idx_name"),
621
+ dtype=any_string_dtype,
622
+ )
623
+ result = s.str.extractall(r"[ab](?P<digit>\d)")
624
+ expected = DataFrame(
625
+ {"digit": ["1", "2", "1"]},
626
+ index=MultiIndex.from_tuples(
627
+ [("XX", 0), ("XX", 1), ("yy", 0)], names=["idx_name", "match"]
628
+ ),
629
+ dtype=any_string_dtype,
630
+ )
631
+ tm.assert_frame_equal(result, expected)
632
+
633
+
634
+ def test_extractall_no_capture_groups_raises(any_string_dtype):
635
+ # Does not make sense to use extractall with a regex that has no capture groups.
636
+ # (it returns DataFrame with one column for each capture group)
637
+ s = Series(["a3", "b3", "d4c2"], name="series_name", dtype=any_string_dtype)
638
+ with pytest.raises(ValueError, match="no capture groups"):
639
+ s.str.extractall(r"[a-z]")
640
+
641
+
642
+ def test_extract_index_one_two_groups():
643
+ s = Series(["a3", "b3", "d4c2"], index=["A3", "B3", "D4"], name="series_name")
644
+ r = s.index.str.extract(r"([A-Z])", expand=True)
645
+ e = DataFrame(["A", "B", "D"])
646
+ tm.assert_frame_equal(r, e)
647
+
648
+ # Prior to v0.18.0, index.str.extract(regex with one group)
649
+ # returned Index. With more than one group, extract raised an
650
+ # error (GH9980). Now extract always returns DataFrame.
651
+ r = s.index.str.extract(r"(?P<letter>[A-Z])(?P<digit>[0-9])", expand=True)
652
+ e_list = [("A", "3"), ("B", "3"), ("D", "4")]
653
+ e = DataFrame(e_list, columns=["letter", "digit"])
654
+ tm.assert_frame_equal(r, e)
655
+
656
+
657
+ def test_extractall_same_as_extract(any_string_dtype):
658
+ s = Series(["a3", "b3", "c2"], name="series_name", dtype=any_string_dtype)
659
+
660
+ pattern_two_noname = r"([a-z])([0-9])"
661
+ extract_two_noname = s.str.extract(pattern_two_noname, expand=True)
662
+ has_multi_index = s.str.extractall(pattern_two_noname)
663
+ no_multi_index = has_multi_index.xs(0, level="match")
664
+ tm.assert_frame_equal(extract_two_noname, no_multi_index)
665
+
666
+ pattern_two_named = r"(?P<letter>[a-z])(?P<digit>[0-9])"
667
+ extract_two_named = s.str.extract(pattern_two_named, expand=True)
668
+ has_multi_index = s.str.extractall(pattern_two_named)
669
+ no_multi_index = has_multi_index.xs(0, level="match")
670
+ tm.assert_frame_equal(extract_two_named, no_multi_index)
671
+
672
+ pattern_one_named = r"(?P<group_name>[a-z])"
673
+ extract_one_named = s.str.extract(pattern_one_named, expand=True)
674
+ has_multi_index = s.str.extractall(pattern_one_named)
675
+ no_multi_index = has_multi_index.xs(0, level="match")
676
+ tm.assert_frame_equal(extract_one_named, no_multi_index)
677
+
678
+ pattern_one_noname = r"([a-z])"
679
+ extract_one_noname = s.str.extract(pattern_one_noname, expand=True)
680
+ has_multi_index = s.str.extractall(pattern_one_noname)
681
+ no_multi_index = has_multi_index.xs(0, level="match")
682
+ tm.assert_frame_equal(extract_one_noname, no_multi_index)
683
+
684
+
685
+ def test_extractall_same_as_extract_subject_index(any_string_dtype):
686
+ # same as above tests, but s has an MultiIndex.
687
+ mi = MultiIndex.from_tuples(
688
+ [("A", "first"), ("B", "second"), ("C", "third")],
689
+ names=("capital", "ordinal"),
690
+ )
691
+ s = Series(["a3", "b3", "c2"], index=mi, name="series_name", dtype=any_string_dtype)
692
+
693
+ pattern_two_noname = r"([a-z])([0-9])"
694
+ extract_two_noname = s.str.extract(pattern_two_noname, expand=True)
695
+ has_match_index = s.str.extractall(pattern_two_noname)
696
+ no_match_index = has_match_index.xs(0, level="match")
697
+ tm.assert_frame_equal(extract_two_noname, no_match_index)
698
+
699
+ pattern_two_named = r"(?P<letter>[a-z])(?P<digit>[0-9])"
700
+ extract_two_named = s.str.extract(pattern_two_named, expand=True)
701
+ has_match_index = s.str.extractall(pattern_two_named)
702
+ no_match_index = has_match_index.xs(0, level="match")
703
+ tm.assert_frame_equal(extract_two_named, no_match_index)
704
+
705
+ pattern_one_named = r"(?P<group_name>[a-z])"
706
+ extract_one_named = s.str.extract(pattern_one_named, expand=True)
707
+ has_match_index = s.str.extractall(pattern_one_named)
708
+ no_match_index = has_match_index.xs(0, level="match")
709
+ tm.assert_frame_equal(extract_one_named, no_match_index)
710
+
711
+ pattern_one_noname = r"([a-z])"
712
+ extract_one_noname = s.str.extract(pattern_one_noname, expand=True)
713
+ has_match_index = s.str.extractall(pattern_one_noname)
714
+ no_match_index = has_match_index.xs(0, level="match")
715
+ tm.assert_frame_equal(extract_one_noname, no_match_index)
716
+
717
+
718
+ def test_extractall_preserves_dtype():
719
+ # Ensure that when extractall is called on a series with specific dtypes set, that
720
+ # the dtype is preserved in the resulting DataFrame's column.
721
+ pa = pytest.importorskip("pyarrow")
722
+
723
+ result = Series(["abc", "ab"], dtype=ArrowDtype(pa.string())).str.extractall("(ab)")
724
+ assert result.dtypes[0] == "string[pyarrow]"