wL ibdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZddlmZddlmZddlmZddlmZdd lmZdd lmZd Z ddlZd Zed \Z Z!Z"gdZ#dZ$GddZ%GddeZ&dZ'dZ(e)dk(r=ejTjWdsejXde(e-dyy#e$rYxwxYw)aA Sphinx directive to support embedded IPython code. IPython provides an extension for `Sphinx `_ to highlight and run code. This directive allows pasting of entire interactive IPython sessions, prompts and all, and their code will actually get re-executed at doc build time, with all prompts renumbered sequentially. It also allows you to input code as a pure python input by giving the argument python to the directive. The output looks like an interactive ipython section. Here is an example of how the IPython directive can **run** python code, at build time. .. ipython:: In [1]: 1+1 In [1]: import datetime ...: datetime.date.fromisoformat('2022-02-22') It supports IPython construct that plain Python does not understand (like magics): .. ipython:: In [0]: import time In [0]: %pdoc time.sleep This will also support top-level async when using IPython 7.0+ .. ipython:: In [2]: import asyncio ...: print('before') ...: await asyncio.sleep(1) ...: print('after') The namespace will persist across multiple code chucks, Let's define a variable: .. ipython:: In [0]: who = "World" And now say hello: .. ipython:: In [0]: print('Hello,', who) If the current section raises an exception, you can add the ``:okexcept:`` flag to the current block, otherwise the build will fail. .. ipython:: :okexcept: In [1]: 1/0 IPython Sphinx directive module =============================== To enable this directive, simply list it in your Sphinx ``conf.py`` file (making sure the directory where you placed it is visible to sphinx, as is needed for all Sphinx directives). For example, to enable syntax highlighting and the IPython directive:: extensions = ['IPython.sphinxext.ipython_console_highlighting', 'IPython.sphinxext.ipython_directive'] The IPython directive outputs code-blocks with the language 'ipython'. So if you do not have the syntax highlighting extension enabled as well, then all rendered code-blocks will be uncolored. By default this directive assumes that your prompts are unchanged IPython ones, but this can be customized. The configurable options that can be placed in conf.py are: ipython_savefig_dir: The directory in which to save the figures. This is relative to the Sphinx source directory. The default is `html_static_path`. ipython_rgxin: The compiled regular expression to denote the start of IPython input lines. The default is ``re.compile('In \[(\d+)\]:\s?(.*)\s*')``. You shouldn't need to change this. ipython_warning_is_error: [default to True] Fail the build if something unexpected happen, for example if a block raise an exception but does not have the `:okexcept:` flag. The exact behavior of what is considered strict, may change between the sphinx directive version. ipython_rgxout: The compiled regular expression to denote the start of IPython output lines. The default is ``re.compile('Out\[(\d+)\]:\s?(.*)\s*')``. You shouldn't need to change this. ipython_promptin: The string to represent the IPython input prompt in the generated ReST. The default is ``'In [%d]:'``. This expects that the line numbers are used in the prompt. ipython_promptout: The string to represent the IPython prompt in the generated ReST. The default is ``'Out [%d]:'``. This expects that the line numbers are used in the prompt. ipython_mplbackend: The string which specifies if the embedded Sphinx shell should import Matplotlib and set the backend. The value specifies a backend that is passed to `matplotlib.use()` before any lines in `ipython_execlines` are executed. If not specified in conf.py, then the default value of 'agg' is used. To use the IPython directive without matplotlib as a dependency, set the value to `None`. It may end up that matplotlib is still imported if the user specifies so in `ipython_execlines` or makes use of the @savefig pseudo decorator. ipython_execlines: A list of strings to be exec'd in the embedded Sphinx shell. Typical usage is to make certain packages always available. Set this to an empty list if you wish to have no imports always available. If specified in ``conf.py`` as `None`, then it has the effect of making no imports available. If omitted from conf.py altogether, then the default value of ['import numpy as np', 'import matplotlib.pyplot as plt'] is used. ipython_holdcount When the @suppress pseudo-decorator is used, the execution count can be incremented or not. The default behavior is to hold the execution count, corresponding to a value of `True`. Set this to `False` to increment the execution count after each suppressed command. As an example, to use the IPython directive when `matplotlib` is not available, one sets the backend to `None`:: ipython_mplbackend = None An example usage of the directive is: .. code-block:: rst .. ipython:: In [1]: x = 1 In [2]: y = x**2 In [3]: print(y) See http://matplotlib.org/sampledoc/ipython_directive.html for additional documentation. Pseudo-Decorators ================= Note: Only one decorator is supported per input. If more than one decorator is specified, then only the last one is used. In addition to the Pseudo-Decorators/options described at the above link, several enhancements have been made. The directive will emit a message to the console at build-time if code-execution resulted in an exception or warning. You can suppress these on a per-block basis by specifying the :okexcept: or :okwarning: options: .. code-block:: rst .. ipython:: :okexcept: :okwarning: In [1]: 1/0 In [2]: # raise warning. To Do ===== - Turn the ad-hoc test() function into a real test suite. - Break up ipython-specific functionality from matplotlib stuff into better separated code. N)StringIO)AnyDictSet) directives) Directive)logging)Config)InteractiveShell) ProfileDirFT)suppressverbatimsavefigdoctestc ^g}|jd}t|}d}d} ||k(r |S||} |dz }| jjdr|j t | fLt fdtDr| r td} t|j| } | r t| jd| jd} } d d jd gtt| dzzz}t|}g}||krt||}|j|}|s|jdrnJ|j|r||d}|r |dd k(r|dd}| d|zz } n|j ||dz }||krt|j t| | dj|ff|j| }|ret|jd|jd}} ||dz krdj|g||dz}|j t|f |S ) a part is a string of ipython text, comprised of at most one input, one output, comments, and blank lines. The block parser parses the text into a list of:: blocks = [ (TOKEN0, data0), (TOKEN1, data1), ...] where TOKEN is one of [COMMENT | INPUT | OUTPUT ] and data is, depending on the type of token:: COMMENT : the comment string INPUT: the (DECORATOR, INPUT_LINE, REST) where DECORATOR: the input decorator (or None) INPUT_LINE: the input as string (possibly multi-line) REST : any stdout generated by the input line (not OUTPUT) OUTPUT: the output string, possibly multi-line  rN#c3FK|]}jd|zyw@N startswith.0pseudo_decorator line_strippeds i/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/sphinxext/ipython_directive.py zblock_parser.. s*    $ $S+;%; < !z@Applying multiple pseudo-decorators on one line is not supported %s:. )splitlenstriprappendCOMMENTanyPSEUDO_DECORATORS RuntimeErrormatchintgroupjoinstrINPUTOUTPUT)partrgxinrgxoutfmtinfmtoutblocklinesNi decoratorlinematchinlineno inputline continuationNcrestnextlinematchoutoutputrs @r block_parserrJsT* E JJt E E A AI a4 Z LWQx Q  # #C ( LL'4 )   $5  "V* ++d#  #GMM!$4 5w}}Q7GIF$BGGSE3s6{3CA3E,F$GGL\"BDA# !8!<<1x2237((6 (}HHQK3$6#+AB<!11IKK)A1A#4 LL%)Y $!HI J <<%  !23X^^A5FFF1uF8eABi#78 LL&&) *  Lc cheZdZdZddZdZdZdZddZdZ d Z d Z d Z d Z d ZdZdZdZy)EmbeddedSphinxShellz1An embedded IPython instance to run inside SphinxNct|_|g}t}d|j_d|j _d|j _d|j _tjd}d}tjj||}tj|}t j ||}t#j$|j&||_|j(j*|_|j(j,|_d|_d|_||_d|_d|_d|_d|_d|_|D]}|j?|d y) Nz:memory:Fnocolorprofile_)prefixauto_profile_sphinx_build)config profile_dirr$ store_history) rcoutr HistoryManager hist_filer autocall autoindentcolorstempfilemkdtempospathr2r create_profile_dirinstanceatexitregistercleanupIPuser_nsuser_global_nsinputrItmp_profile_dir is_verbatim is_doctest is_suppress directive_pyplot_importedprocess_input_line) self exec_linesrSrjprofnamepdirprofilerfr@s r__init__zEmbeddedSphinxShell.__init__WsDJ  J*4'+0(-2*)2&#***=.ww||OH5//5 & &f' J %ww "gg44  .  !& ?D  # #D # > ?rKcFtj|jdy)NT) ignore_errors)shutilrmtreerjrqs rrezEmbeddedSphinxShell.cleanups d**$?rKcp|jjd|jjdy)Nr)rWseektruncater{s r clear_coutzEmbeddedSphinxShell.clear_couts$ q 1rKc*|j|g|S)NrU)process_input_lines)rqr@rVs rrpz&EmbeddedSphinxShell.process_input_lines''m'LLrKctj}dj|} |jt_|jj |||t_y#|t_wxYw)z#process the input, capturing stdoutrrUN)sysstdoutr2rWrfrun_cell)rqr<rVr source_raws rrz'EmbeddedSphinxShell.process_input_linessOYYu%  CJ GG  Z}  ECJCJs 2A!! A.c|j}|j}|jd}|d}tj||}d|j |j z}d|zg}|ddD]M} | jd\} } | j} | j} |jd| d | Otjj|} d j|} | | fS) z # build out an image directive like # .. image:: somefile.png # :width 4in # # from an input like # savefig somefile.png width=4in r&r/z .. image:: %sr"N=z :z: r) savefig_dir source_dirr'pathlibPath relative_toas_posixr)r*r_r`basenamer2)rqr?rrsaveargsfilenamer`outfile imagerowskwargargval image_fileimage_directives r process_imagez!EmbeddedSphinxShell.process_images&& __ ??3'A;||K2((4==??$w./ ab\ 6E{{3'HC))+C))+C   34 5  6 WW%%g. ))I.?**rKc D|\}}}d}d}|dk(xs |j} |duxr|jdxs |j} |dk(xs |j} |dk(xs |j} |dk(xs |j } |duxr|jd}|j d}t|d kDr|d d k7r|jd d d jd gtt|dzzz}|r|j|\}}g}d}| r|jrd}nd}tjd5}|djdrd}| r2|j!d g|j"xj$d z c_n|j!||ddd| s8t'|D]*\}}|dk(r|d|}n|d|}|j|,| s,t|j)r| r|j||j*j-d|j*j/}| s|s|j|n|r|jd d}d}|j0j2rT|j0j2j4j6}|j0j2j4j8}t;j<t>}| s`d|vsd|vrXd}|d|d|dz }|dz }||dzz }|dz }|jA||jBrtEdjG||| sD]}d}|d|d|dz }|d z }|d!z }|tjH|jJ|jL|jN|jP|jRz }|dz }|jA||jBstEd"jG|||jU|||| |||fS#1swY~xYw)#z6 Process data block for INPUT token. N @verbatim@doctestz @suppressz @okexceptz @okwarningz@savefigrrr$r#r%r"FT)recordr;rUr&Unknown Traceback SyntaxErrorzN >>>------------------------------------------------------------------------- z Exception in z at block ending on line zPSpecify :okexcept: as an option in the ipython:: block to suppress this message zL<<<-------------------------------------------------------------------------z$Unexpected exception in `{}` line {}z Warning in zQSpecify :okwarning: as an option in the ipython:: block to suppress this message zM---------------------------------------------------------------------------- z"Unexpected warning in `{}` line {})+rkrrlrm is_okexcept is_okwarningr'r(r*r2r3r hold_countwarningscatch_warningsendswithrrfexecution_count enumerater)rWr}readrnstatedocumentcurrent_source current_liner getLogger__name__warningwarning_is_errorr.format formatwarningmessagecategoryrrBr@r)rqdata input_promptrBr?rirFrrrkrlrmrr is_savefig input_linesrDret is_semicolonrVwsr>r@formatted_lineprocessed_outputrloggersws r process_inputz!EmbeddedSphinxShell.process_inputs@ "& 5$ ,@0@0@ t+6))*5J:>// ,@0@0@ ,@0@0@  ,.C$2C2C d*6))*5 kk$' { a 2"$""2& s3v;/?/A(B CC *.*<**  +s4::<0[ JJt  q99>>+>  ~~++44CCH^^))22??F""8, , ,-CS2S+A 8VT TA d dA !D( (A # #A NN1 $$":AA(FS  /XvVVii&&X++IIqzz1::qxx''q!((&<CCHfU  ["2Iz?D Ds S Ss ;APPc d}|rv|s|} | j} |j} |jd} d} nb|jjjj} |jj } dj | D cgc]} || z c} } | j|}|dkr;d}|j| | dj |t| |}t|| t|dj} |jdk(rJ| | k7rYd }|j| | dj |t| t| |}t||j||| | g}|d k(xs |j}|r1|jr!|jd j|||Scc} w) z7 Process data block for OUTPUT token.  N Unavailablerrzoutput does not contain output prompt Document source: {0} Raw content: {1} Input line(s): {TAB}{2} Output line(s): {TAB}{3} TABrzdoctest failure Document source: {0} Raw content: {1} On input line(s): {TAB}{2} we found output: {TAB}{3} instead of the expected: {TAB}{4} rz{0} {1} )r)rnrrrcontentr2findrreprr.r(custom_doctestrkr*)rqr output_promptrrIrlr?rrfound submittedsourcerr@indeout_datarks rprocess_outputz"EmbeddedSphinxShell.process_outputds &,EKKME I~~%&'--66EE..00))G$DDS4Z$DE**]+CQw5 HHVWdii .D!%[c3"1o%#m,-.446E J.I%BA $))K2H!%ed9o3!HA&q/)##I{E9M ,@0@0@ 4::< OOK..}dC Dm%Es Gc"|js|gSy)z'Process data fPblock for COMMENT token.N)rm)rqrs rprocess_commentz#EmbeddedSphinxShell.process_comments6M rKc |jd|z}|jdd|jdd|j|d|jdd|jdd|jy) z/ Saves the image file to disk. zplt.gcf().savefig("%s")zbookmark ipy_thisdirFrUzcd -b ipy_savedirzcd -b ipy_thisdirzbookmark -d ipy_thisdirN) ensure_pyplotrpr)rqrcommands r save_imagezEmbeddedSphinxShell.save_images +J6  6eL  35I u=  35I  9O rKc g}d}d}|jj}|j|z}|j|z}d}d} d} |D]s\} } | tk(r|j | } n<| t k(rd} |j| ||\} }}}}}} n| tk(r | sd}d}d}d}|jr|jjjj}|jjjj}|jj}dj|Dcgc]}||z c}}d}|j!||||| }t"j$j'|t)d |j+| ||||} | r |d d k(sJ|d = sc|j-| v||j/||| fScc}w) zZ process block from the block_parser and return a list of processed lines NFTrrrrz Invalid block: Block contains an output prompt without an input prompt. Document source: {0} Content begins at line {1}: {2} Problematic block within content: {TAB}{3} rzAn invalid block was detected.rr$)rfrpromptin promptoutr+rr4rr5rnrrrrrr2rrrwriter.rextendr)rqr;rrIrrBrrrr found_inputtokenrrrlr?r linenumberrrr@rs r process_blockz!EmbeddedSphinxShell.process_blocks ((}}v- /    . %KE4//5%" ,,T<H9; J&"!C!"J*F+G~~%)^^%9%9%B%B%O%O !%!5!5!>!>!M!M"&.."8"8"&))G,LDS4Z,L"MNA WeMAJJ$$Q'&'GHH''m[(. I(24 r7b=)=B 8$]. %b  ! OOJ 'O##A-Ms' G c|jsCdtjvrddl}|jd|j ddd|_yy) z Ensures that pyplot has been imported into the embedded IPython shell. Also, makes sure to set the backend appropriately if not set already. matplotlib.backendsrNaggimport matplotlib.pyplot as pltFrUT)rormodules matplotlibuserp)rqrs rrz!EmbeddedSphinxShell.ensure_pyplot sT$$$CKK7 " u%  # #$E27 $ 9$(D !%rKc g}d}d}d}|j}d}t|D]4\}} | jt| s|j | 4t fdt Dr|j| gd| vrd}ejdr|j| gdd jd gtt|d zzz} |sH||zd } |j | |d z } tj|j d n| d | } |j | t||d zkDr2||d z} t| t| jz dkDr[ tjdj|||d z} t| j dtj"r<| j dj D]}t|tj$sd}!n|j d d}|s|j'|j)dd|j+d}7|S#t$rd}|}YMwxYw#t$rY\wxYw)a content is a list of strings. it is unedited directive content This runs it line by line in the InteractiveShell, prepends prompts as needed capturing stderr and stdout, then returns the content as a list as if it were ipython code FNrc3FK|]}jd|zywrrrs rr z:EmbeddedSphinxShell.process_pure_python..>s*$((/?)?@r!rTrr#r$r%r"r&rr rz plt.clf()rU)rrr)r(r*r,r-rrr2r3astparse Exceptionlstrip isinstancebody FunctionDefReturnrrpr)rqrrIr multilinemultiline_startr9ctrBr@rDmodifiedrGmodelementrs @rprocess_pure_pythonz'EmbeddedSphinxShell.process_pure_python&sj   %g.= LFD JJLMt9 d#(9 tf%$"G'', tf%&rwwuc#b'l1n/E'FFL',rz=A h'a-IIm,MM#& (4T: h'w<&1*,&vz2H8}s8??+<'==A  )) IIgofQh&GHJC!#((1+s?'*xx{'7'72G)'3::>,1 2 c*$) ""$'' 5'I!{= ~ A!- $I&,O-.!s+<&I?BI0I0 I-,I-0 I<;I<cddlm}|j}|d}||vr|||||||ydj|}t |)z1 Perform a specialized doctest. r)doctestszInvalid option to @doctest: {0}N)custom_doctestsrr'rr) rqr?rrrrargs doctest_typers rrz"EmbeddedSphinxShell.custom_doctestwsU . Aw 8 # "H\ "4{E9 M188FAA, rKN)T)r __module__ __qualname____doc__rvrerrprrrrrrrrrrrKrrMrMTsX;3?j@M +@aDHN` C$J)4Ob rKrMceZdZUdZeed<dZeed<dZeed<dZ eed<e je je je je je jdZ eeefed <d ZeZeed <d Zd ZdZdZy )IPythonDirectiveT has_contentrrequired_argumentsoptional_argumentsfinal_argumuent_whitespace)pythonrrrokexcept okwarning option_specN seen_docsc |jjjjj}|j }|jjjjj }tjj||}|j}|j}|j}|j}|j}|j} |j } |j"} ||||||| | | |f Sr)rrsettingsenvrSipython_savefig_dirsrcdirr_r`r2 ipython_rgxinipython_rgxoutipython_warning_is_erroripython_promptinipython_promptoutipython_mplbackendipython_execlinesipython_holdcount) rqrSrrr7r8rrr mplbackendrrrs rget_config_optionsz#IPythonDirective.get_config_optionss$$--118800 ZZ((1155<< ggll:{; ))** 99,,-- .. -- -- Z)ZZIY[ [rKc t|j\ }}}}}}}}} } tj||j Q|r.dtjvrtrddl } | j|t||_||j _ |jjj |j"vr|j j$j&j)d|j j$_|j"j-|jjj ||j _||j _||j _||j _||j _||j _| |j _| |j _|j j?d|zd|j jA||||fS#t$r)} | jtj k7rYd} ~ d} ~ wwxYw)Nrrrzbookmark ipy_savedir "%s"FrU)!r"r_makedirsOSErrorerrnoEEXISTshellrruse_matplotlibrrrMrnrrrrrfhistory_managerresetraddr7r8rrrrrrrpr) rqrrr7r8rrr!rrrrrrs rsetupzIPythonDirective.setupsBFAXAXAZ ?j%9 Z-=  KK $ ::  33;;F>! z*-Z8DJ$(DJJ ::   - -T^^ C JJMM ) ) / / 1,-DJJMM ) NN  tzz22AA B! " & ( !,  *  * &6 # %% '+ 5U &  fh 11Y ww%,,&' sH H7H22H7cr|jjdd|jjy)Nzbookmark -d ipy_savedirFrU)r(rprr{s rteardownzIPythonDirective.teardowns/ %%&?49 & ; rKc d}|j\}}}}|j}d|v|j_d|v|j_d|v|j_d|v|j_d|v|j_d|jvr,|j}|jj||_ dj|jjd }d d g} g} tjt} |D]} t!| ||||} t#| rw|jj%| \}}|D]?}| j'|jdDcgc]}d j)|c}A|| j+|d j)|j,j.j0|j,j.j2}|jj4r t7|| j9|| D]D}| j+d | j'|jd| j+d Ft#| dkDr\|rt;dj| n?|j<j?| |j<j@jCd|jEgScc}w)NFrrrrrrrz z.. code-block:: ipythonr$z {0}z&Code input with no code at {}, line {}r"r)#r-optionsr(rmrlrkrr argumentsrrr2r'r rrrJr(rrrr*rrrrrr.rprint state_machine insert_inputrrr/)rqdebugr7r8rrr1rpartsr<figuresrr6r;rowsfigurerowr@rs rrunzIPythonDirective.runs.2ZZ\*vx,,!+w!6  )W 4 !+w!6 !+w!6 "-"8  t~~ %llG::99'BDL $,,'--f5*B/""8, ,D ufh JE5z#zz77> f@CLL.1iio"?&*#+//$"7"?@@%NN6*B#V $ 3 3 B B $ 3 3 @ @B::..&w//NN7+% ,( F LL  LLd+ , LL   u:>dii&' ""//4--99@@CE  C"?s'K% )rrrr bool__annotations__r r0r rr unchangedflagrrr3rr(setrrr"r-r/r<rrKrr r sK'++&&OOOO??OO__ #Kc3h EUIs[,32j CrKr c(|t_|jdt|j ddd|j ddd|j dt j dd|j d t j d d|j d d d|j d dd|j ddddg}tr|jd|j d|d|j dddddd}|S)NipythonrrrrTrzIn \[(\d+)\]:\s?(.*)\s*rzOut\[(\d+)\]:\s?(.*)\s*rzIn [%d]:rzOut[%d]:rrzimport numpy as nprrr )parallel_read_safeparallel_write_safe) r-app add_directiver add_config_valuerecompiler)r*)rF execlinesmetadatas rr-r-1s EIi!12. 5A3T5A$>?H)$>?H+Z?,j%@ -ue<&&I:;,i?,dE:&*4HH OrKc rgd}|dd}i}|D]'}|jd}tdd||ddddd )y)N)a6 In [9]: pwd Out[9]: '/home/jdhunter/py4science/book' In [10]: cd bookdata/ /home/jdhunter/py4science/book/bookdata In [2]: from pylab import * In [2]: ion() In [3]: im = imread('stinkbug.png') @savefig mystinkbug.png width=4in In [4]: imshow(im) Out[4]: z In [1]: x = 'hello world' # string methods can be # used to alter the string @doctest In [2]: x.upper() Out[2]: 'HELLO WORLD' @verbatim In [3]: x.st x.startswith x.strip a6 In [130]: url = 'http://ichart.finance.yahoo.com/table.csv?s=CROX\ .....: &d=9&e=22&f=2009&g=d&a=1&br=8&c=2006&ignore=.csv' In [131]: print url.split('&') ['http://ichart.finance.yahoo.com/table.csv?s=CROX', 'd=9', 'e=22', 'f=2009', 'g=d', 'a=1', 'b=8', 'c=2006', 'ignore=.csv'] In [60]: import urllib a\ In [133]: import numpy.random @suppress In [134]: numpy.random.seed(2358) @doctest In [135]: numpy.random.rand(10,2) Out[135]: array([[ 0.64524308, 0.59943846], [ 0.47102322, 0.8715456 ], [ 0.29370834, 0.74776844], [ 0.99539577, 0.1313423 ], [ 0.16250302, 0.21103583], [ 0.81626524, 0.1312433 ], [ 0.67338089, 0.72302393], [ 0.7566368 , 0.07033696], [ 0.22591016, 0.77731835], [ 0.0072729 , 0.34273127]]) zt In [106]: print x jdh In [109]: for i in range(10): .....: print i .....: .....: 0 1 2 3 4 5 6 7 8 9 z In [144]: from pylab import * In [145]: ion() # use a semicolon to suppress the output @savefig test_hist.png width=4in In [151]: hist(np.random.randn(10000), 100); @savefig test_plot.png width=4in In [151]: plot(np.random.randn(10000), 'o'); z # use a semicolon to suppress the output In [151]: plt.clf() @savefig plot_simple.png width=4in In [151]: plot([1,2,3]) @savefig hist_simple.png width=4in In [151]: hist(np.random.randn(10000), 100); a~ # update the current fig In [151]: ylabel('number') In [152]: title('normal distribution') @savefig hist_with_text.png In [153]: grid(True) @doctest float In [154]: 0.1 + 0.2 Out[154]: 0.3 @doctest float In [155]: np.arange(16).reshape(4,4) Out[155]: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) In [1]: x = np.arange(16, dtype=float).reshape(4,4) In [2]: x[0,0] = np.inf In [3]: x[0,1] = np.nan @doctest float In [4]: x Out[4]: array([[ inf, nan, 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [ 12., 13., 14., 15.]]) rrr6r)r2r1rrBcontent_offset block_textrr4)r'r )examplesr1examplers rtestrRQsYW Hr|HG--%D'")!)-$ $D rK__main___staticz!All OK? Check figures in _static/).rrcr&r_rrIrr]rrryiortypingrrrdocutils.parsers.rstrr sphinx.utilr traitlets.configr IPythonr IPython.core.profiledirr r)rrranger+r4r5r-rJrMr r-rRrr`isdirmkdirr3rrKrr_skt    !!,*$$. N (B k\ppfgygT@fR Z 77== #F -. G!  s"CC! C!