K ilddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z  ddlZd)dZdZe j$j'e de j$j)ddgd Zd Zd Zd Ze j$j'edud dZdDcgc]}d|z c}Zej6dkredDcgc]}d|z c}z ZgdZdDcgc]}d|z c}Zej6dkredDcgc]}d|z c}z ZdZej6dk\rgZndgZdZ gdZ!ej6dkre!gdz Z!dZ"dZ#e j$jIejJddvdd Z&d!Z'e j$jQd"d#Z)d$Z*d%Z+d&e,fd'Z-d(Z.y#e$rdZYwxYwcc}wcc}wcc}wcc}w)*N)IS_WASMc| |j}i}t|D]]}|dk(r t||}t|ds"t|ds/|j|k7s?|jdz|jz||<_|S)zEReturns a mapping of all objects with the wrong __module__ attribute.core __module____name__.)rdirgetattrhasattrr)module module_nameresultsnameitems a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/numpy/tests/test_public_api.py check_dirrsoo GF B 6> vt$ D, 'GD*,EOO{2 OOc1DMMAGDM B Nc8ddi}tt}||k(sJy)Nrecarrayznumpy.rec.recarray)rnp) allowlist bad_resultss rtest_numpy_namespacer&s, (IB-K ) ## #rzcan't start subprocess)reasonrtestingctjdd|zf}tj|}|rJ|t t vsJy)aMake sure we can actually use the modules we lazy load. While not exported as part of the public API, it was accessible. With the use of __getattr__ and __dir__, this isn't always true It can happen that an infinite recursion may happen. This is the only way I found that would force the failure to appear on the badly implemented code. We also test for the presence of the lazily imported modules in dir z-czimport numpy; numpy.N)sys executable subprocess check_outputr r)rexeresults rtest_import_lazy_importr#1sD >>4!7$!> ?C  $ $S )F: 3r7??rc|tttttttk(sJy)zWAssert that output of dir has only one "testing/tester" attribute without duplicateN)lenr rsetrrtest_dir_testingr(Hs' s2w<3s3r7|, ,, ,rcDttj}|ik(sJyN)rrlinalgrs rtest_numpy_linalgr-NsBII&K "  rcDttj}|ik(sJyr*)rrfftr,s rtest_numpy_fftr0SsBFF#K "  rz#ctypes not available in this pythonctjtjjj }t |dd}|Jdy)Ntest_not_exportedzG'test_not_exported' is mistakenly exported, NPY_NO_EXPORT does not work)ctypesCDLLr_core_multiarray_tests__file__r )cdllfs rtest_NPY_NO_EXPORTr:XsG ;;rxx11:: ;D)40A 95459r) ctypeslibdtypes exceptionsf2pyr/libzlib.array_utilsz lib.formatzlib.introspectz lib.mixinsz lib.npyiozlib.recfunctionsz lib.scimathzlib.stride_tricksr+maz ma.extrasz ma.mrecords polynomialzpolynomial.chebyshevzpolynomial.hermitezpolynomial.hermite_ezpolynomial.laguerrezpolynomial.legendrezpolynomial.polynomialrandomstringsrztesting.overridestypingztyping.mypy_pluginversionnumpy.) ) distutilszdistutils.cpuinfozdistutils.exec_commandzdistutils.misc_utilz distutils.logzdistutils.system_info) numpy.charz numpy.emath numpy.rec))conftestrzcore.multiarrayz core.numericz core.umathzcore.arrayprintzcore.defchararrayzcore.einsumfunczcore.fromnumericzcore.function_basezcore.getlimitszcore.numerictypeszcore.overridesz core.recordszcore.shape_basez f2py.auxfuncszf2py.capi_mapsz f2py.cb_rulesz f2py.cfuncszf2py.common_ruleszf2py.crackfortranz f2py.diagnosez f2py.f2py2ezf2py.f90mod_ruleszf2py.func2subrz f2py.rulesz f2py.symboliczf2py.use_rulesz fft.helperzlib.user_arrayzlinalg.lapack_litez linalg.linalgzma.corez ma.testutilsmatlib matrixlibzmatrixlib.defmatrixzpolynomial.polyutilsz random.mtrandzrandom.bit_generatorztesting.print_coercion_tables)7zdistutils.armccompilerzdistutils.fujitsuccompilerzdistutils.ccompilerzdistutils.ccompiler_optzdistutils.commandzdistutils.command.autodistzdistutils.command.bdist_rpmzdistutils.command.buildzdistutils.command.build_clibzdistutils.command.build_extzdistutils.command.build_pyzdistutils.command.build_scriptszdistutils.command.build_srczdistutils.command.configz!distutils.command.config_compilerzdistutils.command.developzdistutils.command.egg_infozdistutils.command.installzdistutils.command.install_clibzdistutils.command.install_dataz!distutils.command.install_headerszdistutils.command.sdistzdistutils.conv_templatezdistutils.corezdistutils.extensionzdistutils.fcompilerzdistutils.fcompiler.absoftzdistutils.fcompiler.armzdistutils.fcompiler.compaqzdistutils.fcompiler.environmentzdistutils.fcompiler.g95zdistutils.fcompiler.gnuzdistutils.fcompiler.hpuxzdistutils.fcompiler.ibmzdistutils.fcompiler.intelzdistutils.fcompiler.laheyzdistutils.fcompiler.mipszdistutils.fcompiler.nagzdistutils.fcompiler.nonezdistutils.fcompiler.pathf95zdistutils.fcompiler.pgzdistutils.fcompiler.nvzdistutils.fcompiler.sunzdistutils.fcompiler.vastzdistutils.fcompiler.fujitsuzdistutils.from_templatezdistutils.intelccompilerzdistutils.lib2defzdistutils.line_endingszdistutils.mingw32ccompilerzdistutils.msvccompilerzdistutils.npy_pkg_configzdistutils.numpy_distributionzdistutils.pathccompilerzdistutils.unixccompilerc^d|vxr(d|vxr"d|vxr|tvxr|tvxr|tvS)z%Check if this needs to be considered.z._z.testsz.setup)PUBLIC_MODULESPUBLIC_ALIASED_MODULESPRIVATE_BUT_PRESENT_MODULESrs r is_unexpectedrT sT D 4XT1 4hd6J 4  & 4 . . 4 3 3 rznumpy.distutils.msvc9compilercg}tjtjtjdzdD],\}}}t |s|t vs|j|.|rtd|y)z| Test that we don't add anything that looks like a new public module by accident. Check is based on filenames. rN)pathprefixonerrorzFound unexpected modules: ) pkgutil walk_packagesr__path__rrT SKIP_LISTappendAssertionError)modnames_modnameispkgs rtest_all_modules_are_expectedrcs| H$22 :<++:K;?A%7E  !gY&> OOG $%9(DEEr) znumpy.lib.mathznumpy.matlib.charznumpy.matlib.recznumpy.matlib.emathznumpy.matlib.exceptionsznumpy.matlib.mathznumpy.matlib.linalgznumpy.matlib.fftznumpy.matlib.randomznumpy.matlib.ctypeslibznumpy.matlib.ma)znumpy.distutils.log.sysznumpy.distutils.log.loggingznumpy.distutils.log.warningsc~d}|d}tD]}|j|||rtd|y)a Method checking all objects. The pkgutil-based method in `test_all_modules_are_expected` does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like: import .lib.scimath as emath To check if something in a module is (effectively) public, one can check if there's anything in that namespace that's a public function/object but is not exposed in a higher-level namespace. For example for a `numpy.lib` submodule:: mod = np.lib.mixins for obj in mod.__all__: if obj in np.__all__: continue elif obj in np.lib.__all__: continue else: print(obj) cTg}tj|}t|dr |j}n t |}|D]g}|j dr|dz|z}t t||tjsBt|sN|tvsW|j|i|S)N__all__r`r) importlib import_moduler rfr startswith isinstancer types ModuleTyperT SKIP_LIST_2r])mod_namemembersr objnamesobjname fullobjnames rfind_unexpected_membersz@test_all_modules_are_expected_2..find_unexpected_membersas((2 69 %~~H6{H 8G%%c*&nw6 gfg68H8HI$[1&k9#NN;7  8rnumpyz3Found unexpected object(s) that look like modules: N)rPextendr^)rsunexpected_membersras rtest_all_modules_are_expected_2rwHs`2$19!D!!"9'"BCD));(<>? ?rc4d}g}tD]}||r |j||rtd|tD]} t ||rtd|t jd5}t jdtt jdttD]}||r |j| ddd|rtd |y#t $r|j|YwxYw#1swY:xYw) a  Check that all submodules listed higher up in this file can be imported Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may simply need to be removed from the list (deprecation may or may not be needed - apply common sense). cZ tj|y#ttf$rYywxYw)NFT)rgrh ImportErrorAttributeError)r s rcheck_importablez-test_api_importable..check_importables3   # #K 0^,  s **z3Modules in the public API that cannot be imported: z/Modules in the public API that were not found: T)recordalways)categoryNzNModules that are not really public but looked public and can not be imported: ) rPr]r^rQevalr{warningscatch_warningsfilterwarningsDeprecationWarning ImportWarningrR)r| module_namesr ws rtest_api_importabler|sFL%-  ,    ,-**69: :.-  -  - ''3n67 7   -13EF=A6 1K#K0##K0 11@ ,~/0 0 -    , -11s% C.8ADD.D  D DPy_DEBUG)Nr0zNumPy possibly built with `USE_DEBUG=True ./tools/travis-test.sh`, which does not expose the `array_api` entry point. See https://github.com/numpy/numpy/pull/19800ctjdtjv}tj j }|jd}t|dk(r|rd}t|dy td|D}|jd k(ry|j}d |jd }|tusJ|y#t$r|rd}t|dYywxYw) zx Entry point for Array API implementation can be found with importlib and returns the main numpy namespace. platlib array_api)grouprz%No entry points for 'array_api' foundNc3@K|]}|jdk(s|yw)rtNrS).0eps r z-test_array_api_entry_point..s<G);"._remove_private_memberss!%?aQ\\#->???s##c&|jdhS)Nbool) difference)rs r_remove_exceptionszAtest_main_namespace_all_dir_coherence.._remove_exceptionss$$ &   rzMembers that break symmetry: N)rrf__dir__symmetric_difference)rr all_members dir_memberss r%test_main_namespace_all_dir_coherencerso @ *"**5K$[1K)"**,7K$[1K + %'  + +K 8 9 ; %rz:ignore:numpy.core(\.\w+)? is deprecated:DeprecationWarningcddlm}ttjD]}|j ds|dvs d|t vr$ttj|}tj|rv|jrj|jjT|}|}t|D]A}|j drt||}td||g}|t||urAJ|t||urJy) zp Check that all "semi-public" members of `numpy._core` are also accessible from `numpy.core` shims. rNr`)testsrCrF__z numpy.core.)fromlist) numpy.corerr rr5rirQr inspectismodule__spec__origin __import__)r member_namemember submodulesubmodule_namesubmodule_member_namesubmodule_membercore_submodules rtest_core_shims_coherencers288}'8   " "3 '22 }%)?? ;/   V $FOO$:$:$FI(N),Y %(33D9#*96K#L !+!.!1234" (7"$9,  WT;77 77O'8rcddlm}ddlm}ddlm}t h}t}i}g}t g}t|dkDr|j}t|D]x} t|| } tj| rXd| jvrJ| jds9d| jvr+| dvr'| |vr#|j!| |j#| }tj$| st'| |t j(fs| |vr| jd vr|jdk(r| jd k(r|jjd r| jd vr|jd k(r|jdk(r,|j!| j|j|| fY|j#| |j|| <{t|dkDr~~~t|dk(sJ|y)z Check that each public function is available from one location only. Test performs BFS search traversing NumPy's public API. It flags any function-like object that is accessible from more that one place. r)Callable)Any)_ArrayFunctionDispatcherrtr` numpy._core)r>r@rr)absolutearccosarccosharcsinarcsinharctanarctan2arctanh left_shift right_shift conjugateinvert remainderdivide concatenatepower transposetrimcoefznumpy.polynomialaddequal not_equalgreater greater_equalless less_equal numpy.stringsrJN)collections.abcrrDrnumpy._core._multiarray_umathrrr&r%popr r rrrrir]r isfunctionrjufunc) rrdispatched_functionvisited_modulesvisited_functionsfunctions_original_pathsduplicated_functions modules_queuer rrs rtest_functions_single_locationr+s)/1TO14?A)+DM m q ""$v;P GKV[1F  (6??***3/V__4#EEo-$$V,##F+""6*6$7#BC..,&72 :5223EF +!//_< ,6 )//1&9; &))&17=,V4aP G m q l ?,D # $ )?+?? )rc6tg}th}t}g}t|dkDr|j}t |D]}t ||}t j|rXd|jvrJ|jds9d|jvr+|dvr'||vr#|j||j|}t j|rt|ds|jjdr|j|jk7s||vs|jdvr|jdk(r|jd k(r|jdk(s|jd k(r|jd k(r7|jd vr|jd k(rV|jdvrf|j|j|j|jd|j|t|dkDr|rt|dk(sJ|yy)Nrrtr`r) charrr>r@ lapack_litemrecordsrrrArDmtrand bit_generatorrrrrr}rK)c_long c_longlongznumpy.ctypeslib) BitGenerator GeneratorMT19937PCG64 PCG64DXSMPhilox RandomStateSFC64 SeedSequence)Funcactualexpected)rr&r%rr r rrrrir]rr rrrrincorrect_entriesr rrs rtest___module___attributersDMdO m q ""$v;< .KV[1F  (6??***3/V__4$ o-$$V,##F+$$V, +OO..s3!!V__4//??'oo8__ 2v'7Q__0V__ 5SOO'??OO'88??'!(( &"("3"3$*OO"%%f-y< . m q @$%*=,==*rreturnc|j}|j}|j}||jddk(sJtj |}t jt|jd|}||uxsFt|dxr8t|dxr*|j|jk(xr|j|k(S)Nr__get____self__) __qualname__rrsplitrmodules functoolsreducer r )objqualnamerr r actual_objs r"_check_correct_qualname_and_modulersH <>#&r* ** * [[ %F!!'8>>#+>GJc  J * 0wsJ/G 0  ! !S^^ 3 0  # #x / rc:tg}th}t}g}t|dkDrZ|j}t |D]+}t ||}t j|rXd|jvrJ|jds9|dvr5d|jvr'||vr#|j||j|}t j|rt|ds|jjdr|jdrt|r||vs|j|jd||jd|jd|j|.t|dkDrZ|rt|dk(sJ|yy) Nrrtr`>rrDrr:)found_at advertises)rr&r%rr r rrrrir]rr rrr rs r*test___qualname___and___module___attributersDMdO m q ""$v; .KV[1F  (6??***3/#66V__4o-$$V,##F+$$V, +OO..s3**3/6v>//!(('-&7q $F)/):):(;1V=P=P$%*=,==*rr*)/r rgrrYrrrrkrpytestrtr numpy.testingrr3rzrrmarkskipif parametrizer#r(r-r0r:rP version_inforQrRrTr\rcrmrwrxfailget_config_varrrrrrrrrr)ss0rr!s   ! $G$<=)-.>*-   FdN@B5B5(!)!1(Q,!Dg  1   N*6*x!|*Vg8 :$1 :$:zwI01IF,  gK1?h-0`IZ(> 8''T2A.8.8br@jG>Tt&)>U Fv!F &*X:$s)G 8 G G4 G$ G) GG