2[c@`sdZddlmZmZmZddlZddlZddlZddlZddl Z ddl Z ddl m Z mZmZmZmZyddlZeZWnek reZnXdefdYZdefdYZd efd YZd efd YZd efdYZdefdYZdefdYZdefdYZdefdYZ defdYZ!defdYZ"defdYZ#defdYZ$defd YZ%d!efd"YZ&d#efd$YZ'd%efd&YZ(d'efd(YZ)d)efd*YZ*d+efd,YZ+d-efd.YZ,d/efd0YZ-dS(1s Tests related to deprecation warnings. Also a convenient place to document how deprecations should eventually be turned into errors. i(tdivisiontabsolute_importtprint_functionN(t assert_raisest assert_warnstassert_no_warningstassert_array_equaltassert_t_DeprecationTestCasecB`sSeZdZeZdZdZdeeej didZ didZ RS(tcC`s`tjdt|_|jj|_tjdd|jtjdd|jd|jdS(Ntrecordtalwaystcategorytmessage( twarningstcatch_warningstTruetwarn_ctxt __enter__tlogtfilterwarningst warning_clsR (tself((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pytsetup!s cC`s|jjdS(N(Rt__exit__(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pytteardown/sic C`sg|j(|tjkr(|jf}ny|||Wn |rItntk r[nXd}xX|jD]M} | j|jkr|d7}ql|sltd|jj| jfqlqlW|d k r2||kr2dt |j|f} g|jD]} t | j^q} tdj | g| nt jt jdd|jd|jy/||||tkrtd nWn/|k r|tkrtd qnXWd QXd S( sTest if DeprecationWarnings are given and raised. This first checks if the function when called gives `num` DeprecationWarnings, after that it tries to raise these DeprecationWarnings and compares them with `exceptions`. The exceptions can be different for cases where this code path is simply not anticipated and the exception is replaced. Parameters ---------- function : callable The function to test num : int Number of DeprecationWarnings to expect. This should normally be 1. ignore_others : bool Whether warnings of the wrong type should be ignored (note that the message is not checked) function_fails : bool If the function would normally fail, setting this will check for warnings inside a try/except block. exceptions : Exception or tuple of Exceptions Exception to expect when turning the warnings into an error. The default checks for DeprecationWarnings. If exceptions is empty the function is expected to run successfully. args : tuple Arguments for `function` kwargs : dict Keyword arguments for `function` iisexpected %s but got: %ss"%i warnings found but %i expected.s terrorR R s$No error raised during function calls!Error raised during function callN(Rtnpt_NoValueRt ExceptionttupleR tAssertionErrort__name__tNonetlentstrtjoinRRRR ( Rtfunctiontnumt ignore_otherstfunction_failst exceptionstargstkwargst num_foundtwarningtmsgtwtlst((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pytassert_deprecated2s>"   %    c C`s2|j|dddtdtd|d|dS(sTest that warnings are not raised. This is just a shorthand for: self.assert_deprecated(function, num=0, ignore_others=True, exceptions=tuple(), args=args, kwargs=kwargs) R&iR'R)R*R+N(R1RR(RR%R*R+((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pytassert_not_deprecatedys((( R t __module__R tDeprecationWarningRRRtFalseRRR1R2(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRs  Dt_VisibleDeprecationTestCasecB`seZejZRS((R R3RtVisibleDeprecationWarningR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyR6stTestNonTupleNDIndexDeprecationcB`seZdZRS(c C`stjd}tjtjdtt|jddgddggtt|jtdgtjdt t|jddgddggt t|jtdg|ddgWdQXdS(NiR iiR(ii( RtzerosRRRRt FutureWarningt __getitem__tsliceR!R(Rta((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt test_basics  % %(R R3R>(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyR8stTestRankDeprecationcB`seZdZdZRS(sTest that np.rank is deprecated. The function should simply be removed. The VisibleDeprecationWarning may become unnecessary. cC`s)tjd}ttjtj|dS(Ni (RtarangeRR7trank(RR=((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttests(R R3t__doc__RB(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyR?stTestComparisonDeprecationscB`s8eZdZdZdZdZdZdZRS(sPThis tests the deprecation, for non-element-wise comparison logic. This used to mean that when an error occurred during element-wise comparison (i.e. broadcasting) NotImplemented was returned, but also in the comparison itself, False was given instead of the error. Also test FutureWarning for the None comparison. s#elementwise.* comparison failed; .*cC`sxtjtjfD]}|j|dtjdgftjddd}|j|d||d fddtjdtjdddggdt}tjdtjdddggdt}|j|d||fddqWdS( NR*itdtypesi,iiR&ii( toperatorteqtneR1RR9R!tarraytobject(RtopR=tb((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_normal_typess"#--cC`sQtjddg}tjdddg}ttd|||gkdS(NR=RLtccS`s ||kS(N((txty((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyts(RRIRt ValueError(RR=RL((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt test_stringsc`sdtfdY|jfd|jfdtjdddtjdddttfd ttfd ttfd ttfd dS( NtNotArraycB`seZdZdZRS(cS`s tdS(N(t TypeError(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt __array__scS`stS(N(tNotImplemented(Rtother((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt__ne__s(R R3RVRY(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRTs c`stjdkS(Ni(RR@((RT(sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQsc`stjdkS(Ni(RR@((RT(sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQsiREsi4,i4si4,i4,i4c`s dkS(Ni(((tstruct1(sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQsc`s kS(N(((RZtstruct2(sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQsc`s dkS(Ni(((RZ(sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQsc`s kS(N(((RZR[(sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQs(RJR1RR9RR:(R((RTRZR[sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt!test_void_dtype_equality_failuressc C`sttdttdtjxtjdttjddk ttjddkttjddk ttjddkWdQXxtj dtjdgD]}tj ddd}x|dgD]}xt j t j t jt jgD]o}tjdd krntj2}tjd tt|||t| WdQXqtt|||qWqWqWdS( NcS`stjddkS(NiR=(RR@(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQscS`stjddkS(NiR=(RR@(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQsRiR=iREsi4,i4iR (RR:RRRRRRItint16tasarrayR9RFtlttletgttgetsyst version_infoRRUR4(Rtarg1tstructtarg2tftl((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt'test_array_richcompare_legacy_weirdnesss$  %% (R R3RCR RMRSR\Rj(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRDs  tTestDatetime64TimezonecB`s9eZdZdZejje dddZRS(s{Parsing of datetime64 with timezones deprecated in 1.11.0, because datetime64 is now timezone naive rather than UTC only. It will be quite a while before we can remove this, because, at the very least, a lot of existing code uses the 'Z' modifier to avoid conversion from local time to UTC, even if otherwise it handles time in a timezone naive fashion. cC`s0|jtjdd|jtjdddS(NR*s2000-01-01T00+01s2000-01-01T00Z(s2000-01-01T00+01(s2000-01-01T00Z(R1Rt datetime64(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRSstreasons!The pytz module is not available.cC`sMtjd}tjdddddd|}|jtjd|fdS(Ns US/EasterniiittzinfoR*(tpytzttimezonetdatetimeR1RRl(Rttztdt((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt test_datetimes!( R R3RCRStpytesttmarktskipift _has_pytzRt(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRks t!TestNonCContiguousViewDeprecationcB`seZdZdZRS(sIView of non-C-contiguous arrays deprecated in 1.11.0. The deprecation will not be raised for arrays that are both C and F contiguous, as C contiguous is dominant. There are more such arrays with relaxed stride checking than without so the deprecation is not as visible with relaxed stride checking in force. cC`sQ|jtjdjjdtf|jtjdjjdtjfdS(NiR*(ii(ii(R1RtonestTtviewtcomplextint8(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_fortran_contiguouss%(R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRyst8TestInvalidOrderParameterInputForFlattenArrayDeprecationcB`s eZdZdZdZRS(sdInvalid arguments to the ORDER parameter in array.flatten() should not be allowed and should raise an error. However, in the interests of not breaking code that may inadvertently pass invalid arguments to this parameter, a DeprecationWarning will be issued instead for the time being to give developers time to refactor relevant code. cC`s8tjd}d|_|j|jdtjfdS(Niis_Non-string object detected for the array ordering. Please pass in 'C', 'F', 'A', or 'K' insteadR*(ii(RR9R R1tflattentpi(RRO((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt!test_flatten_array_non_string_arg%s cC`s2tjd}d|_|j|jdddS(NiisdNon length-one string passed in for the array ordering. Please pass in 'C', 'F', 'A', or 'K' insteadR*tFACK(ii(R(RR9R R1R(RRO((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt%test_flatten_array_invalid_string_arg,s (R R3RCRR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRs t+TestArrayDataAttributeAssignmentDeprecationcB`seZdZdZRS(sSAssigning the 'data' attribute of an ndarray is unsafe as pointed out in gh-7093. Eventually, such assignment should NOT be allowed, but in the interests of maintaining backwards compatibility, only a Deprecation- Warning will be raised instead for the time being to give developers time to refactor relevant code. cC`sPtjd}tjddd}d|_|j|jdd|jfdS(Ni iiscAssigning the 'data' attribute is an inherently unsafe operation and will be removed in the future.R*tdata(RR@tlinspaceR R1t __setattr__R(RR=RL((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_data_attr_assignmentCs (R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyR;stTestLinspaceInvalidNumParametercB`seZdZdZRS(sArgument to the num parameter in linspace that cannot be safely interpreted as an integer is deprecated in 1.12.0. Argument to the num parameter in linspace that cannot be safely interpreted as an integer should not be allowed. In the interest of not breaking code that passes an argument that could still be interpreted as an integer, a DeprecationWarning will be issued for the time being to give developers time to refactor relevant code. cC`s|jtjdddS(NR*ii g@(ii g@(R1RR(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_float_argXs(R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRMs t9TestBinaryReprInsufficientWidthParameterForRepresentationcB`s eZdZdZdZRS(s If a 'width' parameter is passed into ``binary_repr`` that is insufficient to represent the number in base 2 (positive) or 2's complement (negative) form, the function used to silently ignore the parameter and return a representation using the minimal number of bits needed for the form in question. Such behavior is now considered unsafe from a user perspective and will raise an error in the future. cC`s<d}idd6}d|_|jtjd|d|dS(Ni itwidthsQInsufficient bit width provided. This behavior will raise an error in the future.R*R+(i (R R1Rt binary_repr(RR*R+((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt test_insufficient_width_positivefs  cC`s<d}idd6}d|_|jtjd|d|dS(NiiRsQInsufficient bit width provided. This behavior will raise an error in the future.R*R+(i(R R1RR(RR*R+((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt test_insufficient_width_negativens  (R R3RCRR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyR]s tTestNumericStyleTypecodescB`seZdZdZRS(s| Deprecate the old numeric-style dtypes, which are especially confusing for complex types, e.g. Complex32 -> complex64. When the deprecation cycle is complete, the check for the strings should be removed from PyArray_DescrConverter in descriptor.c, and the deprecated keys should not be added as capitalized aliases in _add_aliases in numerictypes.py. cC`sddddddddd d d d d ddddg}tjddkrb|jddgnx0|D](}|jtjdtfd|fqiWdS(NtBoolt Complex32t Complex64tFloat16tFloat32tFloat64tInt8tInt16tInt32tInt64tObject0t Timedelta64tUInt8tUInt16tUInt32tUInt64tVoid0iitUnicode0tString0R)R*(RcRdtextendR1RRERU(Rtdeprecated_typesRs((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_all_dtypess (R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRwstTestTestDeprecatedcB`seZdZRS(cC`sMt}|jtt|jdd}|j||jdS(NcS`sdS(N(R!(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQscS`stjddtdddS(NtfooR t stackleveli(RtwarnR4(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRs(RRRRR1R(Rttest_case_instanceR((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_assert_deprecateds     (R R3R(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTestClassicIntDivisioncB`seZdZdZRS(s See #7949. Deprecate the numeric-style dtypes with -3 flag in python 2 if used for division List of data types: http://docs.scipy.org/doc/numpy/user/basics.types.html c C`sddddddddd d d d g }tjd dkrtjrd dl}d}xo|D]d}tjdddgd|}tjdddgd|}|j|jd||f|}q_WndS(Ntbool_tint_tintctuint8R~tuint64tint32tuint16tintptint64tuint32R]iiiiRER*(RcRdt py3kwarningRFRRIR1tdiv(RRRKtdt2tdt1R=RL((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_int_dtypess  (R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTestNonNumericConjugatecB`seZdZdZRS(s Deprecate no-op behavior of ndarray.conjugate on non-numeric dtypes, which conflicts with the error behavior of np.conjugate. cC`sx6tjdtjdfD]}|j|jqWxZtjdtjddtjd dtfd tfgfD]}|j|jq|WdS( Niy@tst2016tMiiR=RL(ii(RRIR2t conjugatetintR1(RR=((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_conjugates %+(R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRst TestNPY_CHARcB`seZdZRS(cC`s4ddlm}|j|t|dkdS(Ni(tnpy_char_deprecationtS1(tnumpy.core._multiarray_testsRR1R(RR((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_npy_char_deprecations (R R3R(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTest_UPDATEIFCOPYcB`seZdZdZRS(sh v1.14 deprecates creating an array with the UPDATEIFCOPY flag, use WRITEBACKIFCOPY instead cC`sNddlm}tjdjdd}|j}|j|d|fdS(Ni(tnpy_updateifcopy_deprecationi iR*(RRRR@treshapeR{R1(RRtarrtv((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt!test_npy_updateifcopy_deprecations (R R3RCR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTestDatetimeEventcB`seZdZRS(c C`sxtjtjfD]}|j|dddf|j|dddf|j|ddd f|j|ddd f|j|ddd f|j|ddd fqWdS( NR*itmsiteventi?(Ri(RiiN(RiR(Rii?(RiiR(Riii?(RRlt timedelta64R2R!R1(Rtcls((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyt test_3_tuples(R R3R(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTestTruthTestingEmptyArrayscB`s eZdZdZdZRS(s..*truth value of an empty array is ambiguous.*cC`s#|jtdtjgfdS(NR*(R1tboolRRI(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_1dscC`sa|jtdtjdf|jtdtjdf|jtdtjdfdS(NR*ii(ii(ii(ii(R1RRR9(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_2ds(R R3R RR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRs t TestBincountcB`seZdZRS(cC`s|jddS(NcS`stjdddgddS(Niiit minlength(RtbincountR!(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRQs(R1(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_bincount_minlengths(R R3R(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTestGeneratorSumcB`seZdZRS(cC`s-|jtjddtdDfdS(NR*cs`s|] }|VqdS(N((t.0ti((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pys si(R1Rtsumtrange(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_generator_sums(R R3R(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRstTestFromstringcB`seZdZRS(cC`s!|jtjdddfdS(NR*siP(R1Rt fromstring(R((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyttest_fromstrings(R R3R(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pyRs(.RCt __future__RRRRqRcRFRRutnumpyRt numpy.testingRRRRRRoRRxt ImportErrorR5RJRR6R8R?RDRkRyRRRRRRRRRRRRRRR(((sA/tmp/pip-build-fiC0ax/numpy/numpy/core/tests/test_deprecations.pytsF      (    j W