numpy 2.4.1__pp311-pypy311_pp73-macosx_14_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- numpy/__config__.py +170 -0
- numpy/__config__.pyi +108 -0
- numpy/__init__.cython-30.pxd +1242 -0
- numpy/__init__.pxd +1155 -0
- numpy/__init__.py +942 -0
- numpy/__init__.pyi +6202 -0
- numpy/_array_api_info.py +346 -0
- numpy/_array_api_info.pyi +206 -0
- numpy/_configtool.py +39 -0
- numpy/_configtool.pyi +1 -0
- numpy/_core/__init__.py +201 -0
- numpy/_core/__init__.pyi +666 -0
- numpy/_core/_add_newdocs.py +7151 -0
- numpy/_core/_add_newdocs.pyi +2 -0
- numpy/_core/_add_newdocs_scalars.py +381 -0
- numpy/_core/_add_newdocs_scalars.pyi +16 -0
- numpy/_core/_asarray.py +130 -0
- numpy/_core/_asarray.pyi +43 -0
- numpy/_core/_dtype.py +366 -0
- numpy/_core/_dtype.pyi +56 -0
- numpy/_core/_dtype_ctypes.py +120 -0
- numpy/_core/_dtype_ctypes.pyi +83 -0
- numpy/_core/_exceptions.py +162 -0
- numpy/_core/_exceptions.pyi +54 -0
- numpy/_core/_internal.py +968 -0
- numpy/_core/_internal.pyi +61 -0
- numpy/_core/_methods.py +252 -0
- numpy/_core/_methods.pyi +22 -0
- numpy/_core/_multiarray_tests.pypy311-pp73-darwin.so +0 -0
- numpy/_core/_multiarray_umath.pypy311-pp73-darwin.so +0 -0
- numpy/_core/_operand_flag_tests.pypy311-pp73-darwin.so +0 -0
- numpy/_core/_rational_tests.pypy311-pp73-darwin.so +0 -0
- numpy/_core/_simd.pyi +35 -0
- numpy/_core/_simd.pypy311-pp73-darwin.so +0 -0
- numpy/_core/_string_helpers.py +100 -0
- numpy/_core/_string_helpers.pyi +12 -0
- numpy/_core/_struct_ufunc_tests.pypy311-pp73-darwin.so +0 -0
- numpy/_core/_type_aliases.py +131 -0
- numpy/_core/_type_aliases.pyi +86 -0
- numpy/_core/_ufunc_config.py +515 -0
- numpy/_core/_ufunc_config.pyi +69 -0
- numpy/_core/_umath_tests.pyi +47 -0
- numpy/_core/_umath_tests.pypy311-pp73-darwin.so +0 -0
- numpy/_core/arrayprint.py +1779 -0
- numpy/_core/arrayprint.pyi +158 -0
- numpy/_core/cversions.py +13 -0
- numpy/_core/defchararray.py +1414 -0
- numpy/_core/defchararray.pyi +1150 -0
- numpy/_core/einsumfunc.py +1650 -0
- numpy/_core/einsumfunc.pyi +184 -0
- numpy/_core/fromnumeric.py +4233 -0
- numpy/_core/fromnumeric.pyi +1735 -0
- numpy/_core/function_base.py +547 -0
- numpy/_core/function_base.pyi +276 -0
- numpy/_core/getlimits.py +462 -0
- numpy/_core/getlimits.pyi +124 -0
- numpy/_core/include/numpy/__multiarray_api.c +376 -0
- numpy/_core/include/numpy/__multiarray_api.h +1628 -0
- numpy/_core/include/numpy/__ufunc_api.c +55 -0
- numpy/_core/include/numpy/__ufunc_api.h +349 -0
- numpy/_core/include/numpy/_neighborhood_iterator_imp.h +90 -0
- numpy/_core/include/numpy/_numpyconfig.h +33 -0
- numpy/_core/include/numpy/_public_dtype_api_table.h +86 -0
- numpy/_core/include/numpy/arrayobject.h +7 -0
- numpy/_core/include/numpy/arrayscalars.h +198 -0
- numpy/_core/include/numpy/dtype_api.h +547 -0
- numpy/_core/include/numpy/halffloat.h +70 -0
- numpy/_core/include/numpy/ndarrayobject.h +304 -0
- numpy/_core/include/numpy/ndarraytypes.h +1982 -0
- numpy/_core/include/numpy/npy_2_compat.h +249 -0
- numpy/_core/include/numpy/npy_2_complexcompat.h +28 -0
- numpy/_core/include/numpy/npy_3kcompat.h +374 -0
- numpy/_core/include/numpy/npy_common.h +989 -0
- numpy/_core/include/numpy/npy_cpu.h +126 -0
- numpy/_core/include/numpy/npy_endian.h +79 -0
- numpy/_core/include/numpy/npy_math.h +602 -0
- numpy/_core/include/numpy/npy_no_deprecated_api.h +20 -0
- numpy/_core/include/numpy/npy_os.h +42 -0
- numpy/_core/include/numpy/numpyconfig.h +185 -0
- numpy/_core/include/numpy/random/LICENSE.txt +21 -0
- numpy/_core/include/numpy/random/bitgen.h +20 -0
- numpy/_core/include/numpy/random/distributions.h +209 -0
- numpy/_core/include/numpy/random/libdivide.h +2079 -0
- numpy/_core/include/numpy/ufuncobject.h +343 -0
- numpy/_core/include/numpy/utils.h +37 -0
- numpy/_core/lib/libnpymath.a +0 -0
- numpy/_core/lib/npy-pkg-config/mlib.ini +12 -0
- numpy/_core/lib/npy-pkg-config/npymath.ini +20 -0
- numpy/_core/lib/pkgconfig/numpy.pc +7 -0
- numpy/_core/memmap.py +363 -0
- numpy/_core/memmap.pyi +3 -0
- numpy/_core/multiarray.py +1740 -0
- numpy/_core/multiarray.pyi +1316 -0
- numpy/_core/numeric.py +2758 -0
- numpy/_core/numeric.pyi +1276 -0
- numpy/_core/numerictypes.py +633 -0
- numpy/_core/numerictypes.pyi +196 -0
- numpy/_core/overrides.py +188 -0
- numpy/_core/overrides.pyi +47 -0
- numpy/_core/printoptions.py +32 -0
- numpy/_core/printoptions.pyi +28 -0
- numpy/_core/records.py +1088 -0
- numpy/_core/records.pyi +340 -0
- numpy/_core/shape_base.py +996 -0
- numpy/_core/shape_base.pyi +182 -0
- numpy/_core/strings.py +1813 -0
- numpy/_core/strings.pyi +536 -0
- numpy/_core/tests/_locales.py +72 -0
- numpy/_core/tests/_natype.py +144 -0
- numpy/_core/tests/data/astype_copy.pkl +0 -0
- numpy/_core/tests/data/generate_umath_validation_data.cpp +170 -0
- numpy/_core/tests/data/recarray_from_file.fits +0 -0
- numpy/_core/tests/data/umath-validation-set-README.txt +15 -0
- numpy/_core/tests/data/umath-validation-set-arccos.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arccosh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arcsin.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arcsinh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arctan.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-arctanh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-cbrt.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-cos.csv +1375 -0
- numpy/_core/tests/data/umath-validation-set-cosh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-exp.csv +412 -0
- numpy/_core/tests/data/umath-validation-set-exp2.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-expm1.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-log.csv +271 -0
- numpy/_core/tests/data/umath-validation-set-log10.csv +1629 -0
- numpy/_core/tests/data/umath-validation-set-log1p.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-log2.csv +1629 -0
- numpy/_core/tests/data/umath-validation-set-sin.csv +1370 -0
- numpy/_core/tests/data/umath-validation-set-sinh.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-tan.csv +1429 -0
- numpy/_core/tests/data/umath-validation-set-tanh.csv +1429 -0
- numpy/_core/tests/examples/cython/checks.pyx +373 -0
- numpy/_core/tests/examples/cython/meson.build +43 -0
- numpy/_core/tests/examples/cython/setup.py +39 -0
- numpy/_core/tests/examples/limited_api/limited_api1.c +17 -0
- numpy/_core/tests/examples/limited_api/limited_api2.pyx +11 -0
- numpy/_core/tests/examples/limited_api/limited_api_latest.c +19 -0
- numpy/_core/tests/examples/limited_api/meson.build +59 -0
- numpy/_core/tests/examples/limited_api/setup.py +24 -0
- numpy/_core/tests/test__exceptions.py +90 -0
- numpy/_core/tests/test_abc.py +54 -0
- numpy/_core/tests/test_api.py +655 -0
- numpy/_core/tests/test_argparse.py +90 -0
- numpy/_core/tests/test_array_api_info.py +113 -0
- numpy/_core/tests/test_array_coercion.py +928 -0
- numpy/_core/tests/test_array_interface.py +222 -0
- numpy/_core/tests/test_arraymethod.py +84 -0
- numpy/_core/tests/test_arrayobject.py +75 -0
- numpy/_core/tests/test_arrayprint.py +1324 -0
- numpy/_core/tests/test_casting_floatingpoint_errors.py +154 -0
- numpy/_core/tests/test_casting_unittests.py +955 -0
- numpy/_core/tests/test_conversion_utils.py +209 -0
- numpy/_core/tests/test_cpu_dispatcher.py +48 -0
- numpy/_core/tests/test_cpu_features.py +450 -0
- numpy/_core/tests/test_custom_dtypes.py +393 -0
- numpy/_core/tests/test_cython.py +352 -0
- numpy/_core/tests/test_datetime.py +2792 -0
- numpy/_core/tests/test_defchararray.py +858 -0
- numpy/_core/tests/test_deprecations.py +460 -0
- numpy/_core/tests/test_dlpack.py +190 -0
- numpy/_core/tests/test_dtype.py +2110 -0
- numpy/_core/tests/test_einsum.py +1351 -0
- numpy/_core/tests/test_errstate.py +131 -0
- numpy/_core/tests/test_extint128.py +217 -0
- numpy/_core/tests/test_finfo.py +86 -0
- numpy/_core/tests/test_function_base.py +504 -0
- numpy/_core/tests/test_getlimits.py +171 -0
- numpy/_core/tests/test_half.py +593 -0
- numpy/_core/tests/test_hashtable.py +36 -0
- numpy/_core/tests/test_indexerrors.py +122 -0
- numpy/_core/tests/test_indexing.py +1692 -0
- numpy/_core/tests/test_item_selection.py +167 -0
- numpy/_core/tests/test_limited_api.py +102 -0
- numpy/_core/tests/test_longdouble.py +370 -0
- numpy/_core/tests/test_mem_overlap.py +933 -0
- numpy/_core/tests/test_mem_policy.py +453 -0
- numpy/_core/tests/test_memmap.py +248 -0
- numpy/_core/tests/test_multiarray.py +11008 -0
- numpy/_core/tests/test_multiprocessing.py +55 -0
- numpy/_core/tests/test_multithreading.py +377 -0
- numpy/_core/tests/test_nditer.py +3533 -0
- numpy/_core/tests/test_nep50_promotions.py +287 -0
- numpy/_core/tests/test_numeric.py +4295 -0
- numpy/_core/tests/test_numerictypes.py +650 -0
- numpy/_core/tests/test_overrides.py +800 -0
- numpy/_core/tests/test_print.py +202 -0
- numpy/_core/tests/test_protocols.py +46 -0
- numpy/_core/tests/test_records.py +544 -0
- numpy/_core/tests/test_regression.py +2677 -0
- numpy/_core/tests/test_scalar_ctors.py +203 -0
- numpy/_core/tests/test_scalar_methods.py +328 -0
- numpy/_core/tests/test_scalarbuffer.py +153 -0
- numpy/_core/tests/test_scalarinherit.py +105 -0
- numpy/_core/tests/test_scalarmath.py +1168 -0
- numpy/_core/tests/test_scalarprint.py +403 -0
- numpy/_core/tests/test_shape_base.py +904 -0
- numpy/_core/tests/test_simd.py +1345 -0
- numpy/_core/tests/test_simd_module.py +105 -0
- numpy/_core/tests/test_stringdtype.py +1855 -0
- numpy/_core/tests/test_strings.py +1523 -0
- numpy/_core/tests/test_ufunc.py +3405 -0
- numpy/_core/tests/test_umath.py +4962 -0
- numpy/_core/tests/test_umath_accuracy.py +132 -0
- numpy/_core/tests/test_umath_complex.py +631 -0
- numpy/_core/tests/test_unicode.py +369 -0
- numpy/_core/umath.py +60 -0
- numpy/_core/umath.pyi +232 -0
- numpy/_distributor_init.py +15 -0
- numpy/_distributor_init.pyi +1 -0
- numpy/_expired_attrs_2_0.py +78 -0
- numpy/_expired_attrs_2_0.pyi +61 -0
- numpy/_globals.py +121 -0
- numpy/_globals.pyi +17 -0
- numpy/_pyinstaller/__init__.py +0 -0
- numpy/_pyinstaller/__init__.pyi +0 -0
- numpy/_pyinstaller/hook-numpy.py +36 -0
- numpy/_pyinstaller/hook-numpy.pyi +6 -0
- numpy/_pyinstaller/tests/__init__.py +16 -0
- numpy/_pyinstaller/tests/pyinstaller-smoke.py +32 -0
- numpy/_pyinstaller/tests/test_pyinstaller.py +35 -0
- numpy/_pytesttester.py +201 -0
- numpy/_pytesttester.pyi +18 -0
- numpy/_typing/__init__.py +173 -0
- numpy/_typing/_add_docstring.py +153 -0
- numpy/_typing/_array_like.py +106 -0
- numpy/_typing/_char_codes.py +213 -0
- numpy/_typing/_dtype_like.py +114 -0
- numpy/_typing/_extended_precision.py +15 -0
- numpy/_typing/_nbit.py +19 -0
- numpy/_typing/_nbit_base.py +94 -0
- numpy/_typing/_nbit_base.pyi +39 -0
- numpy/_typing/_nested_sequence.py +79 -0
- numpy/_typing/_scalars.py +20 -0
- numpy/_typing/_shape.py +8 -0
- numpy/_typing/_ufunc.py +7 -0
- numpy/_typing/_ufunc.pyi +975 -0
- numpy/_utils/__init__.py +95 -0
- numpy/_utils/__init__.pyi +28 -0
- numpy/_utils/_convertions.py +18 -0
- numpy/_utils/_convertions.pyi +4 -0
- numpy/_utils/_inspect.py +192 -0
- numpy/_utils/_inspect.pyi +70 -0
- numpy/_utils/_pep440.py +486 -0
- numpy/_utils/_pep440.pyi +118 -0
- numpy/char/__init__.py +2 -0
- numpy/char/__init__.pyi +111 -0
- numpy/conftest.py +248 -0
- numpy/core/__init__.py +33 -0
- numpy/core/__init__.pyi +0 -0
- numpy/core/_dtype.py +10 -0
- numpy/core/_dtype.pyi +0 -0
- numpy/core/_dtype_ctypes.py +10 -0
- numpy/core/_dtype_ctypes.pyi +0 -0
- numpy/core/_internal.py +27 -0
- numpy/core/_multiarray_umath.py +57 -0
- numpy/core/_utils.py +21 -0
- numpy/core/arrayprint.py +10 -0
- numpy/core/defchararray.py +10 -0
- numpy/core/einsumfunc.py +10 -0
- numpy/core/fromnumeric.py +10 -0
- numpy/core/function_base.py +10 -0
- numpy/core/getlimits.py +10 -0
- numpy/core/multiarray.py +25 -0
- numpy/core/numeric.py +12 -0
- numpy/core/numerictypes.py +10 -0
- numpy/core/overrides.py +10 -0
- numpy/core/overrides.pyi +7 -0
- numpy/core/records.py +10 -0
- numpy/core/shape_base.py +10 -0
- numpy/core/umath.py +10 -0
- numpy/ctypeslib/__init__.py +13 -0
- numpy/ctypeslib/__init__.pyi +15 -0
- numpy/ctypeslib/_ctypeslib.py +603 -0
- numpy/ctypeslib/_ctypeslib.pyi +236 -0
- numpy/distutils/__init__.py +64 -0
- numpy/distutils/__init__.pyi +4 -0
- numpy/distutils/__pycache__/conv_template.pypy311.pyc +0 -0
- numpy/distutils/_shell_utils.py +87 -0
- numpy/distutils/armccompiler.py +26 -0
- numpy/distutils/ccompiler.py +826 -0
- numpy/distutils/ccompiler_opt.py +2668 -0
- numpy/distutils/checks/cpu_asimd.c +27 -0
- numpy/distutils/checks/cpu_asimddp.c +16 -0
- numpy/distutils/checks/cpu_asimdfhm.c +19 -0
- numpy/distutils/checks/cpu_asimdhp.c +15 -0
- numpy/distutils/checks/cpu_avx.c +20 -0
- numpy/distutils/checks/cpu_avx2.c +20 -0
- numpy/distutils/checks/cpu_avx512_clx.c +22 -0
- numpy/distutils/checks/cpu_avx512_cnl.c +24 -0
- numpy/distutils/checks/cpu_avx512_icl.c +26 -0
- numpy/distutils/checks/cpu_avx512_knl.c +25 -0
- numpy/distutils/checks/cpu_avx512_knm.c +30 -0
- numpy/distutils/checks/cpu_avx512_skx.c +26 -0
- numpy/distutils/checks/cpu_avx512_spr.c +26 -0
- numpy/distutils/checks/cpu_avx512cd.c +20 -0
- numpy/distutils/checks/cpu_avx512f.c +20 -0
- numpy/distutils/checks/cpu_f16c.c +22 -0
- numpy/distutils/checks/cpu_fma3.c +22 -0
- numpy/distutils/checks/cpu_fma4.c +13 -0
- numpy/distutils/checks/cpu_lsx.c +11 -0
- numpy/distutils/checks/cpu_neon.c +19 -0
- numpy/distutils/checks/cpu_neon_fp16.c +11 -0
- numpy/distutils/checks/cpu_neon_vfpv4.c +21 -0
- numpy/distutils/checks/cpu_popcnt.c +32 -0
- numpy/distutils/checks/cpu_rvv.c +13 -0
- numpy/distutils/checks/cpu_sse.c +20 -0
- numpy/distutils/checks/cpu_sse2.c +20 -0
- numpy/distutils/checks/cpu_sse3.c +20 -0
- numpy/distutils/checks/cpu_sse41.c +20 -0
- numpy/distutils/checks/cpu_sse42.c +20 -0
- numpy/distutils/checks/cpu_ssse3.c +20 -0
- numpy/distutils/checks/cpu_sve.c +14 -0
- numpy/distutils/checks/cpu_vsx.c +21 -0
- numpy/distutils/checks/cpu_vsx2.c +13 -0
- numpy/distutils/checks/cpu_vsx3.c +13 -0
- numpy/distutils/checks/cpu_vsx4.c +14 -0
- numpy/distutils/checks/cpu_vx.c +16 -0
- numpy/distutils/checks/cpu_vxe.c +25 -0
- numpy/distutils/checks/cpu_vxe2.c +21 -0
- numpy/distutils/checks/cpu_xop.c +12 -0
- numpy/distutils/checks/extra_avx512bw_mask.c +18 -0
- numpy/distutils/checks/extra_avx512dq_mask.c +16 -0
- numpy/distutils/checks/extra_avx512f_reduce.c +41 -0
- numpy/distutils/checks/extra_vsx3_half_double.c +12 -0
- numpy/distutils/checks/extra_vsx4_mma.c +21 -0
- numpy/distutils/checks/extra_vsx_asm.c +36 -0
- numpy/distutils/checks/test_flags.c +1 -0
- numpy/distutils/command/__init__.py +41 -0
- numpy/distutils/command/autodist.py +148 -0
- numpy/distutils/command/bdist_rpm.py +22 -0
- numpy/distutils/command/build.py +62 -0
- numpy/distutils/command/build_clib.py +469 -0
- numpy/distutils/command/build_ext.py +752 -0
- numpy/distutils/command/build_py.py +31 -0
- numpy/distutils/command/build_scripts.py +49 -0
- numpy/distutils/command/build_src.py +773 -0
- numpy/distutils/command/config.py +516 -0
- numpy/distutils/command/config_compiler.py +126 -0
- numpy/distutils/command/develop.py +15 -0
- numpy/distutils/command/egg_info.py +25 -0
- numpy/distutils/command/install.py +79 -0
- numpy/distutils/command/install_clib.py +40 -0
- numpy/distutils/command/install_data.py +24 -0
- numpy/distutils/command/install_headers.py +25 -0
- numpy/distutils/command/sdist.py +27 -0
- numpy/distutils/conv_template.py +329 -0
- numpy/distutils/core.py +215 -0
- numpy/distutils/cpuinfo.py +683 -0
- numpy/distutils/exec_command.py +315 -0
- numpy/distutils/extension.py +101 -0
- numpy/distutils/fcompiler/__init__.py +1035 -0
- numpy/distutils/fcompiler/absoft.py +158 -0
- numpy/distutils/fcompiler/arm.py +71 -0
- numpy/distutils/fcompiler/compaq.py +120 -0
- numpy/distutils/fcompiler/environment.py +88 -0
- numpy/distutils/fcompiler/fujitsu.py +46 -0
- numpy/distutils/fcompiler/g95.py +42 -0
- numpy/distutils/fcompiler/gnu.py +555 -0
- numpy/distutils/fcompiler/hpux.py +41 -0
- numpy/distutils/fcompiler/ibm.py +97 -0
- numpy/distutils/fcompiler/intel.py +211 -0
- numpy/distutils/fcompiler/lahey.py +45 -0
- numpy/distutils/fcompiler/mips.py +54 -0
- numpy/distutils/fcompiler/nag.py +87 -0
- numpy/distutils/fcompiler/none.py +28 -0
- numpy/distutils/fcompiler/nv.py +53 -0
- numpy/distutils/fcompiler/pathf95.py +33 -0
- numpy/distutils/fcompiler/pg.py +128 -0
- numpy/distutils/fcompiler/sun.py +51 -0
- numpy/distutils/fcompiler/vast.py +52 -0
- numpy/distutils/from_template.py +261 -0
- numpy/distutils/fujitsuccompiler.py +28 -0
- numpy/distutils/intelccompiler.py +106 -0
- numpy/distutils/lib2def.py +116 -0
- numpy/distutils/line_endings.py +77 -0
- numpy/distutils/log.py +111 -0
- numpy/distutils/mingw/gfortran_vs2003_hack.c +6 -0
- numpy/distutils/mingw32ccompiler.py +620 -0
- numpy/distutils/misc_util.py +2484 -0
- numpy/distutils/msvc9compiler.py +63 -0
- numpy/distutils/msvccompiler.py +76 -0
- numpy/distutils/npy_pkg_config.py +441 -0
- numpy/distutils/numpy_distribution.py +17 -0
- numpy/distutils/pathccompiler.py +21 -0
- numpy/distutils/system_info.py +3267 -0
- numpy/distutils/tests/__init__.py +0 -0
- numpy/distutils/tests/test_build_ext.py +74 -0
- numpy/distutils/tests/test_ccompiler_opt.py +808 -0
- numpy/distutils/tests/test_ccompiler_opt_conf.py +176 -0
- numpy/distutils/tests/test_exec_command.py +217 -0
- numpy/distutils/tests/test_fcompiler.py +43 -0
- numpy/distutils/tests/test_fcompiler_gnu.py +55 -0
- numpy/distutils/tests/test_fcompiler_intel.py +30 -0
- numpy/distutils/tests/test_fcompiler_nagfor.py +22 -0
- numpy/distutils/tests/test_from_template.py +44 -0
- numpy/distutils/tests/test_log.py +34 -0
- numpy/distutils/tests/test_mingw32ccompiler.py +47 -0
- numpy/distutils/tests/test_misc_util.py +88 -0
- numpy/distutils/tests/test_npy_pkg_config.py +84 -0
- numpy/distutils/tests/test_shell_utils.py +79 -0
- numpy/distutils/tests/test_system_info.py +334 -0
- numpy/distutils/tests/utilities.py +90 -0
- numpy/distutils/unixccompiler.py +141 -0
- numpy/doc/ufuncs.py +138 -0
- numpy/dtypes.py +41 -0
- numpy/dtypes.pyi +630 -0
- numpy/exceptions.py +246 -0
- numpy/exceptions.pyi +27 -0
- numpy/f2py/__init__.py +86 -0
- numpy/f2py/__init__.pyi +5 -0
- numpy/f2py/__main__.py +5 -0
- numpy/f2py/__version__.py +1 -0
- numpy/f2py/__version__.pyi +1 -0
- numpy/f2py/_backends/__init__.py +9 -0
- numpy/f2py/_backends/__init__.pyi +5 -0
- numpy/f2py/_backends/_backend.py +44 -0
- numpy/f2py/_backends/_backend.pyi +46 -0
- numpy/f2py/_backends/_distutils.py +76 -0
- numpy/f2py/_backends/_distutils.pyi +13 -0
- numpy/f2py/_backends/_meson.py +244 -0
- numpy/f2py/_backends/_meson.pyi +62 -0
- numpy/f2py/_backends/meson.build.template +58 -0
- numpy/f2py/_isocbind.py +62 -0
- numpy/f2py/_isocbind.pyi +13 -0
- numpy/f2py/_src_pyf.py +247 -0
- numpy/f2py/_src_pyf.pyi +28 -0
- numpy/f2py/auxfuncs.py +1004 -0
- numpy/f2py/auxfuncs.pyi +262 -0
- numpy/f2py/capi_maps.py +811 -0
- numpy/f2py/capi_maps.pyi +33 -0
- numpy/f2py/cb_rules.py +665 -0
- numpy/f2py/cb_rules.pyi +17 -0
- numpy/f2py/cfuncs.py +1563 -0
- numpy/f2py/cfuncs.pyi +31 -0
- numpy/f2py/common_rules.py +143 -0
- numpy/f2py/common_rules.pyi +9 -0
- numpy/f2py/crackfortran.py +3725 -0
- numpy/f2py/crackfortran.pyi +266 -0
- numpy/f2py/diagnose.py +149 -0
- numpy/f2py/diagnose.pyi +1 -0
- numpy/f2py/f2py2e.py +788 -0
- numpy/f2py/f2py2e.pyi +74 -0
- numpy/f2py/f90mod_rules.py +269 -0
- numpy/f2py/f90mod_rules.pyi +16 -0
- numpy/f2py/func2subr.py +329 -0
- numpy/f2py/func2subr.pyi +7 -0
- numpy/f2py/rules.py +1629 -0
- numpy/f2py/rules.pyi +41 -0
- numpy/f2py/setup.cfg +3 -0
- numpy/f2py/src/fortranobject.c +1436 -0
- numpy/f2py/src/fortranobject.h +173 -0
- numpy/f2py/symbolic.py +1518 -0
- numpy/f2py/symbolic.pyi +219 -0
- numpy/f2py/tests/__init__.py +16 -0
- numpy/f2py/tests/src/abstract_interface/foo.f90 +34 -0
- numpy/f2py/tests/src/abstract_interface/gh18403_mod.f90 +6 -0
- numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +235 -0
- numpy/f2py/tests/src/assumed_shape/.f2py_f2cmap +1 -0
- numpy/f2py/tests/src/assumed_shape/foo_free.f90 +34 -0
- numpy/f2py/tests/src/assumed_shape/foo_mod.f90 +41 -0
- numpy/f2py/tests/src/assumed_shape/foo_use.f90 +19 -0
- numpy/f2py/tests/src/assumed_shape/precision.f90 +4 -0
- numpy/f2py/tests/src/block_docstring/foo.f +6 -0
- numpy/f2py/tests/src/callback/foo.f +62 -0
- numpy/f2py/tests/src/callback/gh17797.f90 +7 -0
- numpy/f2py/tests/src/callback/gh18335.f90 +17 -0
- numpy/f2py/tests/src/callback/gh25211.f +10 -0
- numpy/f2py/tests/src/callback/gh25211.pyf +18 -0
- numpy/f2py/tests/src/callback/gh26681.f90 +18 -0
- numpy/f2py/tests/src/cli/gh_22819.pyf +6 -0
- numpy/f2py/tests/src/cli/hi77.f +3 -0
- numpy/f2py/tests/src/cli/hiworld.f90 +3 -0
- numpy/f2py/tests/src/common/block.f +11 -0
- numpy/f2py/tests/src/common/gh19161.f90 +10 -0
- numpy/f2py/tests/src/crackfortran/accesstype.f90 +13 -0
- numpy/f2py/tests/src/crackfortran/common_with_division.f +17 -0
- numpy/f2py/tests/src/crackfortran/data_common.f +8 -0
- numpy/f2py/tests/src/crackfortran/data_multiplier.f +5 -0
- numpy/f2py/tests/src/crackfortran/data_stmts.f90 +20 -0
- numpy/f2py/tests/src/crackfortran/data_with_comments.f +8 -0
- numpy/f2py/tests/src/crackfortran/foo_deps.f90 +6 -0
- numpy/f2py/tests/src/crackfortran/gh15035.f +16 -0
- numpy/f2py/tests/src/crackfortran/gh17859.f +12 -0
- numpy/f2py/tests/src/crackfortran/gh22648.pyf +7 -0
- numpy/f2py/tests/src/crackfortran/gh23533.f +5 -0
- numpy/f2py/tests/src/crackfortran/gh23598.f90 +4 -0
- numpy/f2py/tests/src/crackfortran/gh23598Warn.f90 +11 -0
- numpy/f2py/tests/src/crackfortran/gh23879.f90 +20 -0
- numpy/f2py/tests/src/crackfortran/gh27697.f90 +12 -0
- numpy/f2py/tests/src/crackfortran/gh2848.f90 +13 -0
- numpy/f2py/tests/src/crackfortran/operators.f90 +49 -0
- numpy/f2py/tests/src/crackfortran/privatemod.f90 +11 -0
- numpy/f2py/tests/src/crackfortran/publicmod.f90 +10 -0
- numpy/f2py/tests/src/crackfortran/pubprivmod.f90 +10 -0
- numpy/f2py/tests/src/crackfortran/unicode_comment.f90 +4 -0
- numpy/f2py/tests/src/f2cmap/.f2py_f2cmap +1 -0
- numpy/f2py/tests/src/f2cmap/isoFortranEnvMap.f90 +9 -0
- numpy/f2py/tests/src/isocintrin/isoCtests.f90 +34 -0
- numpy/f2py/tests/src/kind/foo.f90 +20 -0
- numpy/f2py/tests/src/mixed/foo.f +5 -0
- numpy/f2py/tests/src/mixed/foo_fixed.f90 +8 -0
- numpy/f2py/tests/src/mixed/foo_free.f90 +8 -0
- numpy/f2py/tests/src/modules/gh25337/data.f90 +8 -0
- numpy/f2py/tests/src/modules/gh25337/use_data.f90 +6 -0
- numpy/f2py/tests/src/modules/gh26920/two_mods_with_no_public_entities.f90 +21 -0
- numpy/f2py/tests/src/modules/gh26920/two_mods_with_one_public_routine.f90 +21 -0
- numpy/f2py/tests/src/modules/module_data_docstring.f90 +12 -0
- numpy/f2py/tests/src/modules/use_modules.f90 +20 -0
- numpy/f2py/tests/src/negative_bounds/issue_20853.f90 +7 -0
- numpy/f2py/tests/src/parameter/constant_array.f90 +45 -0
- numpy/f2py/tests/src/parameter/constant_both.f90 +57 -0
- numpy/f2py/tests/src/parameter/constant_compound.f90 +15 -0
- numpy/f2py/tests/src/parameter/constant_integer.f90 +22 -0
- numpy/f2py/tests/src/parameter/constant_non_compound.f90 +23 -0
- numpy/f2py/tests/src/parameter/constant_real.f90 +23 -0
- numpy/f2py/tests/src/quoted_character/foo.f +14 -0
- numpy/f2py/tests/src/regression/AB.inc +1 -0
- numpy/f2py/tests/src/regression/assignOnlyModule.f90 +25 -0
- numpy/f2py/tests/src/regression/datonly.f90 +17 -0
- numpy/f2py/tests/src/regression/f77comments.f +26 -0
- numpy/f2py/tests/src/regression/f77fixedform.f95 +5 -0
- numpy/f2py/tests/src/regression/f90continuation.f90 +9 -0
- numpy/f2py/tests/src/regression/incfile.f90 +5 -0
- numpy/f2py/tests/src/regression/inout.f90 +9 -0
- numpy/f2py/tests/src/regression/lower_f2py_fortran.f90 +5 -0
- numpy/f2py/tests/src/regression/mod_derived_types.f90 +23 -0
- numpy/f2py/tests/src/return_character/foo77.f +45 -0
- numpy/f2py/tests/src/return_character/foo90.f90 +48 -0
- numpy/f2py/tests/src/return_complex/foo77.f +45 -0
- numpy/f2py/tests/src/return_complex/foo90.f90 +48 -0
- numpy/f2py/tests/src/return_integer/foo77.f +56 -0
- numpy/f2py/tests/src/return_integer/foo90.f90 +59 -0
- numpy/f2py/tests/src/return_logical/foo77.f +56 -0
- numpy/f2py/tests/src/return_logical/foo90.f90 +59 -0
- numpy/f2py/tests/src/return_real/foo77.f +45 -0
- numpy/f2py/tests/src/return_real/foo90.f90 +48 -0
- numpy/f2py/tests/src/routines/funcfortranname.f +5 -0
- numpy/f2py/tests/src/routines/funcfortranname.pyf +11 -0
- numpy/f2py/tests/src/routines/subrout.f +4 -0
- numpy/f2py/tests/src/routines/subrout.pyf +10 -0
- numpy/f2py/tests/src/size/foo.f90 +44 -0
- numpy/f2py/tests/src/string/char.f90 +29 -0
- numpy/f2py/tests/src/string/fixed_string.f90 +34 -0
- numpy/f2py/tests/src/string/gh24008.f +8 -0
- numpy/f2py/tests/src/string/gh24662.f90 +7 -0
- numpy/f2py/tests/src/string/gh25286.f90 +14 -0
- numpy/f2py/tests/src/string/gh25286.pyf +12 -0
- numpy/f2py/tests/src/string/gh25286_bc.pyf +12 -0
- numpy/f2py/tests/src/string/scalar_string.f90 +9 -0
- numpy/f2py/tests/src/string/string.f +12 -0
- numpy/f2py/tests/src/value_attrspec/gh21665.f90 +9 -0
- numpy/f2py/tests/test_abstract_interface.py +26 -0
- numpy/f2py/tests/test_array_from_pyobj.py +678 -0
- numpy/f2py/tests/test_assumed_shape.py +50 -0
- numpy/f2py/tests/test_block_docstring.py +20 -0
- numpy/f2py/tests/test_callback.py +263 -0
- numpy/f2py/tests/test_character.py +641 -0
- numpy/f2py/tests/test_common.py +23 -0
- numpy/f2py/tests/test_crackfortran.py +421 -0
- numpy/f2py/tests/test_data.py +71 -0
- numpy/f2py/tests/test_docs.py +66 -0
- numpy/f2py/tests/test_f2cmap.py +17 -0
- numpy/f2py/tests/test_f2py2e.py +983 -0
- numpy/f2py/tests/test_isoc.py +56 -0
- numpy/f2py/tests/test_kind.py +52 -0
- numpy/f2py/tests/test_mixed.py +35 -0
- numpy/f2py/tests/test_modules.py +83 -0
- numpy/f2py/tests/test_parameter.py +129 -0
- numpy/f2py/tests/test_pyf_src.py +43 -0
- numpy/f2py/tests/test_quoted_character.py +18 -0
- numpy/f2py/tests/test_regression.py +187 -0
- numpy/f2py/tests/test_return_character.py +48 -0
- numpy/f2py/tests/test_return_complex.py +67 -0
- numpy/f2py/tests/test_return_integer.py +55 -0
- numpy/f2py/tests/test_return_logical.py +65 -0
- numpy/f2py/tests/test_return_real.py +109 -0
- numpy/f2py/tests/test_routines.py +29 -0
- numpy/f2py/tests/test_semicolon_split.py +75 -0
- numpy/f2py/tests/test_size.py +45 -0
- numpy/f2py/tests/test_string.py +100 -0
- numpy/f2py/tests/test_symbolic.py +500 -0
- numpy/f2py/tests/test_value_attrspec.py +15 -0
- numpy/f2py/tests/util.py +442 -0
- numpy/f2py/use_rules.py +99 -0
- numpy/f2py/use_rules.pyi +9 -0
- numpy/fft/__init__.py +213 -0
- numpy/fft/__init__.pyi +38 -0
- numpy/fft/_helper.py +235 -0
- numpy/fft/_helper.pyi +44 -0
- numpy/fft/_pocketfft.py +1693 -0
- numpy/fft/_pocketfft.pyi +137 -0
- numpy/fft/_pocketfft_umath.pypy311-pp73-darwin.so +0 -0
- numpy/fft/tests/__init__.py +0 -0
- numpy/fft/tests/test_helper.py +167 -0
- numpy/fft/tests/test_pocketfft.py +589 -0
- numpy/lib/__init__.py +97 -0
- numpy/lib/__init__.pyi +52 -0
- numpy/lib/_array_utils_impl.py +62 -0
- numpy/lib/_array_utils_impl.pyi +10 -0
- numpy/lib/_arraypad_impl.py +926 -0
- numpy/lib/_arraypad_impl.pyi +88 -0
- numpy/lib/_arraysetops_impl.py +1158 -0
- numpy/lib/_arraysetops_impl.pyi +462 -0
- numpy/lib/_arrayterator_impl.py +224 -0
- numpy/lib/_arrayterator_impl.pyi +45 -0
- numpy/lib/_datasource.py +700 -0
- numpy/lib/_datasource.pyi +30 -0
- numpy/lib/_format_impl.py +1036 -0
- numpy/lib/_format_impl.pyi +56 -0
- numpy/lib/_function_base_impl.py +5760 -0
- numpy/lib/_function_base_impl.pyi +2324 -0
- numpy/lib/_histograms_impl.py +1085 -0
- numpy/lib/_histograms_impl.pyi +40 -0
- numpy/lib/_index_tricks_impl.py +1048 -0
- numpy/lib/_index_tricks_impl.pyi +267 -0
- numpy/lib/_iotools.py +900 -0
- numpy/lib/_iotools.pyi +116 -0
- numpy/lib/_nanfunctions_impl.py +2006 -0
- numpy/lib/_nanfunctions_impl.pyi +48 -0
- numpy/lib/_npyio_impl.py +2583 -0
- numpy/lib/_npyio_impl.pyi +299 -0
- numpy/lib/_polynomial_impl.py +1465 -0
- numpy/lib/_polynomial_impl.pyi +338 -0
- numpy/lib/_scimath_impl.py +642 -0
- numpy/lib/_scimath_impl.pyi +93 -0
- numpy/lib/_shape_base_impl.py +1289 -0
- numpy/lib/_shape_base_impl.pyi +236 -0
- numpy/lib/_stride_tricks_impl.py +582 -0
- numpy/lib/_stride_tricks_impl.pyi +73 -0
- numpy/lib/_twodim_base_impl.py +1201 -0
- numpy/lib/_twodim_base_impl.pyi +408 -0
- numpy/lib/_type_check_impl.py +710 -0
- numpy/lib/_type_check_impl.pyi +348 -0
- numpy/lib/_ufunclike_impl.py +199 -0
- numpy/lib/_ufunclike_impl.pyi +60 -0
- numpy/lib/_user_array_impl.py +310 -0
- numpy/lib/_user_array_impl.pyi +226 -0
- numpy/lib/_utils_impl.py +784 -0
- numpy/lib/_utils_impl.pyi +22 -0
- numpy/lib/_version.py +153 -0
- numpy/lib/_version.pyi +17 -0
- numpy/lib/array_utils.py +7 -0
- numpy/lib/array_utils.pyi +6 -0
- numpy/lib/format.py +24 -0
- numpy/lib/format.pyi +24 -0
- numpy/lib/introspect.py +94 -0
- numpy/lib/introspect.pyi +3 -0
- numpy/lib/mixins.py +180 -0
- numpy/lib/mixins.pyi +78 -0
- numpy/lib/npyio.py +1 -0
- numpy/lib/npyio.pyi +5 -0
- numpy/lib/recfunctions.py +1681 -0
- numpy/lib/recfunctions.pyi +444 -0
- numpy/lib/scimath.py +13 -0
- numpy/lib/scimath.pyi +12 -0
- numpy/lib/stride_tricks.py +1 -0
- numpy/lib/stride_tricks.pyi +4 -0
- numpy/lib/tests/__init__.py +0 -0
- numpy/lib/tests/data/py2-np0-objarr.npy +0 -0
- numpy/lib/tests/data/py2-objarr.npy +0 -0
- numpy/lib/tests/data/py2-objarr.npz +0 -0
- numpy/lib/tests/data/py3-objarr.npy +0 -0
- numpy/lib/tests/data/py3-objarr.npz +0 -0
- numpy/lib/tests/data/python3.npy +0 -0
- numpy/lib/tests/data/win64python2.npy +0 -0
- numpy/lib/tests/test__datasource.py +328 -0
- numpy/lib/tests/test__iotools.py +358 -0
- numpy/lib/tests/test__version.py +64 -0
- numpy/lib/tests/test_array_utils.py +32 -0
- numpy/lib/tests/test_arraypad.py +1427 -0
- numpy/lib/tests/test_arraysetops.py +1302 -0
- numpy/lib/tests/test_arrayterator.py +45 -0
- numpy/lib/tests/test_format.py +1054 -0
- numpy/lib/tests/test_function_base.py +4750 -0
- numpy/lib/tests/test_histograms.py +855 -0
- numpy/lib/tests/test_index_tricks.py +693 -0
- numpy/lib/tests/test_io.py +2857 -0
- numpy/lib/tests/test_loadtxt.py +1099 -0
- numpy/lib/tests/test_mixins.py +215 -0
- numpy/lib/tests/test_nanfunctions.py +1438 -0
- numpy/lib/tests/test_packbits.py +376 -0
- numpy/lib/tests/test_polynomial.py +325 -0
- numpy/lib/tests/test_recfunctions.py +1042 -0
- numpy/lib/tests/test_regression.py +231 -0
- numpy/lib/tests/test_shape_base.py +813 -0
- numpy/lib/tests/test_stride_tricks.py +655 -0
- numpy/lib/tests/test_twodim_base.py +559 -0
- numpy/lib/tests/test_type_check.py +473 -0
- numpy/lib/tests/test_ufunclike.py +97 -0
- numpy/lib/tests/test_utils.py +80 -0
- numpy/lib/user_array.py +1 -0
- numpy/lib/user_array.pyi +1 -0
- numpy/linalg/__init__.py +95 -0
- numpy/linalg/__init__.pyi +71 -0
- numpy/linalg/_linalg.py +3657 -0
- numpy/linalg/_linalg.pyi +548 -0
- numpy/linalg/_umath_linalg.pyi +60 -0
- numpy/linalg/_umath_linalg.pypy311-pp73-darwin.so +0 -0
- numpy/linalg/lapack_lite.pyi +143 -0
- numpy/linalg/lapack_lite.pypy311-pp73-darwin.so +0 -0
- numpy/linalg/tests/__init__.py +0 -0
- numpy/linalg/tests/test_deprecations.py +21 -0
- numpy/linalg/tests/test_linalg.py +2442 -0
- numpy/linalg/tests/test_regression.py +182 -0
- numpy/ma/API_CHANGES.txt +135 -0
- numpy/ma/LICENSE +24 -0
- numpy/ma/README.rst +236 -0
- numpy/ma/__init__.py +53 -0
- numpy/ma/__init__.pyi +458 -0
- numpy/ma/core.py +8929 -0
- numpy/ma/core.pyi +3720 -0
- numpy/ma/extras.py +2266 -0
- numpy/ma/extras.pyi +297 -0
- numpy/ma/mrecords.py +762 -0
- numpy/ma/mrecords.pyi +96 -0
- numpy/ma/tests/__init__.py +0 -0
- numpy/ma/tests/test_arrayobject.py +40 -0
- numpy/ma/tests/test_core.py +6008 -0
- numpy/ma/tests/test_deprecations.py +65 -0
- numpy/ma/tests/test_extras.py +1945 -0
- numpy/ma/tests/test_mrecords.py +495 -0
- numpy/ma/tests/test_old_ma.py +939 -0
- numpy/ma/tests/test_regression.py +83 -0
- numpy/ma/tests/test_subclassing.py +469 -0
- numpy/ma/testutils.py +294 -0
- numpy/ma/testutils.pyi +69 -0
- numpy/matlib.py +380 -0
- numpy/matlib.pyi +580 -0
- numpy/matrixlib/__init__.py +12 -0
- numpy/matrixlib/__init__.pyi +3 -0
- numpy/matrixlib/defmatrix.py +1119 -0
- numpy/matrixlib/defmatrix.pyi +218 -0
- numpy/matrixlib/tests/__init__.py +0 -0
- numpy/matrixlib/tests/test_defmatrix.py +455 -0
- numpy/matrixlib/tests/test_interaction.py +360 -0
- numpy/matrixlib/tests/test_masked_matrix.py +240 -0
- numpy/matrixlib/tests/test_matrix_linalg.py +110 -0
- numpy/matrixlib/tests/test_multiarray.py +17 -0
- numpy/matrixlib/tests/test_numeric.py +18 -0
- numpy/matrixlib/tests/test_regression.py +31 -0
- numpy/polynomial/__init__.py +187 -0
- numpy/polynomial/__init__.pyi +31 -0
- numpy/polynomial/_polybase.py +1191 -0
- numpy/polynomial/_polybase.pyi +262 -0
- numpy/polynomial/_polytypes.pyi +501 -0
- numpy/polynomial/chebyshev.py +2001 -0
- numpy/polynomial/chebyshev.pyi +180 -0
- numpy/polynomial/hermite.py +1738 -0
- numpy/polynomial/hermite.pyi +106 -0
- numpy/polynomial/hermite_e.py +1640 -0
- numpy/polynomial/hermite_e.pyi +106 -0
- numpy/polynomial/laguerre.py +1673 -0
- numpy/polynomial/laguerre.pyi +100 -0
- numpy/polynomial/legendre.py +1603 -0
- numpy/polynomial/legendre.pyi +100 -0
- numpy/polynomial/polynomial.py +1625 -0
- numpy/polynomial/polynomial.pyi +109 -0
- numpy/polynomial/polyutils.py +759 -0
- numpy/polynomial/polyutils.pyi +307 -0
- numpy/polynomial/tests/__init__.py +0 -0
- numpy/polynomial/tests/test_chebyshev.py +618 -0
- numpy/polynomial/tests/test_classes.py +613 -0
- numpy/polynomial/tests/test_hermite.py +553 -0
- numpy/polynomial/tests/test_hermite_e.py +554 -0
- numpy/polynomial/tests/test_laguerre.py +535 -0
- numpy/polynomial/tests/test_legendre.py +566 -0
- numpy/polynomial/tests/test_polynomial.py +691 -0
- numpy/polynomial/tests/test_polyutils.py +123 -0
- numpy/polynomial/tests/test_printing.py +557 -0
- numpy/polynomial/tests/test_symbol.py +217 -0
- numpy/py.typed +0 -0
- numpy/random/LICENSE.md +71 -0
- numpy/random/__init__.pxd +14 -0
- numpy/random/__init__.py +213 -0
- numpy/random/__init__.pyi +124 -0
- numpy/random/_bounded_integers.pxd +29 -0
- numpy/random/_bounded_integers.pyi +1 -0
- numpy/random/_bounded_integers.pypy311-pp73-darwin.so +0 -0
- numpy/random/_common.pxd +110 -0
- numpy/random/_common.pyi +16 -0
- numpy/random/_common.pypy311-pp73-darwin.so +0 -0
- numpy/random/_examples/cffi/extending.py +44 -0
- numpy/random/_examples/cffi/parse.py +53 -0
- numpy/random/_examples/cython/extending.pyx +77 -0
- numpy/random/_examples/cython/extending_distributions.pyx +117 -0
- numpy/random/_examples/cython/meson.build +53 -0
- numpy/random/_examples/numba/extending.py +86 -0
- numpy/random/_examples/numba/extending_distributions.py +67 -0
- numpy/random/_generator.pyi +862 -0
- numpy/random/_generator.pypy311-pp73-darwin.so +0 -0
- numpy/random/_mt19937.pyi +27 -0
- numpy/random/_mt19937.pypy311-pp73-darwin.so +0 -0
- numpy/random/_pcg64.pyi +41 -0
- numpy/random/_pcg64.pypy311-pp73-darwin.so +0 -0
- numpy/random/_philox.pyi +36 -0
- numpy/random/_philox.pypy311-pp73-darwin.so +0 -0
- numpy/random/_pickle.py +88 -0
- numpy/random/_pickle.pyi +43 -0
- numpy/random/_sfc64.pyi +25 -0
- numpy/random/_sfc64.pypy311-pp73-darwin.so +0 -0
- numpy/random/bit_generator.pxd +40 -0
- numpy/random/bit_generator.pyi +123 -0
- numpy/random/bit_generator.pypy311-pp73-darwin.so +0 -0
- numpy/random/c_distributions.pxd +119 -0
- numpy/random/lib/libnpyrandom.a +0 -0
- numpy/random/mtrand.pyi +759 -0
- numpy/random/mtrand.pypy311-pp73-darwin.so +0 -0
- numpy/random/tests/__init__.py +0 -0
- numpy/random/tests/data/__init__.py +0 -0
- numpy/random/tests/data/generator_pcg64_np121.pkl.gz +0 -0
- numpy/random/tests/data/generator_pcg64_np126.pkl.gz +0 -0
- numpy/random/tests/data/mt19937-testset-1.csv +1001 -0
- numpy/random/tests/data/mt19937-testset-2.csv +1001 -0
- numpy/random/tests/data/pcg64-testset-1.csv +1001 -0
- numpy/random/tests/data/pcg64-testset-2.csv +1001 -0
- numpy/random/tests/data/pcg64dxsm-testset-1.csv +1001 -0
- numpy/random/tests/data/pcg64dxsm-testset-2.csv +1001 -0
- numpy/random/tests/data/philox-testset-1.csv +1001 -0
- numpy/random/tests/data/philox-testset-2.csv +1001 -0
- numpy/random/tests/data/sfc64-testset-1.csv +1001 -0
- numpy/random/tests/data/sfc64-testset-2.csv +1001 -0
- numpy/random/tests/data/sfc64_np126.pkl.gz +0 -0
- numpy/random/tests/test_direct.py +595 -0
- numpy/random/tests/test_extending.py +131 -0
- numpy/random/tests/test_generator_mt19937.py +2825 -0
- numpy/random/tests/test_generator_mt19937_regressions.py +221 -0
- numpy/random/tests/test_random.py +1724 -0
- numpy/random/tests/test_randomstate.py +2099 -0
- numpy/random/tests/test_randomstate_regression.py +213 -0
- numpy/random/tests/test_regression.py +175 -0
- numpy/random/tests/test_seed_sequence.py +79 -0
- numpy/random/tests/test_smoke.py +882 -0
- numpy/rec/__init__.py +2 -0
- numpy/rec/__init__.pyi +23 -0
- numpy/strings/__init__.py +2 -0
- numpy/strings/__init__.pyi +97 -0
- numpy/testing/__init__.py +22 -0
- numpy/testing/__init__.pyi +107 -0
- numpy/testing/_private/__init__.py +0 -0
- numpy/testing/_private/__init__.pyi +0 -0
- numpy/testing/_private/extbuild.py +250 -0
- numpy/testing/_private/extbuild.pyi +25 -0
- numpy/testing/_private/utils.py +2830 -0
- numpy/testing/_private/utils.pyi +505 -0
- numpy/testing/overrides.py +84 -0
- numpy/testing/overrides.pyi +10 -0
- numpy/testing/print_coercion_tables.py +207 -0
- numpy/testing/print_coercion_tables.pyi +26 -0
- numpy/testing/tests/__init__.py +0 -0
- numpy/testing/tests/test_utils.py +2123 -0
- numpy/tests/__init__.py +0 -0
- numpy/tests/test__all__.py +10 -0
- numpy/tests/test_configtool.py +51 -0
- numpy/tests/test_ctypeslib.py +383 -0
- numpy/tests/test_lazyloading.py +42 -0
- numpy/tests/test_matlib.py +59 -0
- numpy/tests/test_numpy_config.py +47 -0
- numpy/tests/test_numpy_version.py +54 -0
- numpy/tests/test_public_api.py +807 -0
- numpy/tests/test_reloading.py +76 -0
- numpy/tests/test_scripts.py +48 -0
- numpy/tests/test_warnings.py +79 -0
- numpy/typing/__init__.py +233 -0
- numpy/typing/__init__.pyi +3 -0
- numpy/typing/mypy_plugin.py +200 -0
- numpy/typing/tests/__init__.py +0 -0
- numpy/typing/tests/data/fail/arithmetic.pyi +126 -0
- numpy/typing/tests/data/fail/array_constructors.pyi +34 -0
- numpy/typing/tests/data/fail/array_like.pyi +15 -0
- numpy/typing/tests/data/fail/array_pad.pyi +6 -0
- numpy/typing/tests/data/fail/arrayprint.pyi +15 -0
- numpy/typing/tests/data/fail/arrayterator.pyi +14 -0
- numpy/typing/tests/data/fail/bitwise_ops.pyi +17 -0
- numpy/typing/tests/data/fail/char.pyi +63 -0
- numpy/typing/tests/data/fail/chararray.pyi +61 -0
- numpy/typing/tests/data/fail/comparisons.pyi +27 -0
- numpy/typing/tests/data/fail/constants.pyi +3 -0
- numpy/typing/tests/data/fail/datasource.pyi +16 -0
- numpy/typing/tests/data/fail/dtype.pyi +17 -0
- numpy/typing/tests/data/fail/einsumfunc.pyi +12 -0
- numpy/typing/tests/data/fail/flatiter.pyi +38 -0
- numpy/typing/tests/data/fail/fromnumeric.pyi +148 -0
- numpy/typing/tests/data/fail/histograms.pyi +12 -0
- numpy/typing/tests/data/fail/index_tricks.pyi +14 -0
- numpy/typing/tests/data/fail/lib_function_base.pyi +60 -0
- numpy/typing/tests/data/fail/lib_polynomial.pyi +29 -0
- numpy/typing/tests/data/fail/lib_utils.pyi +3 -0
- numpy/typing/tests/data/fail/lib_version.pyi +6 -0
- numpy/typing/tests/data/fail/linalg.pyi +52 -0
- numpy/typing/tests/data/fail/ma.pyi +155 -0
- numpy/typing/tests/data/fail/memmap.pyi +5 -0
- numpy/typing/tests/data/fail/modules.pyi +17 -0
- numpy/typing/tests/data/fail/multiarray.pyi +52 -0
- numpy/typing/tests/data/fail/ndarray.pyi +11 -0
- numpy/typing/tests/data/fail/ndarray_misc.pyi +49 -0
- numpy/typing/tests/data/fail/nditer.pyi +8 -0
- numpy/typing/tests/data/fail/nested_sequence.pyi +17 -0
- numpy/typing/tests/data/fail/npyio.pyi +24 -0
- numpy/typing/tests/data/fail/numerictypes.pyi +5 -0
- numpy/typing/tests/data/fail/random.pyi +62 -0
- numpy/typing/tests/data/fail/rec.pyi +17 -0
- numpy/typing/tests/data/fail/scalars.pyi +86 -0
- numpy/typing/tests/data/fail/shape.pyi +7 -0
- numpy/typing/tests/data/fail/shape_base.pyi +8 -0
- numpy/typing/tests/data/fail/stride_tricks.pyi +9 -0
- numpy/typing/tests/data/fail/strings.pyi +52 -0
- numpy/typing/tests/data/fail/testing.pyi +28 -0
- numpy/typing/tests/data/fail/twodim_base.pyi +39 -0
- numpy/typing/tests/data/fail/type_check.pyi +12 -0
- numpy/typing/tests/data/fail/ufunc_config.pyi +21 -0
- numpy/typing/tests/data/fail/ufunclike.pyi +21 -0
- numpy/typing/tests/data/fail/ufuncs.pyi +17 -0
- numpy/typing/tests/data/fail/warnings_and_errors.pyi +5 -0
- numpy/typing/tests/data/misc/extended_precision.pyi +9 -0
- numpy/typing/tests/data/mypy.ini +8 -0
- numpy/typing/tests/data/pass/arithmetic.py +614 -0
- numpy/typing/tests/data/pass/array_constructors.py +138 -0
- numpy/typing/tests/data/pass/array_like.py +43 -0
- numpy/typing/tests/data/pass/arrayprint.py +37 -0
- numpy/typing/tests/data/pass/arrayterator.py +28 -0
- numpy/typing/tests/data/pass/bitwise_ops.py +131 -0
- numpy/typing/tests/data/pass/comparisons.py +316 -0
- numpy/typing/tests/data/pass/dtype.py +57 -0
- numpy/typing/tests/data/pass/einsumfunc.py +36 -0
- numpy/typing/tests/data/pass/flatiter.py +26 -0
- numpy/typing/tests/data/pass/fromnumeric.py +272 -0
- numpy/typing/tests/data/pass/index_tricks.py +62 -0
- numpy/typing/tests/data/pass/lib_user_array.py +22 -0
- numpy/typing/tests/data/pass/lib_utils.py +19 -0
- numpy/typing/tests/data/pass/lib_version.py +18 -0
- numpy/typing/tests/data/pass/literal.py +52 -0
- numpy/typing/tests/data/pass/ma.py +199 -0
- numpy/typing/tests/data/pass/mod.py +149 -0
- numpy/typing/tests/data/pass/modules.py +45 -0
- numpy/typing/tests/data/pass/multiarray.py +77 -0
- numpy/typing/tests/data/pass/ndarray_conversion.py +81 -0
- numpy/typing/tests/data/pass/ndarray_misc.py +199 -0
- numpy/typing/tests/data/pass/ndarray_shape_manipulation.py +47 -0
- numpy/typing/tests/data/pass/nditer.py +4 -0
- numpy/typing/tests/data/pass/numeric.py +90 -0
- numpy/typing/tests/data/pass/numerictypes.py +17 -0
- numpy/typing/tests/data/pass/random.py +1498 -0
- numpy/typing/tests/data/pass/recfunctions.py +164 -0
- numpy/typing/tests/data/pass/scalars.py +249 -0
- numpy/typing/tests/data/pass/shape.py +19 -0
- numpy/typing/tests/data/pass/simple.py +170 -0
- numpy/typing/tests/data/pass/ufunc_config.py +64 -0
- numpy/typing/tests/data/pass/ufunclike.py +52 -0
- numpy/typing/tests/data/pass/ufuncs.py +16 -0
- numpy/typing/tests/data/pass/warnings_and_errors.py +6 -0
- numpy/typing/tests/data/reveal/arithmetic.pyi +719 -0
- numpy/typing/tests/data/reveal/array_api_info.pyi +70 -0
- numpy/typing/tests/data/reveal/array_constructors.pyi +277 -0
- numpy/typing/tests/data/reveal/arraypad.pyi +27 -0
- numpy/typing/tests/data/reveal/arrayprint.pyi +25 -0
- numpy/typing/tests/data/reveal/arraysetops.pyi +74 -0
- numpy/typing/tests/data/reveal/arrayterator.pyi +27 -0
- numpy/typing/tests/data/reveal/bitwise_ops.pyi +166 -0
- numpy/typing/tests/data/reveal/char.pyi +225 -0
- numpy/typing/tests/data/reveal/chararray.pyi +138 -0
- numpy/typing/tests/data/reveal/comparisons.pyi +264 -0
- numpy/typing/tests/data/reveal/constants.pyi +14 -0
- numpy/typing/tests/data/reveal/ctypeslib.pyi +81 -0
- numpy/typing/tests/data/reveal/datasource.pyi +23 -0
- numpy/typing/tests/data/reveal/dtype.pyi +132 -0
- numpy/typing/tests/data/reveal/einsumfunc.pyi +39 -0
- numpy/typing/tests/data/reveal/emath.pyi +54 -0
- numpy/typing/tests/data/reveal/fft.pyi +37 -0
- numpy/typing/tests/data/reveal/flatiter.pyi +86 -0
- numpy/typing/tests/data/reveal/fromnumeric.pyi +347 -0
- numpy/typing/tests/data/reveal/getlimits.pyi +53 -0
- numpy/typing/tests/data/reveal/histograms.pyi +25 -0
- numpy/typing/tests/data/reveal/index_tricks.pyi +70 -0
- numpy/typing/tests/data/reveal/lib_function_base.pyi +409 -0
- numpy/typing/tests/data/reveal/lib_polynomial.pyi +147 -0
- numpy/typing/tests/data/reveal/lib_utils.pyi +17 -0
- numpy/typing/tests/data/reveal/lib_version.pyi +20 -0
- numpy/typing/tests/data/reveal/linalg.pyi +154 -0
- numpy/typing/tests/data/reveal/ma.pyi +1098 -0
- numpy/typing/tests/data/reveal/matrix.pyi +73 -0
- numpy/typing/tests/data/reveal/memmap.pyi +19 -0
- numpy/typing/tests/data/reveal/mod.pyi +178 -0
- numpy/typing/tests/data/reveal/modules.pyi +51 -0
- numpy/typing/tests/data/reveal/multiarray.pyi +197 -0
- numpy/typing/tests/data/reveal/nbit_base_example.pyi +20 -0
- numpy/typing/tests/data/reveal/ndarray_assignability.pyi +82 -0
- numpy/typing/tests/data/reveal/ndarray_conversion.pyi +83 -0
- numpy/typing/tests/data/reveal/ndarray_misc.pyi +246 -0
- numpy/typing/tests/data/reveal/ndarray_shape_manipulation.pyi +47 -0
- numpy/typing/tests/data/reveal/nditer.pyi +49 -0
- numpy/typing/tests/data/reveal/nested_sequence.pyi +25 -0
- numpy/typing/tests/data/reveal/npyio.pyi +83 -0
- numpy/typing/tests/data/reveal/numeric.pyi +170 -0
- numpy/typing/tests/data/reveal/numerictypes.pyi +16 -0
- numpy/typing/tests/data/reveal/polynomial_polybase.pyi +217 -0
- numpy/typing/tests/data/reveal/polynomial_polyutils.pyi +218 -0
- numpy/typing/tests/data/reveal/polynomial_series.pyi +138 -0
- numpy/typing/tests/data/reveal/random.pyi +1546 -0
- numpy/typing/tests/data/reveal/rec.pyi +171 -0
- numpy/typing/tests/data/reveal/scalars.pyi +191 -0
- numpy/typing/tests/data/reveal/shape.pyi +13 -0
- numpy/typing/tests/data/reveal/shape_base.pyi +52 -0
- numpy/typing/tests/data/reveal/stride_tricks.pyi +27 -0
- numpy/typing/tests/data/reveal/strings.pyi +196 -0
- numpy/typing/tests/data/reveal/testing.pyi +198 -0
- numpy/typing/tests/data/reveal/twodim_base.pyi +225 -0
- numpy/typing/tests/data/reveal/type_check.pyi +67 -0
- numpy/typing/tests/data/reveal/ufunc_config.pyi +29 -0
- numpy/typing/tests/data/reveal/ufunclike.pyi +31 -0
- numpy/typing/tests/data/reveal/ufuncs.pyi +142 -0
- numpy/typing/tests/data/reveal/warnings_and_errors.pyi +11 -0
- numpy/typing/tests/test_isfile.py +38 -0
- numpy/typing/tests/test_runtime.py +110 -0
- numpy/typing/tests/test_typing.py +205 -0
- numpy/version.py +11 -0
- numpy/version.pyi +9 -0
- numpy-2.4.1.dist-info/METADATA +139 -0
- numpy-2.4.1.dist-info/RECORD +1039 -0
- numpy-2.4.1.dist-info/WHEEL +6 -0
- numpy-2.4.1.dist-info/entry_points.txt +13 -0
- numpy-2.4.1.dist-info/licenses/LICENSE.txt +935 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/include/numpy/libdivide/LICENSE.txt +21 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/common/pythoncapi-compat/COPYING +14 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/highway/LICENSE +371 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/multiarray/dragon4_LICENSE.txt +27 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/npysort/x86-simd-sort/LICENSE.md +28 -0
- numpy-2.4.1.dist-info/licenses/numpy/_core/src/umath/svml/LICENSE +30 -0
- numpy-2.4.1.dist-info/licenses/numpy/fft/pocketfft/LICENSE.md +25 -0
- numpy-2.4.1.dist-info/licenses/numpy/linalg/lapack_lite/LICENSE.txt +48 -0
- numpy-2.4.1.dist-info/licenses/numpy/ma/LICENSE +24 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/LICENSE.md +71 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/distributions/LICENSE.md +61 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/mt19937/LICENSE.md +61 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/pcg64/LICENSE.md +22 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/philox/LICENSE.md +31 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/sfc64/LICENSE.md +27 -0
- numpy-2.4.1.dist-info/licenses/numpy/random/src/splitmix64/LICENSE.md +9 -0
numpy/_core/strings.py
ADDED
|
@@ -0,0 +1,1813 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module contains a set of functions for vectorized string
|
|
3
|
+
operations.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import functools
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
from numpy import (
|
|
11
|
+
add,
|
|
12
|
+
equal,
|
|
13
|
+
greater,
|
|
14
|
+
greater_equal,
|
|
15
|
+
less,
|
|
16
|
+
less_equal,
|
|
17
|
+
multiply as _multiply_ufunc,
|
|
18
|
+
not_equal,
|
|
19
|
+
)
|
|
20
|
+
from numpy._core.multiarray import _vec_string
|
|
21
|
+
from numpy._core.overrides import array_function_dispatch, set_module
|
|
22
|
+
from numpy._core.umath import (
|
|
23
|
+
_center,
|
|
24
|
+
_expandtabs,
|
|
25
|
+
_expandtabs_length,
|
|
26
|
+
_ljust,
|
|
27
|
+
_lstrip_chars,
|
|
28
|
+
_lstrip_whitespace,
|
|
29
|
+
_partition,
|
|
30
|
+
_partition_index,
|
|
31
|
+
_replace,
|
|
32
|
+
_rjust,
|
|
33
|
+
_rpartition,
|
|
34
|
+
_rpartition_index,
|
|
35
|
+
_rstrip_chars,
|
|
36
|
+
_rstrip_whitespace,
|
|
37
|
+
_slice,
|
|
38
|
+
_strip_chars,
|
|
39
|
+
_strip_whitespace,
|
|
40
|
+
_zfill,
|
|
41
|
+
count as _count_ufunc,
|
|
42
|
+
endswith as _endswith_ufunc,
|
|
43
|
+
find as _find_ufunc,
|
|
44
|
+
index as _index_ufunc,
|
|
45
|
+
isalnum,
|
|
46
|
+
isalpha,
|
|
47
|
+
isdecimal,
|
|
48
|
+
isdigit,
|
|
49
|
+
islower,
|
|
50
|
+
isnumeric,
|
|
51
|
+
isspace,
|
|
52
|
+
istitle,
|
|
53
|
+
isupper,
|
|
54
|
+
rfind as _rfind_ufunc,
|
|
55
|
+
rindex as _rindex_ufunc,
|
|
56
|
+
startswith as _startswith_ufunc,
|
|
57
|
+
str_len,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _override___module__():
|
|
62
|
+
for ufunc in [
|
|
63
|
+
isalnum, isalpha, isdecimal, isdigit, islower, isnumeric, isspace,
|
|
64
|
+
istitle, isupper, str_len,
|
|
65
|
+
]:
|
|
66
|
+
ufunc.__module__ = "numpy.strings"
|
|
67
|
+
ufunc.__qualname__ = ufunc.__name__
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
_override___module__()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
__all__ = [
|
|
74
|
+
# UFuncs
|
|
75
|
+
"equal", "not_equal", "less", "less_equal", "greater", "greater_equal",
|
|
76
|
+
"add", "multiply", "isalpha", "isdigit", "isspace", "isalnum", "islower",
|
|
77
|
+
"isupper", "istitle", "isdecimal", "isnumeric", "str_len", "find",
|
|
78
|
+
"rfind", "index", "rindex", "count", "startswith", "endswith", "lstrip",
|
|
79
|
+
"rstrip", "strip", "replace", "expandtabs", "center", "ljust", "rjust",
|
|
80
|
+
"zfill", "partition", "rpartition", "slice",
|
|
81
|
+
|
|
82
|
+
# _vec_string - Will gradually become ufuncs as well
|
|
83
|
+
"upper", "lower", "swapcase", "capitalize", "title",
|
|
84
|
+
|
|
85
|
+
# _vec_string - Will probably not become ufuncs
|
|
86
|
+
"mod", "decode", "encode", "translate",
|
|
87
|
+
|
|
88
|
+
# Removed from namespace until behavior has been crystallized
|
|
89
|
+
# "join", "split", "rsplit", "splitlines",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
MAX = np.iinfo(np.int64).max
|
|
94
|
+
|
|
95
|
+
array_function_dispatch = functools.partial(
|
|
96
|
+
array_function_dispatch, module='numpy.strings')
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _get_num_chars(a):
|
|
100
|
+
"""
|
|
101
|
+
Helper function that returns the number of characters per field in
|
|
102
|
+
a string or unicode array. This is to abstract out the fact that
|
|
103
|
+
for a unicode array this is itemsize / 4.
|
|
104
|
+
"""
|
|
105
|
+
if issubclass(a.dtype.type, np.str_):
|
|
106
|
+
return a.itemsize // 4
|
|
107
|
+
return a.itemsize
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _to_bytes_or_str_array(result, output_dtype_like):
|
|
111
|
+
"""
|
|
112
|
+
Helper function to cast a result back into an array
|
|
113
|
+
with the appropriate dtype if an object array must be used
|
|
114
|
+
as an intermediary.
|
|
115
|
+
"""
|
|
116
|
+
output_dtype_like = np.asarray(output_dtype_like)
|
|
117
|
+
if result.size == 0:
|
|
118
|
+
# Calling asarray & tolist in an empty array would result
|
|
119
|
+
# in losing shape information
|
|
120
|
+
return result.astype(output_dtype_like.dtype)
|
|
121
|
+
ret = np.asarray(result.tolist())
|
|
122
|
+
if isinstance(output_dtype_like.dtype, np.dtypes.StringDType):
|
|
123
|
+
return ret.astype(type(output_dtype_like.dtype))
|
|
124
|
+
return ret.astype(type(output_dtype_like.dtype)(_get_num_chars(ret)))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _clean_args(*args):
|
|
128
|
+
"""
|
|
129
|
+
Helper function for delegating arguments to Python string
|
|
130
|
+
functions.
|
|
131
|
+
|
|
132
|
+
Many of the Python string operations that have optional arguments
|
|
133
|
+
do not use 'None' to indicate a default value. In these cases,
|
|
134
|
+
we need to remove all None arguments, and those following them.
|
|
135
|
+
"""
|
|
136
|
+
newargs = []
|
|
137
|
+
for chk in args:
|
|
138
|
+
if chk is None:
|
|
139
|
+
break
|
|
140
|
+
newargs.append(chk)
|
|
141
|
+
return newargs
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _multiply_dispatcher(a, i):
|
|
145
|
+
return (a,)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@set_module("numpy.strings")
|
|
149
|
+
@array_function_dispatch(_multiply_dispatcher)
|
|
150
|
+
def multiply(a, i):
|
|
151
|
+
"""
|
|
152
|
+
Return (a * i), that is string multiple concatenation,
|
|
153
|
+
element-wise.
|
|
154
|
+
|
|
155
|
+
Values in ``i`` of less than 0 are treated as 0 (which yields an
|
|
156
|
+
empty string).
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
a : array_like, with ``StringDType``, ``bytes_`` or ``str_`` dtype
|
|
161
|
+
|
|
162
|
+
i : array_like, with any integer dtype
|
|
163
|
+
|
|
164
|
+
Returns
|
|
165
|
+
-------
|
|
166
|
+
out : ndarray
|
|
167
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
168
|
+
depending on input types
|
|
169
|
+
|
|
170
|
+
Examples
|
|
171
|
+
--------
|
|
172
|
+
>>> import numpy as np
|
|
173
|
+
>>> a = np.array(["a", "b", "c"])
|
|
174
|
+
>>> np.strings.multiply(a, 3)
|
|
175
|
+
array(['aaa', 'bbb', 'ccc'], dtype='<U3')
|
|
176
|
+
>>> i = np.array([1, 2, 3])
|
|
177
|
+
>>> np.strings.multiply(a, i)
|
|
178
|
+
array(['a', 'bb', 'ccc'], dtype='<U3')
|
|
179
|
+
>>> np.strings.multiply(np.array(['a']), i)
|
|
180
|
+
array(['a', 'aa', 'aaa'], dtype='<U3')
|
|
181
|
+
>>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3))
|
|
182
|
+
>>> np.strings.multiply(a, 3)
|
|
183
|
+
array([['aaa', 'bbb', 'ccc'],
|
|
184
|
+
['ddd', 'eee', 'fff']], dtype='<U3')
|
|
185
|
+
>>> np.strings.multiply(a, i)
|
|
186
|
+
array([['a', 'bb', 'ccc'],
|
|
187
|
+
['d', 'ee', 'fff']], dtype='<U3')
|
|
188
|
+
|
|
189
|
+
"""
|
|
190
|
+
a = np.asanyarray(a)
|
|
191
|
+
|
|
192
|
+
i = np.asanyarray(i)
|
|
193
|
+
if not np.issubdtype(i.dtype, np.integer):
|
|
194
|
+
raise TypeError(f"unsupported type {i.dtype} for operand 'i'")
|
|
195
|
+
i = np.maximum(i, 0)
|
|
196
|
+
|
|
197
|
+
# delegate to stringdtype loops that also do overflow checking
|
|
198
|
+
if a.dtype.char == "T":
|
|
199
|
+
return a * i
|
|
200
|
+
|
|
201
|
+
a_len = str_len(a)
|
|
202
|
+
|
|
203
|
+
# Ensure we can do a_len * i without overflow.
|
|
204
|
+
if np.any(a_len > sys.maxsize / np.maximum(i, 1)):
|
|
205
|
+
raise OverflowError("Overflow encountered in string multiply")
|
|
206
|
+
|
|
207
|
+
buffersizes = a_len * i
|
|
208
|
+
out_dtype = f"{a.dtype.char}{buffersizes.max()}"
|
|
209
|
+
out = np.empty_like(a, shape=buffersizes.shape, dtype=out_dtype)
|
|
210
|
+
return _multiply_ufunc(a, i, out=out)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _mod_dispatcher(a, values):
|
|
214
|
+
return (a, values)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@set_module("numpy.strings")
|
|
218
|
+
@array_function_dispatch(_mod_dispatcher)
|
|
219
|
+
def mod(a, values):
|
|
220
|
+
"""
|
|
221
|
+
Return (a % i), that is pre-Python 2.6 string formatting
|
|
222
|
+
(interpolation), element-wise for a pair of array_likes of str
|
|
223
|
+
or unicode.
|
|
224
|
+
|
|
225
|
+
Parameters
|
|
226
|
+
----------
|
|
227
|
+
a : array_like, with `np.bytes_` or `np.str_` dtype
|
|
228
|
+
|
|
229
|
+
values : array_like of values
|
|
230
|
+
These values will be element-wise interpolated into the string.
|
|
231
|
+
|
|
232
|
+
Returns
|
|
233
|
+
-------
|
|
234
|
+
out : ndarray
|
|
235
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
236
|
+
depending on input types
|
|
237
|
+
|
|
238
|
+
Examples
|
|
239
|
+
--------
|
|
240
|
+
>>> import numpy as np
|
|
241
|
+
>>> a = np.array(["NumPy is a %s library"])
|
|
242
|
+
>>> np.strings.mod(a, values=["Python"])
|
|
243
|
+
array(['NumPy is a Python library'], dtype='<U25')
|
|
244
|
+
|
|
245
|
+
>>> a = np.array([b'%d bytes', b'%d bits'])
|
|
246
|
+
>>> values = np.array([8, 64])
|
|
247
|
+
>>> np.strings.mod(a, values)
|
|
248
|
+
array([b'8 bytes', b'64 bits'], dtype='|S7')
|
|
249
|
+
|
|
250
|
+
"""
|
|
251
|
+
return _to_bytes_or_str_array(
|
|
252
|
+
_vec_string(a, np.object_, '__mod__', (values,)), a)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@set_module("numpy.strings")
|
|
256
|
+
def find(a, sub, start=0, end=None):
|
|
257
|
+
"""
|
|
258
|
+
For each element, return the lowest index in the string where
|
|
259
|
+
substring ``sub`` is found, such that ``sub`` is contained in the
|
|
260
|
+
range [``start``, ``end``).
|
|
261
|
+
|
|
262
|
+
Parameters
|
|
263
|
+
----------
|
|
264
|
+
a : array_like, with ``StringDType``, ``bytes_`` or ``str_`` dtype
|
|
265
|
+
|
|
266
|
+
sub : array_like, with `np.bytes_` or `np.str_` dtype
|
|
267
|
+
The substring to search for.
|
|
268
|
+
|
|
269
|
+
start, end : array_like, with any integer dtype
|
|
270
|
+
The range to look in, interpreted as in slice notation.
|
|
271
|
+
|
|
272
|
+
Returns
|
|
273
|
+
-------
|
|
274
|
+
y : ndarray
|
|
275
|
+
Output array of ints
|
|
276
|
+
|
|
277
|
+
See Also
|
|
278
|
+
--------
|
|
279
|
+
str.find
|
|
280
|
+
|
|
281
|
+
Examples
|
|
282
|
+
--------
|
|
283
|
+
>>> import numpy as np
|
|
284
|
+
>>> a = np.array(["NumPy is a Python library"])
|
|
285
|
+
>>> np.strings.find(a, "Python")
|
|
286
|
+
array([11])
|
|
287
|
+
|
|
288
|
+
"""
|
|
289
|
+
end = end if end is not None else MAX
|
|
290
|
+
return _find_ufunc(a, sub, start, end)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@set_module("numpy.strings")
|
|
294
|
+
def rfind(a, sub, start=0, end=None):
|
|
295
|
+
"""
|
|
296
|
+
For each element, return the highest index in the string where
|
|
297
|
+
substring ``sub`` is found, such that ``sub`` is contained in the
|
|
298
|
+
range [``start``, ``end``).
|
|
299
|
+
|
|
300
|
+
Parameters
|
|
301
|
+
----------
|
|
302
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
303
|
+
|
|
304
|
+
sub : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
305
|
+
The substring to search for.
|
|
306
|
+
|
|
307
|
+
start, end : array_like, with any integer dtype
|
|
308
|
+
The range to look in, interpreted as in slice notation.
|
|
309
|
+
|
|
310
|
+
Returns
|
|
311
|
+
-------
|
|
312
|
+
y : ndarray
|
|
313
|
+
Output array of ints
|
|
314
|
+
|
|
315
|
+
See Also
|
|
316
|
+
--------
|
|
317
|
+
str.rfind
|
|
318
|
+
|
|
319
|
+
Examples
|
|
320
|
+
--------
|
|
321
|
+
>>> import numpy as np
|
|
322
|
+
>>> a = np.array(["Computer Science"])
|
|
323
|
+
>>> np.strings.rfind(a, "Science", start=0, end=None)
|
|
324
|
+
array([9])
|
|
325
|
+
>>> np.strings.rfind(a, "Science", start=0, end=8)
|
|
326
|
+
array([-1])
|
|
327
|
+
>>> b = np.array(["Computer Science", "Science"])
|
|
328
|
+
>>> np.strings.rfind(b, "Science", start=0, end=None)
|
|
329
|
+
array([9, 0])
|
|
330
|
+
|
|
331
|
+
"""
|
|
332
|
+
end = end if end is not None else MAX
|
|
333
|
+
return _rfind_ufunc(a, sub, start, end)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
@set_module("numpy.strings")
|
|
337
|
+
def index(a, sub, start=0, end=None):
|
|
338
|
+
"""
|
|
339
|
+
Like `find`, but raises :exc:`ValueError` when the substring is not found.
|
|
340
|
+
|
|
341
|
+
Parameters
|
|
342
|
+
----------
|
|
343
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
344
|
+
|
|
345
|
+
sub : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
346
|
+
|
|
347
|
+
start, end : array_like, with any integer dtype, optional
|
|
348
|
+
|
|
349
|
+
Returns
|
|
350
|
+
-------
|
|
351
|
+
out : ndarray
|
|
352
|
+
Output array of ints.
|
|
353
|
+
|
|
354
|
+
See Also
|
|
355
|
+
--------
|
|
356
|
+
find, str.index
|
|
357
|
+
|
|
358
|
+
Examples
|
|
359
|
+
--------
|
|
360
|
+
>>> import numpy as np
|
|
361
|
+
>>> a = np.array(["Computer Science"])
|
|
362
|
+
>>> np.strings.index(a, "Science", start=0, end=None)
|
|
363
|
+
array([9])
|
|
364
|
+
|
|
365
|
+
"""
|
|
366
|
+
end = end if end is not None else MAX
|
|
367
|
+
return _index_ufunc(a, sub, start, end)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
@set_module("numpy.strings")
|
|
371
|
+
def rindex(a, sub, start=0, end=None):
|
|
372
|
+
"""
|
|
373
|
+
Like `rfind`, but raises :exc:`ValueError` when the substring `sub` is
|
|
374
|
+
not found.
|
|
375
|
+
|
|
376
|
+
Parameters
|
|
377
|
+
----------
|
|
378
|
+
a : array-like, with `np.bytes_` or `np.str_` dtype
|
|
379
|
+
|
|
380
|
+
sub : array-like, with `np.bytes_` or `np.str_` dtype
|
|
381
|
+
|
|
382
|
+
start, end : array-like, with any integer dtype, optional
|
|
383
|
+
|
|
384
|
+
Returns
|
|
385
|
+
-------
|
|
386
|
+
out : ndarray
|
|
387
|
+
Output array of ints.
|
|
388
|
+
|
|
389
|
+
See Also
|
|
390
|
+
--------
|
|
391
|
+
rfind, str.rindex
|
|
392
|
+
|
|
393
|
+
Examples
|
|
394
|
+
--------
|
|
395
|
+
>>> a = np.array(["Computer Science"])
|
|
396
|
+
>>> np.strings.rindex(a, "Science", start=0, end=None)
|
|
397
|
+
array([9])
|
|
398
|
+
|
|
399
|
+
"""
|
|
400
|
+
end = end if end is not None else MAX
|
|
401
|
+
return _rindex_ufunc(a, sub, start, end)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@set_module("numpy.strings")
|
|
405
|
+
def count(a, sub, start=0, end=None):
|
|
406
|
+
"""
|
|
407
|
+
Returns an array with the number of non-overlapping occurrences of
|
|
408
|
+
substring ``sub`` in the range [``start``, ``end``).
|
|
409
|
+
|
|
410
|
+
Parameters
|
|
411
|
+
----------
|
|
412
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
413
|
+
|
|
414
|
+
sub : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
415
|
+
The substring to search for.
|
|
416
|
+
|
|
417
|
+
start, end : array_like, with any integer dtype
|
|
418
|
+
The range to look in, interpreted as in slice notation.
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
y : ndarray
|
|
423
|
+
Output array of ints
|
|
424
|
+
|
|
425
|
+
See Also
|
|
426
|
+
--------
|
|
427
|
+
str.count
|
|
428
|
+
|
|
429
|
+
Examples
|
|
430
|
+
--------
|
|
431
|
+
>>> import numpy as np
|
|
432
|
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
433
|
+
>>> c
|
|
434
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
435
|
+
>>> np.strings.count(c, 'A')
|
|
436
|
+
array([3, 1, 1])
|
|
437
|
+
>>> np.strings.count(c, 'aA')
|
|
438
|
+
array([3, 1, 0])
|
|
439
|
+
>>> np.strings.count(c, 'A', start=1, end=4)
|
|
440
|
+
array([2, 1, 1])
|
|
441
|
+
>>> np.strings.count(c, 'A', start=1, end=3)
|
|
442
|
+
array([1, 0, 0])
|
|
443
|
+
|
|
444
|
+
"""
|
|
445
|
+
end = end if end is not None else MAX
|
|
446
|
+
return _count_ufunc(a, sub, start, end)
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
@set_module("numpy.strings")
|
|
450
|
+
def startswith(a, prefix, start=0, end=None):
|
|
451
|
+
"""
|
|
452
|
+
Returns a boolean array which is `True` where the string element
|
|
453
|
+
in ``a`` starts with ``prefix``, otherwise `False`.
|
|
454
|
+
|
|
455
|
+
Parameters
|
|
456
|
+
----------
|
|
457
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
458
|
+
|
|
459
|
+
prefix : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
460
|
+
|
|
461
|
+
start, end : array_like, with any integer dtype
|
|
462
|
+
With ``start``, test beginning at that position. With ``end``,
|
|
463
|
+
stop comparing at that position.
|
|
464
|
+
|
|
465
|
+
Returns
|
|
466
|
+
-------
|
|
467
|
+
out : ndarray
|
|
468
|
+
Output array of bools
|
|
469
|
+
|
|
470
|
+
See Also
|
|
471
|
+
--------
|
|
472
|
+
str.startswith
|
|
473
|
+
|
|
474
|
+
Examples
|
|
475
|
+
--------
|
|
476
|
+
>>> import numpy as np
|
|
477
|
+
>>> s = np.array(['foo', 'bar'])
|
|
478
|
+
>>> s
|
|
479
|
+
array(['foo', 'bar'], dtype='<U3')
|
|
480
|
+
>>> np.strings.startswith(s, 'fo')
|
|
481
|
+
array([True, False])
|
|
482
|
+
>>> np.strings.startswith(s, 'o', start=1, end=2)
|
|
483
|
+
array([True, False])
|
|
484
|
+
|
|
485
|
+
"""
|
|
486
|
+
end = end if end is not None else MAX
|
|
487
|
+
return _startswith_ufunc(a, prefix, start, end)
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
@set_module("numpy.strings")
|
|
491
|
+
def endswith(a, suffix, start=0, end=None):
|
|
492
|
+
"""
|
|
493
|
+
Returns a boolean array which is `True` where the string element
|
|
494
|
+
in ``a`` ends with ``suffix``, otherwise `False`.
|
|
495
|
+
|
|
496
|
+
Parameters
|
|
497
|
+
----------
|
|
498
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
499
|
+
|
|
500
|
+
suffix : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
501
|
+
|
|
502
|
+
start, end : array_like, with any integer dtype
|
|
503
|
+
With ``start``, test beginning at that position. With ``end``,
|
|
504
|
+
stop comparing at that position.
|
|
505
|
+
|
|
506
|
+
Returns
|
|
507
|
+
-------
|
|
508
|
+
out : ndarray
|
|
509
|
+
Output array of bools
|
|
510
|
+
|
|
511
|
+
See Also
|
|
512
|
+
--------
|
|
513
|
+
str.endswith
|
|
514
|
+
|
|
515
|
+
Examples
|
|
516
|
+
--------
|
|
517
|
+
>>> import numpy as np
|
|
518
|
+
>>> s = np.array(['foo', 'bar'])
|
|
519
|
+
>>> s
|
|
520
|
+
array(['foo', 'bar'], dtype='<U3')
|
|
521
|
+
>>> np.strings.endswith(s, 'ar')
|
|
522
|
+
array([False, True])
|
|
523
|
+
>>> np.strings.endswith(s, 'a', start=1, end=2)
|
|
524
|
+
array([False, True])
|
|
525
|
+
|
|
526
|
+
"""
|
|
527
|
+
end = end if end is not None else MAX
|
|
528
|
+
return _endswith_ufunc(a, suffix, start, end)
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
def _code_dispatcher(a, encoding=None, errors=None):
|
|
532
|
+
return (a,)
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
@set_module("numpy.strings")
|
|
536
|
+
@array_function_dispatch(_code_dispatcher)
|
|
537
|
+
def decode(a, encoding=None, errors=None):
|
|
538
|
+
r"""
|
|
539
|
+
Calls :meth:`bytes.decode` element-wise.
|
|
540
|
+
|
|
541
|
+
The set of available codecs comes from the Python standard library,
|
|
542
|
+
and may be extended at runtime. For more information, see the
|
|
543
|
+
:mod:`codecs` module.
|
|
544
|
+
|
|
545
|
+
Parameters
|
|
546
|
+
----------
|
|
547
|
+
a : array_like, with ``bytes_`` dtype
|
|
548
|
+
|
|
549
|
+
encoding : str, optional
|
|
550
|
+
The name of an encoding
|
|
551
|
+
|
|
552
|
+
errors : str, optional
|
|
553
|
+
Specifies how to handle encoding errors
|
|
554
|
+
|
|
555
|
+
Returns
|
|
556
|
+
-------
|
|
557
|
+
out : ndarray
|
|
558
|
+
|
|
559
|
+
See Also
|
|
560
|
+
--------
|
|
561
|
+
:py:meth:`bytes.decode`
|
|
562
|
+
|
|
563
|
+
Notes
|
|
564
|
+
-----
|
|
565
|
+
The type of the result will depend on the encoding specified.
|
|
566
|
+
|
|
567
|
+
Examples
|
|
568
|
+
--------
|
|
569
|
+
>>> import numpy as np
|
|
570
|
+
>>> c = np.array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@',
|
|
571
|
+
... b'\x81\x82\xc2\xc1\xc2\x82\x81'])
|
|
572
|
+
>>> c
|
|
573
|
+
array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@',
|
|
574
|
+
b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7')
|
|
575
|
+
>>> np.strings.decode(c, encoding='cp037')
|
|
576
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
577
|
+
|
|
578
|
+
"""
|
|
579
|
+
return _to_bytes_or_str_array(
|
|
580
|
+
_vec_string(a, np.object_, 'decode', _clean_args(encoding, errors)),
|
|
581
|
+
np.str_(''))
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
@set_module("numpy.strings")
|
|
585
|
+
@array_function_dispatch(_code_dispatcher)
|
|
586
|
+
def encode(a, encoding=None, errors=None):
|
|
587
|
+
"""
|
|
588
|
+
Calls :meth:`str.encode` element-wise.
|
|
589
|
+
|
|
590
|
+
The set of available codecs comes from the Python standard library,
|
|
591
|
+
and may be extended at runtime. For more information, see the
|
|
592
|
+
:mod:`codecs` module.
|
|
593
|
+
|
|
594
|
+
Parameters
|
|
595
|
+
----------
|
|
596
|
+
a : array_like, with ``StringDType`` or ``str_`` dtype
|
|
597
|
+
|
|
598
|
+
encoding : str, optional
|
|
599
|
+
The name of an encoding
|
|
600
|
+
|
|
601
|
+
errors : str, optional
|
|
602
|
+
Specifies how to handle encoding errors
|
|
603
|
+
|
|
604
|
+
Returns
|
|
605
|
+
-------
|
|
606
|
+
out : ndarray
|
|
607
|
+
|
|
608
|
+
See Also
|
|
609
|
+
--------
|
|
610
|
+
str.encode
|
|
611
|
+
|
|
612
|
+
Notes
|
|
613
|
+
-----
|
|
614
|
+
The type of the result will depend on the encoding specified.
|
|
615
|
+
|
|
616
|
+
Examples
|
|
617
|
+
--------
|
|
618
|
+
>>> import numpy as np
|
|
619
|
+
>>> a = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
620
|
+
>>> np.strings.encode(a, encoding='cp037')
|
|
621
|
+
array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@',
|
|
622
|
+
b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7')
|
|
623
|
+
|
|
624
|
+
"""
|
|
625
|
+
return _to_bytes_or_str_array(
|
|
626
|
+
_vec_string(a, np.object_, 'encode', _clean_args(encoding, errors)),
|
|
627
|
+
np.bytes_(b''))
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def _expandtabs_dispatcher(a, tabsize=None):
|
|
631
|
+
return (a,)
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
@set_module("numpy.strings")
|
|
635
|
+
@array_function_dispatch(_expandtabs_dispatcher)
|
|
636
|
+
def expandtabs(a, tabsize=8):
|
|
637
|
+
"""
|
|
638
|
+
Return a copy of each string element where all tab characters are
|
|
639
|
+
replaced by one or more spaces.
|
|
640
|
+
|
|
641
|
+
Calls :meth:`str.expandtabs` element-wise.
|
|
642
|
+
|
|
643
|
+
Return a copy of each string element where all tab characters are
|
|
644
|
+
replaced by one or more spaces, depending on the current column
|
|
645
|
+
and the given `tabsize`. The column number is reset to zero after
|
|
646
|
+
each newline occurring in the string. This doesn't understand other
|
|
647
|
+
non-printing characters or escape sequences.
|
|
648
|
+
|
|
649
|
+
Parameters
|
|
650
|
+
----------
|
|
651
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
652
|
+
Input array
|
|
653
|
+
tabsize : int, optional
|
|
654
|
+
Replace tabs with `tabsize` number of spaces. If not given defaults
|
|
655
|
+
to 8 spaces.
|
|
656
|
+
|
|
657
|
+
Returns
|
|
658
|
+
-------
|
|
659
|
+
out : ndarray
|
|
660
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
661
|
+
depending on input type
|
|
662
|
+
|
|
663
|
+
See Also
|
|
664
|
+
--------
|
|
665
|
+
str.expandtabs
|
|
666
|
+
|
|
667
|
+
Examples
|
|
668
|
+
--------
|
|
669
|
+
>>> import numpy as np
|
|
670
|
+
>>> a = np.array(['\t\tHello\tworld'])
|
|
671
|
+
>>> np.strings.expandtabs(a, tabsize=4) # doctest: +SKIP
|
|
672
|
+
array([' Hello world'], dtype='<U21') # doctest: +SKIP
|
|
673
|
+
|
|
674
|
+
"""
|
|
675
|
+
a = np.asanyarray(a)
|
|
676
|
+
tabsize = np.asanyarray(tabsize)
|
|
677
|
+
|
|
678
|
+
if a.dtype.char == "T":
|
|
679
|
+
return _expandtabs(a, tabsize)
|
|
680
|
+
|
|
681
|
+
buffersizes = _expandtabs_length(a, tabsize)
|
|
682
|
+
out_dtype = f"{a.dtype.char}{buffersizes.max()}"
|
|
683
|
+
out = np.empty_like(a, shape=buffersizes.shape, dtype=out_dtype)
|
|
684
|
+
return _expandtabs(a, tabsize, out=out)
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def _just_dispatcher(a, width, fillchar=None):
|
|
688
|
+
return (a,)
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
@set_module("numpy.strings")
|
|
692
|
+
@array_function_dispatch(_just_dispatcher)
|
|
693
|
+
def center(a, width, fillchar=' '):
|
|
694
|
+
"""
|
|
695
|
+
Return a copy of `a` with its elements centered in a string of
|
|
696
|
+
length `width`.
|
|
697
|
+
|
|
698
|
+
Parameters
|
|
699
|
+
----------
|
|
700
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
701
|
+
|
|
702
|
+
width : array_like, with any integer dtype
|
|
703
|
+
The length of the resulting strings, unless ``width < str_len(a)``.
|
|
704
|
+
fillchar : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
705
|
+
Optional padding character to use (default is space).
|
|
706
|
+
|
|
707
|
+
Returns
|
|
708
|
+
-------
|
|
709
|
+
out : ndarray
|
|
710
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
711
|
+
depending on input types
|
|
712
|
+
|
|
713
|
+
See Also
|
|
714
|
+
--------
|
|
715
|
+
str.center
|
|
716
|
+
|
|
717
|
+
Notes
|
|
718
|
+
-----
|
|
719
|
+
While it is possible for ``a`` and ``fillchar`` to have different dtypes,
|
|
720
|
+
passing a non-ASCII character in ``fillchar`` when ``a`` is of dtype "S"
|
|
721
|
+
is not allowed, and a ``ValueError`` is raised.
|
|
722
|
+
|
|
723
|
+
Examples
|
|
724
|
+
--------
|
|
725
|
+
>>> import numpy as np
|
|
726
|
+
>>> c = np.array(['a1b2','1b2a','b2a1','2a1b']); c
|
|
727
|
+
array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4')
|
|
728
|
+
>>> np.strings.center(c, width=9)
|
|
729
|
+
array([' a1b2 ', ' 1b2a ', ' b2a1 ', ' 2a1b '], dtype='<U9')
|
|
730
|
+
>>> np.strings.center(c, width=9, fillchar='*')
|
|
731
|
+
array(['***a1b2**', '***1b2a**', '***b2a1**', '***2a1b**'], dtype='<U9')
|
|
732
|
+
>>> np.strings.center(c, width=1)
|
|
733
|
+
array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='<U4')
|
|
734
|
+
|
|
735
|
+
"""
|
|
736
|
+
width = np.asanyarray(width)
|
|
737
|
+
|
|
738
|
+
if not np.issubdtype(width.dtype, np.integer):
|
|
739
|
+
raise TypeError(f"unsupported type {width.dtype} for operand 'width'")
|
|
740
|
+
|
|
741
|
+
a = np.asanyarray(a)
|
|
742
|
+
fillchar = np.asanyarray(fillchar)
|
|
743
|
+
|
|
744
|
+
if np.any(str_len(fillchar) != 1):
|
|
745
|
+
raise TypeError(
|
|
746
|
+
"The fill character must be exactly one character long")
|
|
747
|
+
|
|
748
|
+
if np.result_type(a, fillchar).char == "T":
|
|
749
|
+
return _center(a, width, fillchar)
|
|
750
|
+
|
|
751
|
+
fillchar = fillchar.astype(a.dtype, copy=False)
|
|
752
|
+
width = np.maximum(str_len(a), width)
|
|
753
|
+
out_dtype = f"{a.dtype.char}{width.max()}"
|
|
754
|
+
shape = np.broadcast_shapes(a.shape, width.shape, fillchar.shape)
|
|
755
|
+
out = np.empty_like(a, shape=shape, dtype=out_dtype)
|
|
756
|
+
|
|
757
|
+
return _center(a, width, fillchar, out=out)
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
@set_module("numpy.strings")
|
|
761
|
+
@array_function_dispatch(_just_dispatcher)
|
|
762
|
+
def ljust(a, width, fillchar=' '):
|
|
763
|
+
"""
|
|
764
|
+
Return an array with the elements of `a` left-justified in a
|
|
765
|
+
string of length `width`.
|
|
766
|
+
|
|
767
|
+
Parameters
|
|
768
|
+
----------
|
|
769
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
770
|
+
|
|
771
|
+
width : array_like, with any integer dtype
|
|
772
|
+
The length of the resulting strings, unless ``width < str_len(a)``.
|
|
773
|
+
fillchar : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
774
|
+
Optional character to use for padding (default is space).
|
|
775
|
+
|
|
776
|
+
Returns
|
|
777
|
+
-------
|
|
778
|
+
out : ndarray
|
|
779
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
780
|
+
depending on input types
|
|
781
|
+
|
|
782
|
+
See Also
|
|
783
|
+
--------
|
|
784
|
+
str.ljust
|
|
785
|
+
|
|
786
|
+
Notes
|
|
787
|
+
-----
|
|
788
|
+
While it is possible for ``a`` and ``fillchar`` to have different dtypes,
|
|
789
|
+
passing a non-ASCII character in ``fillchar`` when ``a`` is of dtype "S"
|
|
790
|
+
is not allowed, and a ``ValueError`` is raised.
|
|
791
|
+
|
|
792
|
+
Examples
|
|
793
|
+
--------
|
|
794
|
+
>>> import numpy as np
|
|
795
|
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
796
|
+
>>> np.strings.ljust(c, width=3)
|
|
797
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
798
|
+
>>> np.strings.ljust(c, width=9)
|
|
799
|
+
array(['aAaAaA ', ' aA ', 'abBABba '], dtype='<U9')
|
|
800
|
+
|
|
801
|
+
"""
|
|
802
|
+
width = np.asanyarray(width)
|
|
803
|
+
if not np.issubdtype(width.dtype, np.integer):
|
|
804
|
+
raise TypeError(f"unsupported type {width.dtype} for operand 'width'")
|
|
805
|
+
|
|
806
|
+
a = np.asanyarray(a)
|
|
807
|
+
fillchar = np.asanyarray(fillchar)
|
|
808
|
+
|
|
809
|
+
if np.any(str_len(fillchar) != 1):
|
|
810
|
+
raise TypeError(
|
|
811
|
+
"The fill character must be exactly one character long")
|
|
812
|
+
|
|
813
|
+
if np.result_type(a, fillchar).char == "T":
|
|
814
|
+
return _ljust(a, width, fillchar)
|
|
815
|
+
|
|
816
|
+
fillchar = fillchar.astype(a.dtype, copy=False)
|
|
817
|
+
width = np.maximum(str_len(a), width)
|
|
818
|
+
shape = np.broadcast_shapes(a.shape, width.shape, fillchar.shape)
|
|
819
|
+
out_dtype = f"{a.dtype.char}{width.max()}"
|
|
820
|
+
out = np.empty_like(a, shape=shape, dtype=out_dtype)
|
|
821
|
+
|
|
822
|
+
return _ljust(a, width, fillchar, out=out)
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
@set_module("numpy.strings")
|
|
826
|
+
@array_function_dispatch(_just_dispatcher)
|
|
827
|
+
def rjust(a, width, fillchar=' '):
|
|
828
|
+
"""
|
|
829
|
+
Return an array with the elements of `a` right-justified in a
|
|
830
|
+
string of length `width`.
|
|
831
|
+
|
|
832
|
+
Parameters
|
|
833
|
+
----------
|
|
834
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
835
|
+
|
|
836
|
+
width : array_like, with any integer dtype
|
|
837
|
+
The length of the resulting strings, unless ``width < str_len(a)``.
|
|
838
|
+
fillchar : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
839
|
+
Optional padding character to use (default is space).
|
|
840
|
+
|
|
841
|
+
Returns
|
|
842
|
+
-------
|
|
843
|
+
out : ndarray
|
|
844
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
845
|
+
depending on input types
|
|
846
|
+
|
|
847
|
+
See Also
|
|
848
|
+
--------
|
|
849
|
+
str.rjust
|
|
850
|
+
|
|
851
|
+
Notes
|
|
852
|
+
-----
|
|
853
|
+
While it is possible for ``a`` and ``fillchar`` to have different dtypes,
|
|
854
|
+
passing a non-ASCII character in ``fillchar`` when ``a`` is of dtype "S"
|
|
855
|
+
is not allowed, and a ``ValueError`` is raised.
|
|
856
|
+
|
|
857
|
+
Examples
|
|
858
|
+
--------
|
|
859
|
+
>>> import numpy as np
|
|
860
|
+
>>> a = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
861
|
+
>>> np.strings.rjust(a, width=3)
|
|
862
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
863
|
+
>>> np.strings.rjust(a, width=9)
|
|
864
|
+
array([' aAaAaA', ' aA ', ' abBABba'], dtype='<U9')
|
|
865
|
+
|
|
866
|
+
"""
|
|
867
|
+
width = np.asanyarray(width)
|
|
868
|
+
if not np.issubdtype(width.dtype, np.integer):
|
|
869
|
+
raise TypeError(f"unsupported type {width.dtype} for operand 'width'")
|
|
870
|
+
|
|
871
|
+
a = np.asanyarray(a)
|
|
872
|
+
fillchar = np.asanyarray(fillchar)
|
|
873
|
+
|
|
874
|
+
if np.any(str_len(fillchar) != 1):
|
|
875
|
+
raise TypeError(
|
|
876
|
+
"The fill character must be exactly one character long")
|
|
877
|
+
|
|
878
|
+
if np.result_type(a, fillchar).char == "T":
|
|
879
|
+
return _rjust(a, width, fillchar)
|
|
880
|
+
|
|
881
|
+
fillchar = fillchar.astype(a.dtype, copy=False)
|
|
882
|
+
width = np.maximum(str_len(a), width)
|
|
883
|
+
shape = np.broadcast_shapes(a.shape, width.shape, fillchar.shape)
|
|
884
|
+
out_dtype = f"{a.dtype.char}{width.max()}"
|
|
885
|
+
out = np.empty_like(a, shape=shape, dtype=out_dtype)
|
|
886
|
+
|
|
887
|
+
return _rjust(a, width, fillchar, out=out)
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def _zfill_dispatcher(a, width):
|
|
891
|
+
return (a,)
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
@set_module("numpy.strings")
|
|
895
|
+
@array_function_dispatch(_zfill_dispatcher)
|
|
896
|
+
def zfill(a, width):
|
|
897
|
+
"""
|
|
898
|
+
Return the numeric string left-filled with zeros. A leading
|
|
899
|
+
sign prefix (``+``/``-``) is handled by inserting the padding
|
|
900
|
+
after the sign character rather than before.
|
|
901
|
+
|
|
902
|
+
Parameters
|
|
903
|
+
----------
|
|
904
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
905
|
+
|
|
906
|
+
width : array_like, with any integer dtype
|
|
907
|
+
Width of string to left-fill elements in `a`.
|
|
908
|
+
|
|
909
|
+
Returns
|
|
910
|
+
-------
|
|
911
|
+
out : ndarray
|
|
912
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
913
|
+
depending on input type
|
|
914
|
+
|
|
915
|
+
See Also
|
|
916
|
+
--------
|
|
917
|
+
str.zfill
|
|
918
|
+
|
|
919
|
+
Examples
|
|
920
|
+
--------
|
|
921
|
+
>>> import numpy as np
|
|
922
|
+
>>> np.strings.zfill(['1', '-1', '+1'], 3)
|
|
923
|
+
array(['001', '-01', '+01'], dtype='<U3')
|
|
924
|
+
|
|
925
|
+
"""
|
|
926
|
+
width = np.asanyarray(width)
|
|
927
|
+
if not np.issubdtype(width.dtype, np.integer):
|
|
928
|
+
raise TypeError(f"unsupported type {width.dtype} for operand 'width'")
|
|
929
|
+
|
|
930
|
+
a = np.asanyarray(a)
|
|
931
|
+
|
|
932
|
+
if a.dtype.char == "T":
|
|
933
|
+
return _zfill(a, width)
|
|
934
|
+
|
|
935
|
+
width = np.maximum(str_len(a), width)
|
|
936
|
+
shape = np.broadcast_shapes(a.shape, width.shape)
|
|
937
|
+
out_dtype = f"{a.dtype.char}{width.max()}"
|
|
938
|
+
out = np.empty_like(a, shape=shape, dtype=out_dtype)
|
|
939
|
+
return _zfill(a, width, out=out)
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
@set_module("numpy.strings")
|
|
943
|
+
def lstrip(a, chars=None):
|
|
944
|
+
"""
|
|
945
|
+
For each element in `a`, return a copy with the leading characters
|
|
946
|
+
removed.
|
|
947
|
+
|
|
948
|
+
Parameters
|
|
949
|
+
----------
|
|
950
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
951
|
+
chars : scalar with the same dtype as ``a``, optional
|
|
952
|
+
The ``chars`` argument is a string specifying the set of
|
|
953
|
+
characters to be removed. If ``None``, the ``chars``
|
|
954
|
+
argument defaults to removing whitespace. The ``chars`` argument
|
|
955
|
+
is not a prefix or suffix; rather, all combinations of its
|
|
956
|
+
values are stripped.
|
|
957
|
+
|
|
958
|
+
Returns
|
|
959
|
+
-------
|
|
960
|
+
out : ndarray
|
|
961
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
962
|
+
depending on input types
|
|
963
|
+
|
|
964
|
+
See Also
|
|
965
|
+
--------
|
|
966
|
+
str.lstrip
|
|
967
|
+
|
|
968
|
+
Examples
|
|
969
|
+
--------
|
|
970
|
+
>>> import numpy as np
|
|
971
|
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
972
|
+
>>> c
|
|
973
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
974
|
+
# The 'a' variable is unstripped from c[1] because of leading whitespace.
|
|
975
|
+
>>> np.strings.lstrip(c, 'a')
|
|
976
|
+
array(['AaAaA', ' aA ', 'bBABba'], dtype='<U7')
|
|
977
|
+
>>> np.strings.lstrip(c, 'A') # leaves c unchanged
|
|
978
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
979
|
+
>>> (np.strings.lstrip(c, ' ') == np.strings.lstrip(c, '')).all()
|
|
980
|
+
np.False_
|
|
981
|
+
>>> (np.strings.lstrip(c, ' ') == np.strings.lstrip(c)).all()
|
|
982
|
+
np.True_
|
|
983
|
+
|
|
984
|
+
"""
|
|
985
|
+
if chars is None:
|
|
986
|
+
return _lstrip_whitespace(a)
|
|
987
|
+
return _lstrip_chars(a, chars)
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
@set_module("numpy.strings")
|
|
991
|
+
def rstrip(a, chars=None):
|
|
992
|
+
"""
|
|
993
|
+
For each element in `a`, return a copy with the trailing characters
|
|
994
|
+
removed.
|
|
995
|
+
|
|
996
|
+
Parameters
|
|
997
|
+
----------
|
|
998
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
999
|
+
chars : scalar with the same dtype as ``a``, optional
|
|
1000
|
+
The ``chars`` argument is a string specifying the set of
|
|
1001
|
+
characters to be removed. If ``None``, the ``chars``
|
|
1002
|
+
argument defaults to removing whitespace. The ``chars`` argument
|
|
1003
|
+
is not a prefix or suffix; rather, all combinations of its
|
|
1004
|
+
values are stripped.
|
|
1005
|
+
|
|
1006
|
+
Returns
|
|
1007
|
+
-------
|
|
1008
|
+
out : ndarray
|
|
1009
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1010
|
+
depending on input types
|
|
1011
|
+
|
|
1012
|
+
See Also
|
|
1013
|
+
--------
|
|
1014
|
+
str.rstrip
|
|
1015
|
+
|
|
1016
|
+
Examples
|
|
1017
|
+
--------
|
|
1018
|
+
>>> import numpy as np
|
|
1019
|
+
>>> c = np.array(['aAaAaA', 'abBABba'])
|
|
1020
|
+
>>> c
|
|
1021
|
+
array(['aAaAaA', 'abBABba'], dtype='<U7')
|
|
1022
|
+
>>> np.strings.rstrip(c, 'a')
|
|
1023
|
+
array(['aAaAaA', 'abBABb'], dtype='<U7')
|
|
1024
|
+
>>> np.strings.rstrip(c, 'A')
|
|
1025
|
+
array(['aAaAa', 'abBABba'], dtype='<U7')
|
|
1026
|
+
|
|
1027
|
+
"""
|
|
1028
|
+
if chars is None:
|
|
1029
|
+
return _rstrip_whitespace(a)
|
|
1030
|
+
return _rstrip_chars(a, chars)
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
@set_module("numpy.strings")
|
|
1034
|
+
def strip(a, chars=None):
|
|
1035
|
+
"""
|
|
1036
|
+
For each element in `a`, return a copy with the leading and
|
|
1037
|
+
trailing characters removed.
|
|
1038
|
+
|
|
1039
|
+
Parameters
|
|
1040
|
+
----------
|
|
1041
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1042
|
+
chars : scalar with the same dtype as ``a``, optional
|
|
1043
|
+
The ``chars`` argument is a string specifying the set of
|
|
1044
|
+
characters to be removed. If ``None``, the ``chars``
|
|
1045
|
+
argument defaults to removing whitespace. The ``chars`` argument
|
|
1046
|
+
is not a prefix or suffix; rather, all combinations of its
|
|
1047
|
+
values are stripped.
|
|
1048
|
+
|
|
1049
|
+
Returns
|
|
1050
|
+
-------
|
|
1051
|
+
out : ndarray
|
|
1052
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1053
|
+
depending on input types
|
|
1054
|
+
|
|
1055
|
+
See Also
|
|
1056
|
+
--------
|
|
1057
|
+
str.strip
|
|
1058
|
+
|
|
1059
|
+
Examples
|
|
1060
|
+
--------
|
|
1061
|
+
>>> import numpy as np
|
|
1062
|
+
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
1063
|
+
>>> c
|
|
1064
|
+
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
|
|
1065
|
+
>>> np.strings.strip(c)
|
|
1066
|
+
array(['aAaAaA', 'aA', 'abBABba'], dtype='<U7')
|
|
1067
|
+
# 'a' unstripped from c[1] because of leading whitespace.
|
|
1068
|
+
>>> np.strings.strip(c, 'a')
|
|
1069
|
+
array(['AaAaA', ' aA ', 'bBABb'], dtype='<U7')
|
|
1070
|
+
# 'A' unstripped from c[1] because of trailing whitespace.
|
|
1071
|
+
>>> np.strings.strip(c, 'A')
|
|
1072
|
+
array(['aAaAa', ' aA ', 'abBABba'], dtype='<U7')
|
|
1073
|
+
|
|
1074
|
+
"""
|
|
1075
|
+
if chars is None:
|
|
1076
|
+
return _strip_whitespace(a)
|
|
1077
|
+
return _strip_chars(a, chars)
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
def _unary_op_dispatcher(a):
|
|
1081
|
+
return (a,)
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
@set_module("numpy.strings")
|
|
1085
|
+
@array_function_dispatch(_unary_op_dispatcher)
|
|
1086
|
+
def upper(a):
|
|
1087
|
+
"""
|
|
1088
|
+
Return an array with the elements converted to uppercase.
|
|
1089
|
+
|
|
1090
|
+
Calls :meth:`str.upper` element-wise.
|
|
1091
|
+
|
|
1092
|
+
For 8-bit strings, this method is locale-dependent.
|
|
1093
|
+
|
|
1094
|
+
Parameters
|
|
1095
|
+
----------
|
|
1096
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1097
|
+
Input array.
|
|
1098
|
+
|
|
1099
|
+
Returns
|
|
1100
|
+
-------
|
|
1101
|
+
out : ndarray
|
|
1102
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1103
|
+
depending on input types
|
|
1104
|
+
|
|
1105
|
+
See Also
|
|
1106
|
+
--------
|
|
1107
|
+
str.upper
|
|
1108
|
+
|
|
1109
|
+
Examples
|
|
1110
|
+
--------
|
|
1111
|
+
>>> import numpy as np
|
|
1112
|
+
>>> c = np.array(['a1b c', '1bca', 'bca1']); c
|
|
1113
|
+
array(['a1b c', '1bca', 'bca1'], dtype='<U5')
|
|
1114
|
+
>>> np.strings.upper(c)
|
|
1115
|
+
array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')
|
|
1116
|
+
|
|
1117
|
+
"""
|
|
1118
|
+
a_arr = np.asarray(a)
|
|
1119
|
+
return _vec_string(a_arr, a_arr.dtype, 'upper')
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
@set_module("numpy.strings")
|
|
1123
|
+
@array_function_dispatch(_unary_op_dispatcher)
|
|
1124
|
+
def lower(a):
|
|
1125
|
+
"""
|
|
1126
|
+
Return an array with the elements converted to lowercase.
|
|
1127
|
+
|
|
1128
|
+
Call :meth:`str.lower` element-wise.
|
|
1129
|
+
|
|
1130
|
+
For 8-bit strings, this method is locale-dependent.
|
|
1131
|
+
|
|
1132
|
+
Parameters
|
|
1133
|
+
----------
|
|
1134
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1135
|
+
Input array.
|
|
1136
|
+
|
|
1137
|
+
Returns
|
|
1138
|
+
-------
|
|
1139
|
+
out : ndarray
|
|
1140
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1141
|
+
depending on input types
|
|
1142
|
+
|
|
1143
|
+
See Also
|
|
1144
|
+
--------
|
|
1145
|
+
str.lower
|
|
1146
|
+
|
|
1147
|
+
Examples
|
|
1148
|
+
--------
|
|
1149
|
+
>>> import numpy as np
|
|
1150
|
+
>>> c = np.array(['A1B C', '1BCA', 'BCA1']); c
|
|
1151
|
+
array(['A1B C', '1BCA', 'BCA1'], dtype='<U5')
|
|
1152
|
+
>>> np.strings.lower(c)
|
|
1153
|
+
array(['a1b c', '1bca', 'bca1'], dtype='<U5')
|
|
1154
|
+
|
|
1155
|
+
"""
|
|
1156
|
+
a_arr = np.asarray(a)
|
|
1157
|
+
return _vec_string(a_arr, a_arr.dtype, 'lower')
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
@set_module("numpy.strings")
|
|
1161
|
+
@array_function_dispatch(_unary_op_dispatcher)
|
|
1162
|
+
def swapcase(a):
|
|
1163
|
+
"""
|
|
1164
|
+
Return element-wise a copy of the string with
|
|
1165
|
+
uppercase characters converted to lowercase and vice versa.
|
|
1166
|
+
|
|
1167
|
+
Calls :meth:`str.swapcase` element-wise.
|
|
1168
|
+
|
|
1169
|
+
For 8-bit strings, this method is locale-dependent.
|
|
1170
|
+
|
|
1171
|
+
Parameters
|
|
1172
|
+
----------
|
|
1173
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1174
|
+
Input array.
|
|
1175
|
+
|
|
1176
|
+
Returns
|
|
1177
|
+
-------
|
|
1178
|
+
out : ndarray
|
|
1179
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1180
|
+
depending on input types
|
|
1181
|
+
|
|
1182
|
+
See Also
|
|
1183
|
+
--------
|
|
1184
|
+
str.swapcase
|
|
1185
|
+
|
|
1186
|
+
Examples
|
|
1187
|
+
--------
|
|
1188
|
+
>>> import numpy as np
|
|
1189
|
+
>>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c
|
|
1190
|
+
array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'],
|
|
1191
|
+
dtype='|S5')
|
|
1192
|
+
>>> np.strings.swapcase(c)
|
|
1193
|
+
array(['A1b C', '1B cA', 'B cA1', 'Ca1B'],
|
|
1194
|
+
dtype='|S5')
|
|
1195
|
+
|
|
1196
|
+
"""
|
|
1197
|
+
a_arr = np.asarray(a)
|
|
1198
|
+
return _vec_string(a_arr, a_arr.dtype, 'swapcase')
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
@set_module("numpy.strings")
|
|
1202
|
+
@array_function_dispatch(_unary_op_dispatcher)
|
|
1203
|
+
def capitalize(a):
|
|
1204
|
+
"""
|
|
1205
|
+
Return a copy of ``a`` with only the first character of each element
|
|
1206
|
+
capitalized.
|
|
1207
|
+
|
|
1208
|
+
Calls :meth:`str.capitalize` element-wise.
|
|
1209
|
+
|
|
1210
|
+
For byte strings, this method is locale-dependent.
|
|
1211
|
+
|
|
1212
|
+
Parameters
|
|
1213
|
+
----------
|
|
1214
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1215
|
+
Input array of strings to capitalize.
|
|
1216
|
+
|
|
1217
|
+
Returns
|
|
1218
|
+
-------
|
|
1219
|
+
out : ndarray
|
|
1220
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1221
|
+
depending on input types
|
|
1222
|
+
|
|
1223
|
+
See Also
|
|
1224
|
+
--------
|
|
1225
|
+
str.capitalize
|
|
1226
|
+
|
|
1227
|
+
Examples
|
|
1228
|
+
--------
|
|
1229
|
+
>>> import numpy as np
|
|
1230
|
+
>>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c
|
|
1231
|
+
array(['a1b2', '1b2a', 'b2a1', '2a1b'],
|
|
1232
|
+
dtype='|S4')
|
|
1233
|
+
>>> np.strings.capitalize(c)
|
|
1234
|
+
array(['A1b2', '1b2a', 'B2a1', '2a1b'],
|
|
1235
|
+
dtype='|S4')
|
|
1236
|
+
|
|
1237
|
+
"""
|
|
1238
|
+
a_arr = np.asarray(a)
|
|
1239
|
+
return _vec_string(a_arr, a_arr.dtype, 'capitalize')
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
@set_module("numpy.strings")
|
|
1243
|
+
@array_function_dispatch(_unary_op_dispatcher)
|
|
1244
|
+
def title(a):
|
|
1245
|
+
"""
|
|
1246
|
+
Return element-wise title cased version of string or unicode.
|
|
1247
|
+
|
|
1248
|
+
Title case words start with uppercase characters, all remaining cased
|
|
1249
|
+
characters are lowercase.
|
|
1250
|
+
|
|
1251
|
+
Calls :meth:`str.title` element-wise.
|
|
1252
|
+
|
|
1253
|
+
For 8-bit strings, this method is locale-dependent.
|
|
1254
|
+
|
|
1255
|
+
Parameters
|
|
1256
|
+
----------
|
|
1257
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1258
|
+
Input array.
|
|
1259
|
+
|
|
1260
|
+
Returns
|
|
1261
|
+
-------
|
|
1262
|
+
out : ndarray
|
|
1263
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1264
|
+
depending on input types
|
|
1265
|
+
|
|
1266
|
+
See Also
|
|
1267
|
+
--------
|
|
1268
|
+
str.title
|
|
1269
|
+
|
|
1270
|
+
Examples
|
|
1271
|
+
--------
|
|
1272
|
+
>>> import numpy as np
|
|
1273
|
+
>>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c
|
|
1274
|
+
array(['a1b c', '1b ca', 'b ca1', 'ca1b'],
|
|
1275
|
+
dtype='|S5')
|
|
1276
|
+
>>> np.strings.title(c)
|
|
1277
|
+
array(['A1B C', '1B Ca', 'B Ca1', 'Ca1B'],
|
|
1278
|
+
dtype='|S5')
|
|
1279
|
+
|
|
1280
|
+
"""
|
|
1281
|
+
a_arr = np.asarray(a)
|
|
1282
|
+
return _vec_string(a_arr, a_arr.dtype, 'title')
|
|
1283
|
+
|
|
1284
|
+
|
|
1285
|
+
def _replace_dispatcher(a, old, new, count=None):
|
|
1286
|
+
return (a,)
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
@set_module("numpy.strings")
|
|
1290
|
+
@array_function_dispatch(_replace_dispatcher)
|
|
1291
|
+
def replace(a, old, new, count=-1):
|
|
1292
|
+
"""
|
|
1293
|
+
For each element in ``a``, return a copy of the string with
|
|
1294
|
+
occurrences of substring ``old`` replaced by ``new``.
|
|
1295
|
+
|
|
1296
|
+
Parameters
|
|
1297
|
+
----------
|
|
1298
|
+
a : array_like, with ``bytes_`` or ``str_`` dtype
|
|
1299
|
+
|
|
1300
|
+
old, new : array_like, with ``bytes_`` or ``str_`` dtype
|
|
1301
|
+
|
|
1302
|
+
count : array_like, with ``int_`` dtype
|
|
1303
|
+
If the optional argument ``count`` is given, only the first
|
|
1304
|
+
``count`` occurrences are replaced.
|
|
1305
|
+
|
|
1306
|
+
Returns
|
|
1307
|
+
-------
|
|
1308
|
+
out : ndarray
|
|
1309
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1310
|
+
depending on input types
|
|
1311
|
+
|
|
1312
|
+
See Also
|
|
1313
|
+
--------
|
|
1314
|
+
str.replace
|
|
1315
|
+
|
|
1316
|
+
Examples
|
|
1317
|
+
--------
|
|
1318
|
+
>>> import numpy as np
|
|
1319
|
+
>>> a = np.array(["That is a mango", "Monkeys eat mangos"])
|
|
1320
|
+
>>> np.strings.replace(a, 'mango', 'banana')
|
|
1321
|
+
array(['That is a banana', 'Monkeys eat bananas'], dtype='<U19')
|
|
1322
|
+
|
|
1323
|
+
>>> a = np.array(["The dish is fresh", "This is it"])
|
|
1324
|
+
>>> np.strings.replace(a, 'is', 'was')
|
|
1325
|
+
array(['The dwash was fresh', 'Thwas was it'], dtype='<U19')
|
|
1326
|
+
|
|
1327
|
+
"""
|
|
1328
|
+
count = np.asanyarray(count)
|
|
1329
|
+
if not np.issubdtype(count.dtype, np.integer):
|
|
1330
|
+
raise TypeError(f"unsupported type {count.dtype} for operand 'count'")
|
|
1331
|
+
|
|
1332
|
+
arr = np.asanyarray(a)
|
|
1333
|
+
old_dtype = getattr(old, 'dtype', None)
|
|
1334
|
+
old = np.asanyarray(old)
|
|
1335
|
+
new_dtype = getattr(new, 'dtype', None)
|
|
1336
|
+
new = np.asanyarray(new)
|
|
1337
|
+
|
|
1338
|
+
if np.result_type(arr, old, new).char == "T":
|
|
1339
|
+
return _replace(arr, old, new, count)
|
|
1340
|
+
|
|
1341
|
+
a_dt = arr.dtype
|
|
1342
|
+
old = old.astype(old_dtype or a_dt, copy=False)
|
|
1343
|
+
new = new.astype(new_dtype or a_dt, copy=False)
|
|
1344
|
+
max_int64 = np.iinfo(np.int64).max
|
|
1345
|
+
counts = _count_ufunc(arr, old, 0, max_int64)
|
|
1346
|
+
counts = np.where(count < 0, counts, np.minimum(counts, count))
|
|
1347
|
+
buffersizes = str_len(arr) + counts * (str_len(new) - str_len(old))
|
|
1348
|
+
out_dtype = f"{arr.dtype.char}{buffersizes.max()}"
|
|
1349
|
+
out = np.empty_like(arr, shape=buffersizes.shape, dtype=out_dtype)
|
|
1350
|
+
|
|
1351
|
+
return _replace(arr, old, new, counts, out=out)
|
|
1352
|
+
|
|
1353
|
+
|
|
1354
|
+
def _join_dispatcher(sep, seq):
|
|
1355
|
+
return (sep, seq)
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
@array_function_dispatch(_join_dispatcher)
|
|
1359
|
+
def _join(sep, seq):
|
|
1360
|
+
"""
|
|
1361
|
+
Return a string which is the concatenation of the strings in the
|
|
1362
|
+
sequence `seq`.
|
|
1363
|
+
|
|
1364
|
+
Calls :meth:`str.join` element-wise.
|
|
1365
|
+
|
|
1366
|
+
Parameters
|
|
1367
|
+
----------
|
|
1368
|
+
sep : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1369
|
+
seq : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1370
|
+
|
|
1371
|
+
Returns
|
|
1372
|
+
-------
|
|
1373
|
+
out : ndarray
|
|
1374
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1375
|
+
depending on input types
|
|
1376
|
+
|
|
1377
|
+
See Also
|
|
1378
|
+
--------
|
|
1379
|
+
str.join
|
|
1380
|
+
|
|
1381
|
+
Examples
|
|
1382
|
+
--------
|
|
1383
|
+
>>> import numpy as np
|
|
1384
|
+
>>> np.strings.join('-', 'osd') # doctest: +SKIP
|
|
1385
|
+
array('o-s-d', dtype='<U5') # doctest: +SKIP
|
|
1386
|
+
|
|
1387
|
+
>>> np.strings.join(['-', '.'], ['ghc', 'osd']) # doctest: +SKIP
|
|
1388
|
+
array(['g-h-c', 'o.s.d'], dtype='<U5') # doctest: +SKIP
|
|
1389
|
+
|
|
1390
|
+
"""
|
|
1391
|
+
return _to_bytes_or_str_array(
|
|
1392
|
+
_vec_string(sep, np.object_, 'join', (seq,)), seq)
|
|
1393
|
+
|
|
1394
|
+
|
|
1395
|
+
def _split_dispatcher(a, sep=None, maxsplit=None):
|
|
1396
|
+
return (a,)
|
|
1397
|
+
|
|
1398
|
+
|
|
1399
|
+
@array_function_dispatch(_split_dispatcher)
|
|
1400
|
+
def _split(a, sep=None, maxsplit=None):
|
|
1401
|
+
"""
|
|
1402
|
+
For each element in `a`, return a list of the words in the
|
|
1403
|
+
string, using `sep` as the delimiter string.
|
|
1404
|
+
|
|
1405
|
+
Calls :meth:`str.split` element-wise.
|
|
1406
|
+
|
|
1407
|
+
Parameters
|
|
1408
|
+
----------
|
|
1409
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1410
|
+
|
|
1411
|
+
sep : str or unicode, optional
|
|
1412
|
+
If `sep` is not specified or None, any whitespace string is a
|
|
1413
|
+
separator.
|
|
1414
|
+
|
|
1415
|
+
maxsplit : int, optional
|
|
1416
|
+
If `maxsplit` is given, at most `maxsplit` splits are done.
|
|
1417
|
+
|
|
1418
|
+
Returns
|
|
1419
|
+
-------
|
|
1420
|
+
out : ndarray
|
|
1421
|
+
Array of list objects
|
|
1422
|
+
|
|
1423
|
+
Examples
|
|
1424
|
+
--------
|
|
1425
|
+
>>> import numpy as np
|
|
1426
|
+
>>> x = np.array("Numpy is nice!")
|
|
1427
|
+
>>> np.strings.split(x, " ") # doctest: +SKIP
|
|
1428
|
+
array(list(['Numpy', 'is', 'nice!']), dtype=object) # doctest: +SKIP
|
|
1429
|
+
|
|
1430
|
+
>>> np.strings.split(x, " ", 1) # doctest: +SKIP
|
|
1431
|
+
array(list(['Numpy', 'is nice!']), dtype=object) # doctest: +SKIP
|
|
1432
|
+
|
|
1433
|
+
See Also
|
|
1434
|
+
--------
|
|
1435
|
+
str.split, rsplit
|
|
1436
|
+
|
|
1437
|
+
"""
|
|
1438
|
+
# This will return an array of lists of different sizes, so we
|
|
1439
|
+
# leave it as an object array
|
|
1440
|
+
return _vec_string(
|
|
1441
|
+
a, np.object_, 'split', [sep] + _clean_args(maxsplit))
|
|
1442
|
+
|
|
1443
|
+
|
|
1444
|
+
@array_function_dispatch(_split_dispatcher)
|
|
1445
|
+
def _rsplit(a, sep=None, maxsplit=None):
|
|
1446
|
+
"""
|
|
1447
|
+
For each element in `a`, return a list of the words in the
|
|
1448
|
+
string, using `sep` as the delimiter string.
|
|
1449
|
+
|
|
1450
|
+
Calls :meth:`str.rsplit` element-wise.
|
|
1451
|
+
|
|
1452
|
+
Except for splitting from the right, `rsplit`
|
|
1453
|
+
behaves like `split`.
|
|
1454
|
+
|
|
1455
|
+
Parameters
|
|
1456
|
+
----------
|
|
1457
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1458
|
+
|
|
1459
|
+
sep : str or unicode, optional
|
|
1460
|
+
If `sep` is not specified or None, any whitespace string
|
|
1461
|
+
is a separator.
|
|
1462
|
+
maxsplit : int, optional
|
|
1463
|
+
If `maxsplit` is given, at most `maxsplit` splits are done,
|
|
1464
|
+
the rightmost ones.
|
|
1465
|
+
|
|
1466
|
+
Returns
|
|
1467
|
+
-------
|
|
1468
|
+
out : ndarray
|
|
1469
|
+
Array of list objects
|
|
1470
|
+
|
|
1471
|
+
See Also
|
|
1472
|
+
--------
|
|
1473
|
+
str.rsplit, split
|
|
1474
|
+
|
|
1475
|
+
Examples
|
|
1476
|
+
--------
|
|
1477
|
+
>>> import numpy as np
|
|
1478
|
+
>>> a = np.array(['aAaAaA', 'abBABba'])
|
|
1479
|
+
>>> np.strings.rsplit(a, 'A') # doctest: +SKIP
|
|
1480
|
+
array([list(['a', 'a', 'a', '']), # doctest: +SKIP
|
|
1481
|
+
list(['abB', 'Bba'])], dtype=object) # doctest: +SKIP
|
|
1482
|
+
|
|
1483
|
+
"""
|
|
1484
|
+
# This will return an array of lists of different sizes, so we
|
|
1485
|
+
# leave it as an object array
|
|
1486
|
+
return _vec_string(
|
|
1487
|
+
a, np.object_, 'rsplit', [sep] + _clean_args(maxsplit))
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
def _splitlines_dispatcher(a, keepends=None):
|
|
1491
|
+
return (a,)
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
@array_function_dispatch(_splitlines_dispatcher)
|
|
1495
|
+
def _splitlines(a, keepends=None):
|
|
1496
|
+
"""
|
|
1497
|
+
For each element in `a`, return a list of the lines in the
|
|
1498
|
+
element, breaking at line boundaries.
|
|
1499
|
+
|
|
1500
|
+
Calls :meth:`str.splitlines` element-wise.
|
|
1501
|
+
|
|
1502
|
+
Parameters
|
|
1503
|
+
----------
|
|
1504
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1505
|
+
|
|
1506
|
+
keepends : bool, optional
|
|
1507
|
+
Line breaks are not included in the resulting list unless
|
|
1508
|
+
keepends is given and true.
|
|
1509
|
+
|
|
1510
|
+
Returns
|
|
1511
|
+
-------
|
|
1512
|
+
out : ndarray
|
|
1513
|
+
Array of list objects
|
|
1514
|
+
|
|
1515
|
+
See Also
|
|
1516
|
+
--------
|
|
1517
|
+
str.splitlines
|
|
1518
|
+
|
|
1519
|
+
Examples
|
|
1520
|
+
--------
|
|
1521
|
+
>>> np.char.splitlines("first line\\nsecond line")
|
|
1522
|
+
array(list(['first line', 'second line']), dtype=object)
|
|
1523
|
+
>>> a = np.array(["first\\nsecond", "third\\nfourth"])
|
|
1524
|
+
>>> np.char.splitlines(a)
|
|
1525
|
+
array([list(['first', 'second']), list(['third', 'fourth'])], dtype=object)
|
|
1526
|
+
|
|
1527
|
+
"""
|
|
1528
|
+
return _vec_string(
|
|
1529
|
+
a, np.object_, 'splitlines', _clean_args(keepends))
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
def _partition_dispatcher(a, sep):
|
|
1533
|
+
return (a,)
|
|
1534
|
+
|
|
1535
|
+
|
|
1536
|
+
@set_module("numpy.strings")
|
|
1537
|
+
@array_function_dispatch(_partition_dispatcher)
|
|
1538
|
+
def partition(a, sep):
|
|
1539
|
+
"""
|
|
1540
|
+
Partition each element in ``a`` around ``sep``.
|
|
1541
|
+
|
|
1542
|
+
For each element in ``a``, split the element at the first
|
|
1543
|
+
occurrence of ``sep``, and return a 3-tuple containing the part
|
|
1544
|
+
before the separator, the separator itself, and the part after
|
|
1545
|
+
the separator. If the separator is not found, the first item of
|
|
1546
|
+
the tuple will contain the whole string, and the second and third
|
|
1547
|
+
ones will be the empty string.
|
|
1548
|
+
|
|
1549
|
+
Parameters
|
|
1550
|
+
----------
|
|
1551
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1552
|
+
Input array
|
|
1553
|
+
sep : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1554
|
+
Separator to split each string element in ``a``.
|
|
1555
|
+
|
|
1556
|
+
Returns
|
|
1557
|
+
-------
|
|
1558
|
+
out : 3-tuple:
|
|
1559
|
+
- array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the
|
|
1560
|
+
part before the separator
|
|
1561
|
+
- array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the
|
|
1562
|
+
separator
|
|
1563
|
+
- array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the
|
|
1564
|
+
part after the separator
|
|
1565
|
+
|
|
1566
|
+
See Also
|
|
1567
|
+
--------
|
|
1568
|
+
str.partition
|
|
1569
|
+
|
|
1570
|
+
Examples
|
|
1571
|
+
--------
|
|
1572
|
+
>>> import numpy as np
|
|
1573
|
+
>>> x = np.array(["Numpy is nice!"])
|
|
1574
|
+
>>> np.strings.partition(x, " ")
|
|
1575
|
+
(array(['Numpy'], dtype='<U5'),
|
|
1576
|
+
array([' '], dtype='<U1'),
|
|
1577
|
+
array(['is nice!'], dtype='<U8'))
|
|
1578
|
+
|
|
1579
|
+
"""
|
|
1580
|
+
a = np.asanyarray(a)
|
|
1581
|
+
sep = np.asanyarray(sep)
|
|
1582
|
+
|
|
1583
|
+
if np.result_type(a, sep).char == "T":
|
|
1584
|
+
return _partition(a, sep)
|
|
1585
|
+
|
|
1586
|
+
sep = sep.astype(a.dtype, copy=False)
|
|
1587
|
+
pos = _find_ufunc(a, sep, 0, MAX)
|
|
1588
|
+
a_len = str_len(a)
|
|
1589
|
+
sep_len = str_len(sep)
|
|
1590
|
+
|
|
1591
|
+
not_found = pos < 0
|
|
1592
|
+
buffersizes1 = np.where(not_found, a_len, pos)
|
|
1593
|
+
buffersizes3 = np.where(not_found, 0, a_len - pos - sep_len)
|
|
1594
|
+
|
|
1595
|
+
out_dtype = ",".join([f"{a.dtype.char}{n}" for n in (
|
|
1596
|
+
buffersizes1.max(),
|
|
1597
|
+
1 if np.all(not_found) else sep_len.max(),
|
|
1598
|
+
buffersizes3.max(),
|
|
1599
|
+
)])
|
|
1600
|
+
shape = np.broadcast_shapes(a.shape, sep.shape)
|
|
1601
|
+
out = np.empty_like(a, shape=shape, dtype=out_dtype)
|
|
1602
|
+
return _partition_index(a, sep, pos, out=(out["f0"], out["f1"], out["f2"]))
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
@set_module("numpy.strings")
|
|
1606
|
+
@array_function_dispatch(_partition_dispatcher)
|
|
1607
|
+
def rpartition(a, sep):
|
|
1608
|
+
"""
|
|
1609
|
+
Partition (split) each element around the right-most separator.
|
|
1610
|
+
|
|
1611
|
+
For each element in ``a``, split the element at the last
|
|
1612
|
+
occurrence of ``sep``, and return a 3-tuple containing the part
|
|
1613
|
+
before the separator, the separator itself, and the part after
|
|
1614
|
+
the separator. If the separator is not found, the third item of
|
|
1615
|
+
the tuple will contain the whole string, and the first and second
|
|
1616
|
+
ones will be the empty string.
|
|
1617
|
+
|
|
1618
|
+
Parameters
|
|
1619
|
+
----------
|
|
1620
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1621
|
+
Input array
|
|
1622
|
+
sep : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1623
|
+
Separator to split each string element in ``a``.
|
|
1624
|
+
|
|
1625
|
+
Returns
|
|
1626
|
+
-------
|
|
1627
|
+
out : 3-tuple:
|
|
1628
|
+
- array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the
|
|
1629
|
+
part before the separator
|
|
1630
|
+
- array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the
|
|
1631
|
+
separator
|
|
1632
|
+
- array with ``StringDType``, ``bytes_`` or ``str_`` dtype with the
|
|
1633
|
+
part after the separator
|
|
1634
|
+
|
|
1635
|
+
See Also
|
|
1636
|
+
--------
|
|
1637
|
+
str.rpartition
|
|
1638
|
+
|
|
1639
|
+
Examples
|
|
1640
|
+
--------
|
|
1641
|
+
>>> import numpy as np
|
|
1642
|
+
>>> a = np.array(['aAaAaA', ' aA ', 'abBABba'])
|
|
1643
|
+
>>> np.strings.rpartition(a, 'A')
|
|
1644
|
+
(array(['aAaAa', ' a', 'abB'], dtype='<U5'),
|
|
1645
|
+
array(['A', 'A', 'A'], dtype='<U1'),
|
|
1646
|
+
array(['', ' ', 'Bba'], dtype='<U3'))
|
|
1647
|
+
|
|
1648
|
+
"""
|
|
1649
|
+
a = np.asanyarray(a)
|
|
1650
|
+
sep = np.asanyarray(sep)
|
|
1651
|
+
|
|
1652
|
+
if np.result_type(a, sep).char == "T":
|
|
1653
|
+
return _rpartition(a, sep)
|
|
1654
|
+
|
|
1655
|
+
sep = sep.astype(a.dtype, copy=False)
|
|
1656
|
+
pos = _rfind_ufunc(a, sep, 0, MAX)
|
|
1657
|
+
a_len = str_len(a)
|
|
1658
|
+
sep_len = str_len(sep)
|
|
1659
|
+
|
|
1660
|
+
not_found = pos < 0
|
|
1661
|
+
buffersizes1 = np.where(not_found, 0, pos)
|
|
1662
|
+
buffersizes3 = np.where(not_found, a_len, a_len - pos - sep_len)
|
|
1663
|
+
|
|
1664
|
+
out_dtype = ",".join([f"{a.dtype.char}{n}" for n in (
|
|
1665
|
+
buffersizes1.max(),
|
|
1666
|
+
1 if np.all(not_found) else sep_len.max(),
|
|
1667
|
+
buffersizes3.max(),
|
|
1668
|
+
)])
|
|
1669
|
+
shape = np.broadcast_shapes(a.shape, sep.shape)
|
|
1670
|
+
out = np.empty_like(a, shape=shape, dtype=out_dtype)
|
|
1671
|
+
return _rpartition_index(
|
|
1672
|
+
a, sep, pos, out=(out["f0"], out["f1"], out["f2"]))
|
|
1673
|
+
|
|
1674
|
+
|
|
1675
|
+
def _translate_dispatcher(a, table, deletechars=None):
|
|
1676
|
+
return (a,)
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
@set_module("numpy.strings")
|
|
1680
|
+
@array_function_dispatch(_translate_dispatcher)
|
|
1681
|
+
def translate(a, table, deletechars=None):
|
|
1682
|
+
"""
|
|
1683
|
+
For each element in `a`, return a copy of the string where all
|
|
1684
|
+
characters occurring in the optional argument `deletechars` are
|
|
1685
|
+
removed, and the remaining characters have been mapped through the
|
|
1686
|
+
given translation table.
|
|
1687
|
+
|
|
1688
|
+
Calls :meth:`str.translate` element-wise.
|
|
1689
|
+
|
|
1690
|
+
Parameters
|
|
1691
|
+
----------
|
|
1692
|
+
a : array-like, with `np.bytes_` or `np.str_` dtype
|
|
1693
|
+
|
|
1694
|
+
table : str of length 256
|
|
1695
|
+
|
|
1696
|
+
deletechars : str
|
|
1697
|
+
|
|
1698
|
+
Returns
|
|
1699
|
+
-------
|
|
1700
|
+
out : ndarray
|
|
1701
|
+
Output array of str or unicode, depending on input type
|
|
1702
|
+
|
|
1703
|
+
See Also
|
|
1704
|
+
--------
|
|
1705
|
+
str.translate
|
|
1706
|
+
|
|
1707
|
+
Examples
|
|
1708
|
+
--------
|
|
1709
|
+
>>> import numpy as np
|
|
1710
|
+
>>> a = np.array(['a1b c', '1bca', 'bca1'])
|
|
1711
|
+
>>> table = a[0].maketrans('abc', '123')
|
|
1712
|
+
>>> deletechars = ' '
|
|
1713
|
+
>>> np.char.translate(a, table, deletechars)
|
|
1714
|
+
array(['112 3', '1231', '2311'], dtype='<U5')
|
|
1715
|
+
|
|
1716
|
+
"""
|
|
1717
|
+
a_arr = np.asarray(a)
|
|
1718
|
+
if issubclass(a_arr.dtype.type, np.str_):
|
|
1719
|
+
return _vec_string(
|
|
1720
|
+
a_arr, a_arr.dtype, 'translate', (table,))
|
|
1721
|
+
else:
|
|
1722
|
+
return _vec_string(
|
|
1723
|
+
a_arr,
|
|
1724
|
+
a_arr.dtype,
|
|
1725
|
+
'translate',
|
|
1726
|
+
[table] + _clean_args(deletechars)
|
|
1727
|
+
)
|
|
1728
|
+
|
|
1729
|
+
@set_module("numpy.strings")
|
|
1730
|
+
def slice(a, start=None, stop=np._NoValue, step=None, /):
|
|
1731
|
+
"""
|
|
1732
|
+
Slice the strings in `a` by slices specified by `start`, `stop`, `step`.
|
|
1733
|
+
Like in the regular Python `slice` object, if only `start` is
|
|
1734
|
+
specified then it is interpreted as the `stop`.
|
|
1735
|
+
|
|
1736
|
+
Parameters
|
|
1737
|
+
----------
|
|
1738
|
+
a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
|
|
1739
|
+
Input array
|
|
1740
|
+
|
|
1741
|
+
start : None, an integer or an array of integers
|
|
1742
|
+
The start of the slice, broadcasted to `a`'s shape
|
|
1743
|
+
|
|
1744
|
+
stop : None, an integer or an array of integers
|
|
1745
|
+
The end of the slice, broadcasted to `a`'s shape
|
|
1746
|
+
|
|
1747
|
+
step : None, an integer or an array of integers
|
|
1748
|
+
The step for the slice, broadcasted to `a`'s shape
|
|
1749
|
+
|
|
1750
|
+
Returns
|
|
1751
|
+
-------
|
|
1752
|
+
out : ndarray
|
|
1753
|
+
Output array of ``StringDType``, ``bytes_`` or ``str_`` dtype,
|
|
1754
|
+
depending on input type
|
|
1755
|
+
|
|
1756
|
+
Examples
|
|
1757
|
+
--------
|
|
1758
|
+
>>> import numpy as np
|
|
1759
|
+
>>> a = np.array(['hello', 'world'])
|
|
1760
|
+
>>> np.strings.slice(a, 2)
|
|
1761
|
+
array(['he', 'wo'], dtype='<U5')
|
|
1762
|
+
|
|
1763
|
+
>>> np.strings.slice(a, 2, None)
|
|
1764
|
+
array(['llo', 'rld'], dtype='<U5')
|
|
1765
|
+
|
|
1766
|
+
>>> np.strings.slice(a, 1, 5, 2)
|
|
1767
|
+
array(['el', 'ol'], dtype='<U5')
|
|
1768
|
+
|
|
1769
|
+
One can specify different start/stop/step for different array entries:
|
|
1770
|
+
|
|
1771
|
+
>>> np.strings.slice(a, np.array([1, 2]), np.array([4, 5]))
|
|
1772
|
+
array(['ell', 'rld'], dtype='<U5')
|
|
1773
|
+
|
|
1774
|
+
Negative slices have the same meaning as in regular Python:
|
|
1775
|
+
|
|
1776
|
+
>>> b = np.array(['hello world', 'γεια σου κόσμε', '你好世界', '👋 🌍'],
|
|
1777
|
+
... dtype=np.dtypes.StringDType())
|
|
1778
|
+
>>> np.strings.slice(b, -2)
|
|
1779
|
+
array(['hello wor', 'γεια σου κόσ', '你好', '👋'], dtype=StringDType())
|
|
1780
|
+
|
|
1781
|
+
>>> np.strings.slice(b, -2, None)
|
|
1782
|
+
array(['ld', 'με', '世界', ' 🌍'], dtype=StringDType())
|
|
1783
|
+
|
|
1784
|
+
>>> np.strings.slice(b, [3, -10, 2, -3], [-1, -2, -1, 3])
|
|
1785
|
+
array(['lo worl', ' σου κόσ', '世', '👋 🌍'], dtype=StringDType())
|
|
1786
|
+
|
|
1787
|
+
>>> np.strings.slice(b, None, None, -1)
|
|
1788
|
+
array(['dlrow olleh', 'εμσόκ υοσ αιεγ', '界世好你', '🌍 👋'],
|
|
1789
|
+
dtype=StringDType())
|
|
1790
|
+
|
|
1791
|
+
"""
|
|
1792
|
+
# Just like in the construction of a regular slice object, if only start
|
|
1793
|
+
# is specified then start will become stop, see logic in slice_new.
|
|
1794
|
+
if stop is np._NoValue:
|
|
1795
|
+
stop = start
|
|
1796
|
+
start = None
|
|
1797
|
+
|
|
1798
|
+
# adjust start, stop, step to be integers, see logic in PySlice_Unpack
|
|
1799
|
+
if step is None:
|
|
1800
|
+
step = 1
|
|
1801
|
+
step = np.asanyarray(step)
|
|
1802
|
+
if not np.issubdtype(step.dtype, np.integer):
|
|
1803
|
+
raise TypeError(f"unsupported type {step.dtype} for operand 'step'")
|
|
1804
|
+
if np.any(step == 0):
|
|
1805
|
+
raise ValueError("slice step cannot be zero")
|
|
1806
|
+
|
|
1807
|
+
if start is None:
|
|
1808
|
+
start = np.where(step < 0, np.iinfo(np.intp).max, 0)
|
|
1809
|
+
|
|
1810
|
+
if stop is None:
|
|
1811
|
+
stop = np.where(step < 0, np.iinfo(np.intp).min, np.iinfo(np.intp).max)
|
|
1812
|
+
|
|
1813
|
+
return _slice(a, start, stop, step)
|