B @`f4@sZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Ze ejddedddZe ejd dedddZe ed ed d ed dedddZe ed ed d ed dedddZe ejjdd ddedddZe ejjdd ddedddZejjej ddGdddZdS)N) DataFrameIndexSeries) expressionsi'ABCDZfloat64)columnsdtypedABZfloat32CZint64DZint32)r r r r)i'r)size)erznot using numexpr)reasonc @seZdZddZddZeeedddZedd d Z edd d Z edd dZ e j deeeejjddeedeeeege j dddgddZddZe j ddddddge j d eefeefgd!d"Ze j dd#d$d%d&d'd(ge j d eefeefgd)d*Ze j d+ddge j deeeegd,d-Ze j d.d/d0d1gd2d3Ze j d.d4d5d6gd7d8Ze j d9e dd:dd;gdd:dd;ggdd?gd@e ddgddggdd?gd@e ddgddgddggd5z)TestExpressions.call_op..FT)__name__r&operatorrset_use_numexprget_test_result)dfotherr$r%opexpectedresultr )r%r!call_op2s      zTestExpressions.call_op)r$cCsdt_ddddddg}xj|D]b}|||||\}}|dkrr|jdkrX|jjd ksrtntd d |jj Dsrtt ||qWdS) Nraddsubmulmodtruedivfloordivrfcss|]}|jdkVqdS)r;N)kind).0r'r r r! Msz1TestExpressions.run_arithmetic..) rrr4ndimr r<AssertionErrorallZdtypesvaluestm assert_equal)rr/r0r$ operationsarithr3r2r r r!run_arithmeticCs  zTestExpressions.run_arithmeticc Csfdt_tdddddddg}x@|D]8}|||||\}}t}|sRtd t||q&Wd S) z tests solely that the result is the same whether or not numexpr is enabled. Need to test whether the function does the correct thing elsewhere. rTgtltgeleeqnez Did not use numexpr as expected.N)rrZ set_test_moder4r.r@rCrD) rr/r0r$rErFr3r2Z used_numexprr r r! run_binaryPs   zTestExpressions.run_binarycCs~||||td|d}td||||x@tt|jD].}||jdd|f|jdd|f|qHWdS)NFrT)rGrr-rNrangelenriloc)rr/r0r$Z binary_compir r r! run_frameas  zTestExpressions.run_framer/r)rr$TFcCs||||dS)N)rS)rr/r$r r r!test_arithmeticpszTestExpressions.test_arithmeticcCsttjd|j|jd}|r tttjd|j|jd}|r@tttjd|j|jd}|r`tttjd|j|jd}|stdS)Nevaluate+)r_can_use_numexprr,r5rr@rr)rr3r r r! test_invalidszTestExpressions.test_invalidz opname,op_str)r5rW)r6-)r7*)r9/)powz**z left,rightcsNfdd}td|tdtd|t|dS)Ncsdkr dStt}t|d}|jks6ttj|dd}tj|dd}t|trrt ||nt ||j t|d}|rtdS)Nr]rVT) use_numexprF) r&r,rrX_is_mixed_typer@rV isinstancerrCassert_frame_equalassert_numpy_array_equalrB)r1r3r2)leftop_strr%rightr r!testits  z/TestExpressions.test_binary_ops..testitFTr)rr-set_numexpr_threads)rr%rdrcrerfr )rcrdr%rer!test_binary_opss   zTestExpressions.test_binary_ops)rH>)rI<)rJz>=)rKz<=)rLz==)rMz!=csNfdd}td|tdtd|t|dS)Ncsd}d}tt}t||d}|jks:ttj||dd}tj||dd}t|trvt ||nt ||j t||d}|rtdS)NrrVT)r^F) r&r,rrXr_r@rVr`rrCrarbrB)Zf12Zf22r1r3r2)rcrdr%rer r!rfs  z3TestExpressions.test_comparison_ops..testitFTr)rr-rg)rr%rdrcrerfr )rcrdr%rer!test_comparison_opss    z#TestExpressions.test_comparison_opscondcsJfdd}td|tdtd|t|dS)NcsXtjjtjd}|t|jjd}t|jjd}t ||dS)N)r r) npemptyshapeZbool_fillrwhererBrCrb)cr3r2)rlr/r r!rfs  z*TestExpressions.test_where..testitFTr)rr-rg)rrlr/rfr )rlr/r! test_wheres   zTestExpressions.test_wherez op_str,opname)r\r9)z//r:)z**r]c Cs.ttjddktjddkd}dt|d}tt|}t|}t j t |d|||WdQRXt j t |d||j |j WdQRXt j t |d||j dWdQRXt j t |d|d|j WdQRXt j t |d|d|WdQRXt j t |d||dWdQRXdS) N g?)abz operator z not implemented for bool dtypes)matchTF)rrmrandomrandreprr&r,reescapepytestZraisesNotImplementedErrorrurv)rrdr%r/msgr;err_msgr r r!!test_bool_ops_raise_on_arithmetics &  z1TestExpressions.test_bool_ops_raise_on_arithmetic)rWr5)r[r7)rZr6c Csd}ttj|dktj|dkd}dddd}dd d d }tt|}tt|||}|d krjdStjd ddftjdd&|||} |||} t | | WdQRXtjdd.||j |j } ||j |j } t | | WdQRXtjdd*||j d } ||j d } t | | WdQRXtjdd*|d|j } |d|j } t | | WdQRXtjdd&|d|} |d|} t | | WdQRXtjdd&||d } ||d } t | | WdQRXWdQRXdS)Nrtg?)rurv|&^)rWr[rZor_and_xor)rrrrZT)Z min_elementsF)Zcheck_stacklevel) rrmrxryr&r,rCr^Zassert_produces_warningrarurvZassert_series_equal) rrdr%nr/subsZ sub_funcsr;Zferer r r! test_bool_ops_warn_on_arithmeticsB&             z0TestExpressions.test_bool_ops_warn_on_arithmeticztest_input,expectedrZaarurvrrr )rrZbbcCs>|jddddgf|jddddgf}t||dS)Nrur )locrMrCra)rZ test_inputr2r3r r r!test_bool_ops_column_name_dtypeEs.z/TestExpressions.test_bool_ops_column_name_dtyperF)r5r6r7r8r9r:axis)rrcCs|j}|dkr$|jjdddf}n|jjdddf}dt_t||}td|||d}td|||d}t||dS)NrrF)rT)rrQrrr&r-rCra)rrrFr/r0Zop_funcr2r3r r r!test_frame_series_axis_s     z&TestExpressions.test_frame_series_axisr1__mod____rmod__zGH-36552)r)Zmarks __floordiv__ __rfloordiv__boxscalarrc Csdt_tdd}||}t||}||}td||}tdt||xlt|D]`\} } |t kr~|j | df} n|| } ytt | ||}Wnt k rYq^X| |ks^t q^WdS)Nri2FT)rrrmZaranger&r-rCrD enumeraterrQintZeroDivisionErrorr@) rr1rrdataobjrr3r2rRelemZ scalar_resultr r r!,test_python_semantics_with_numexpr_installedws$      zs.