/usr/share/doc/python-hypothesis/html/numpy.html is in python-hypothesis-doc 3.44.1-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | <!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hypothesis for the Scientific Stack — Hypothesis 3.44.1 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="index" title="Index"
href="genindex.html"/>
<link rel="search" title="Search" href="search.html"/>
<link rel="top" title="Hypothesis 3.44.1 documentation" href="index.html"/>
<link rel="next" title="Health checks" href="healthchecks.html"/>
<link rel="prev" title="Hypothesis for Django users" href="django.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> Hypothesis
</a>
<div class="version">
3.44.1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quick start guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="details.html">Details and advanced features</a></li>
<li class="toctree-l1"><a class="reference internal" href="settings.html">Settings</a></li>
<li class="toctree-l1"><a class="reference internal" href="data.html">What you can generate and how</a></li>
<li class="toctree-l1"><a class="reference internal" href="extras.html">Additional packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="django.html">Hypothesis for Django users</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Hypothesis for the Scientific Stack</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#numpy">numpy</a></li>
<li class="toctree-l2"><a class="reference internal" href="#pandas">pandas</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#supported-versions">Supported Versions</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="healthchecks.html">Health checks</a></li>
<li class="toctree-l1"><a class="reference internal" href="database.html">The Hypothesis Example Database</a></li>
<li class="toctree-l1"><a class="reference internal" href="stateful.html">Stateful testing</a></li>
<li class="toctree-l1"><a class="reference internal" href="supported.html">Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">Some more examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="community.html">Community</a></li>
<li class="toctree-l1"><a class="reference internal" href="manifesto.html">The Purpose of Hypothesis</a></li>
<li class="toctree-l1"><a class="reference internal" href="endorsements.html">Testimonials</a></li>
<li class="toctree-l1"><a class="reference internal" href="usage.html">Open Source Projects using Hypothesis</a></li>
<li class="toctree-l1"><a class="reference internal" href="strategies.html">Projects extending Hypothesis</a></li>
<li class="toctree-l1"><a class="reference internal" href="changes.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="development.html">Ongoing Hypothesis Development</a></li>
<li class="toctree-l1"><a class="reference internal" href="support.html">Help and Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="packaging.html">Packaging Guidelines</a></li>
<li class="toctree-l1"><a class="reference internal" href="reproducing.html">Reproducing Failures</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Hypothesis</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Hypothesis for the Scientific Stack</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/numpy.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="hypothesis-for-the-scientific-stack">
<h1>Hypothesis for the Scientific Stack<a class="headerlink" href="#hypothesis-for-the-scientific-stack" title="Permalink to this headline">¶</a></h1>
<div class="section" id="numpy">
<span id="hypothesis-numpy"></span><h2>numpy<a class="headerlink" href="#numpy" title="Permalink to this headline">¶</a></h2>
<p>Hypothesis offers a number of strategies for <a class="reference external" href="http://www.numpy.org/">NumPy</a> testing,
available in the <code class="xref py py-mod docutils literal"><span class="pre">hypothesis[numpy]</span></code> <a class="reference internal" href="extras.html"><span class="doc">extra</span></a>.
It lives in the <code class="docutils literal"><span class="pre">hypothesis.extra.numpy</span></code> package.</p>
<p>The centerpiece is the <a class="reference internal" href="#hypothesis.extra.numpy.arrays" title="hypothesis.extra.numpy.arrays"><code class="xref py py-func docutils literal"><span class="pre">arrays()</span></code></a> strategy, which generates arrays with
any dtype, shape, and contents you can specify or give a strategy for.
To make this as useful as possible, strategies are provided to generate array
shapes and generate all kinds of fixed-size or compound dtypes.</p>
<span class="target" id="module-hypothesis.extra.numpy"></span><dl class="function">
<dt id="hypothesis.extra.numpy.arrays">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">arrays</code><span class="sig-paren">(</span><em>dtype</em>, <em>shape</em>, <em>elements=None</em>, <em>fill=None</em>, <em>unique=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#arrays"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.arrays" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a strategy for generating <code class="xref py py-class docutils literal"><span class="pre">numpy's</span>
<span class="pre">ndarrays</span></code>.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">dtype</span></code> may be any valid input to <code class="xref py py-class docutils literal"><span class="pre">numpy.dtype</span></code>
(this includes <code class="docutils literal"><span class="pre">dtype</span></code> objects), or a strategy that generates such
values.</li>
<li><code class="docutils literal"><span class="pre">shape</span></code> may be an integer >= 0, a tuple of length >= 0 of such
integers, or a strategy that generates such values.</li>
<li><code class="docutils literal"><span class="pre">elements</span></code> is a strategy for generating values to put in the array.
If it is None a suitable value will be inferred based on the dtype,
which may give any legal value (including eg <code class="docutils literal"><span class="pre">NaN</span></code> for floats).
If you have more specific requirements, you should supply your own
elements strategy.</li>
<li><code class="docutils literal"><span class="pre">fill</span></code> is a strategy that may be used to generate a single background
value for the array. If None, a suitable default will be inferred
based on the other arguments. If set to
<a class="reference internal" href="data.html#hypothesis.strategies.nothing" title="hypothesis.strategies.nothing"><code class="xref py py-func docutils literal"><span class="pre">st.nothing()</span></code></a> then filling
behaviour will be disabled entirely and every element will be generated
independently.</li>
<li><code class="docutils literal"><span class="pre">unique</span></code> specifies if the elements of the array should all be
distinct from one another. Note that in this case multiple NaN values
may still be allowed. If fill is also set, the only valid values for
it to return are NaN values (anything for which <code class="xref py py-func docutils literal"><span class="pre">numpy.isnan()</span></code>
returns True. So e.g. for complex numbers (nan+1j) is also a valid fill).
Note that if unique is set to True the generated values must be hashable.</li>
</ul>
<p>Arrays of specified <code class="docutils literal"><span class="pre">dtype</span></code> and <code class="docutils literal"><span class="pre">shape</span></code> are generated for example
like this:</p>
<div class="highlight-pycon"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="n">arrays</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">int8</span><span class="p">,</span> <span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span><span class="o">.</span><span class="n">example</span><span class="p">()</span>
<span class="go">array([[-8, 6, 3],</span>
<span class="go"> [-6, 4, 6]], dtype=int8)</span>
</pre></div>
</div>
<ul class="simple">
<li>See <a class="reference internal" href="data.html"><span class="doc">What you can generate and how</span></a>.</li>
</ul>
<div class="highlight-pycon"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis.strategies</span> <span class="kn">import</span> <span class="n">floats</span>
<span class="gp">>>> </span><span class="n">arrays</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">float</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">elements</span><span class="o">=</span><span class="n">floats</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">example</span><span class="p">()</span>
<span class="go">array([ 0.88974794, 0.77387938, 0.1977879 ])</span>
</pre></div>
</div>
<p>Array values are generated in two parts:</p>
<ol class="arabic simple">
<li>Some subset of the coordinates of the array are populated with a value
drawn from the elements strategy (or its inferred form).</li>
<li>If any coordinates were not assigned in the previous step, a single
value is drawn from the fill strategy and is assigned to all remaining
places.</li>
</ol>
<p>You can set fill to <a class="reference internal" href="data.html#hypothesis.strategies.nothing" title="hypothesis.strategies.nothing"><code class="xref py py-func docutils literal"><span class="pre">nothing()</span></code></a> if you want to
disable this behaviour and draw a value for every element.</p>
<p>If fill is set to None then it will attempt to infer the correct behaviour
automatically: If unique is True, no filling will occur by default.
Otherwise, if it looks safe to reuse the values of elements across
multiple coordinates (this will be the case for any inferred strategy, and
for most of the builtins, but is not the case for mutable values or
strategies built with flatmap, map, composite, etc) then it will use the
elements strategy as the fill, else it will default to having no fill.</p>
<p>Having a fill helps Hypothesis craft high quality examples, but its
main importance is when the array generated is large: Hypothesis is
primarily designed around testing small examples. If you have arrays with
hundreds or more elements, having a fill value is essential if you want
your tests to run in reasonable time.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.array_shapes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">array_shapes</code><span class="sig-paren">(</span><em>min_dims=1</em>, <em>max_dims=3</em>, <em>min_side=1</em>, <em>max_side=10</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#array_shapes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.array_shapes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for array shapes (tuples of int >= 1).</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.scalar_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">scalar_dtypes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#scalar_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.scalar_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy that can return any non-flexible scalar dtype.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.unsigned_integer_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">unsigned_integer_dtypes</code><span class="sig-paren">(</span><em>endianness='?'</em>, <em>sizes=(8</em>, <em>16</em>, <em>32</em>, <em>64)</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#unsigned_integer_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.unsigned_integer_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for unsigned integer dtypes.</p>
<p>endianness may be <code class="docutils literal"><span class="pre"><</span></code> for little-endian, <code class="docutils literal"><span class="pre">></span></code> for big-endian,
<code class="docutils literal"><span class="pre">=</span></code> for native byte order, or <code class="docutils literal"><span class="pre">?</span></code> to allow either byte order.
This argument only applies to dtypes of more than one byte.</p>
<p>sizes must be a collection of integer sizes in bits. The default
(8, 16, 32, 64) covers the full range of sizes.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.integer_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">integer_dtypes</code><span class="sig-paren">(</span><em>endianness='?'</em>, <em>sizes=(8</em>, <em>16</em>, <em>32</em>, <em>64)</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#integer_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.integer_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for signed integer dtypes.</p>
<p>endianness and sizes are treated as for
<a class="reference internal" href="#hypothesis.extra.numpy.unsigned_integer_dtypes" title="hypothesis.extra.numpy.unsigned_integer_dtypes"><code class="xref py py-func docutils literal"><span class="pre">unsigned_integer_dtypes()</span></code></a>.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.floating_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">floating_dtypes</code><span class="sig-paren">(</span><em>endianness='?'</em>, <em>sizes=(16</em>, <em>32</em>, <em>64)</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#floating_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.floating_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for floating-point dtypes.</p>
<p>sizes is the size in bits of floating-point number. Some machines support
96- or 128-bit floats, but these are not generated by default.</p>
<p>Larger floats (96 and 128 bit real parts) are not supported on all
platforms and therefore disabled by default. To generate these dtypes,
include these values in the sizes argument.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.complex_number_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">complex_number_dtypes</code><span class="sig-paren">(</span><em>endianness='?'</em>, <em>sizes=(64</em>, <em>128)</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#complex_number_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.complex_number_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for complex-number dtypes.</p>
<p>sizes is the total size in bits of a complex number, which consists
of two floats. Complex halfs (a 16-bit real part) are not supported
by numpy and will not be generated by this strategy.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.datetime64_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">datetime64_dtypes</code><span class="sig-paren">(</span><em>max_period='Y'</em>, <em>min_period='ns'</em>, <em>endianness='?'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#datetime64_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.datetime64_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for datetime64 dtypes, with various precisions from
year to attosecond.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.timedelta64_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">timedelta64_dtypes</code><span class="sig-paren">(</span><em>max_period='Y'</em>, <em>min_period='ns'</em>, <em>endianness='?'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#timedelta64_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.timedelta64_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for timedelta64 dtypes, with various precisions from
year to attosecond.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.byte_string_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">byte_string_dtypes</code><span class="sig-paren">(</span><em>endianness='?'</em>, <em>min_len=0</em>, <em>max_len=16</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#byte_string_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.byte_string_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for generating bytestring dtypes, of various lengths
and byteorder.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.unicode_string_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">unicode_string_dtypes</code><span class="sig-paren">(</span><em>endianness='?'</em>, <em>min_len=0</em>, <em>max_len=16</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#unicode_string_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.unicode_string_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for generating unicode string dtypes, of various
lengths and byteorder.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.array_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">array_dtypes</code><span class="sig-paren">(</span><em>subtype_strategy=scalar_dtypes()</em>, <em>min_size=1</em>, <em>max_size=5</em>, <em>allow_subarrays=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#array_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.array_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a strategy for generating array (compound) dtypes, with members
drawn from the given subtype strategy.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.numpy.nested_dtypes">
<code class="descclassname">hypothesis.extra.numpy.</code><code class="descname">nested_dtypes</code><span class="sig-paren">(</span><em>subtype_strategy=scalar_dtypes()</em>, <em>max_leaves=10</em>, <em>max_itemsize=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/numpy.html#nested_dtypes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.numpy.nested_dtypes" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the most-general dtype strategy.</p>
<p>Elements drawn from this strategy may be simple (from the
subtype_strategy), or several such values drawn from
<a class="reference internal" href="#hypothesis.extra.numpy.array_dtypes" title="hypothesis.extra.numpy.array_dtypes"><code class="xref py py-func docutils literal"><span class="pre">array_dtypes()</span></code></a> with <code class="docutils literal"><span class="pre">allow_subarrays=True</span></code>. Subdtypes in an
array dtype may be nested to any depth, subject to the max_leaves
argument.</p>
</dd></dl>
</div>
<div class="section" id="pandas">
<span id="hypothesis-pandas"></span><h2>pandas<a class="headerlink" href="#pandas" title="Permalink to this headline">¶</a></h2>
<p>Hypothesis provides strategies for several of the core pandas data types:
<code class="xref py py-class docutils literal"><span class="pre">pandas.Index</span></code>, <code class="xref py py-class docutils literal"><span class="pre">pandas.Series</span></code> and <code class="xref py py-class docutils literal"><span class="pre">pandas.DataFrame</span></code>.</p>
<p>The general approach taken by the pandas module is that there are multiple
strategies for generating indexes, and all of the other strategies take the
number of entries they contain from their index strategy (with sensible defaults).
So e.g. a Series is specified by specifying its <code class="xref py py-class docutils literal"><span class="pre">numpy.dtype</span></code> (and/or
a strategy for generating elements for it).</p>
<span class="target" id="module-hypothesis.extra.pandas"></span><dl class="function">
<dt id="hypothesis.extra.pandas.indexes">
<code class="descclassname">hypothesis.extra.pandas.</code><code class="descname">indexes</code><span class="sig-paren">(</span><em>elements=None</em>, <em>dtype=None</em>, <em>min_size=0</em>, <em>max_size=None</em>, <em>unique=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/pandas/impl.html#indexes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.pandas.indexes" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides a strategy for producing a <code class="xref py py-class docutils literal"><span class="pre">pandas.Index</span></code>.</p>
<p>Arguments:</p>
<ul class="simple">
<li>elements is a strategy which will be used to generate the individual
values of the index. If None, it will be inferred from the dtype. Note:
even if the elements strategy produces tuples, the generated value
will not be a MultiIndex, but instead be a normal index whose elements
are tuples.</li>
<li>dtype is the dtype of the resulting index. If None, it will be inferred
from the elements strategy. At least one of dtype or elements must be
provided.</li>
<li>min_size is the minimum number of elements in the index.</li>
<li>max_size is the maximum number of elements in the index. If None then it
will default to a suitable small size. If you want larger indexes you
should pass a max_size explicitly.</li>
<li>unique specifies whether all of the elements in the resulting index
should be distinct.</li>
</ul>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.pandas.range_indexes">
<code class="descclassname">hypothesis.extra.pandas.</code><code class="descname">range_indexes</code><span class="sig-paren">(</span><em>min_size=0</em>, <em>max_size=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/pandas/impl.html#range_indexes"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.pandas.range_indexes" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides a strategy which generates an <code class="xref py py-class docutils literal"><span class="pre">Index</span></code> whose
values are 0, 1, …, n for some n.</p>
<p>Arguments:</p>
<ul class="simple">
<li>min_size is the smallest number of elements the index can have.</li>
<li>max_size is the largest number of elements the index can have. If None
it will default to some suitable value based on min_size.</li>
</ul>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.pandas.series">
<code class="descclassname">hypothesis.extra.pandas.</code><code class="descname">series</code><span class="sig-paren">(</span><em>elements=None</em>, <em>dtype=None</em>, <em>index=None</em>, <em>fill=None</em>, <em>unique=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/pandas/impl.html#series"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.pandas.series" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides a strategy for producing a <code class="xref py py-class docutils literal"><span class="pre">pandas.Series</span></code>.</p>
<p>Arguments:</p>
<ul>
<li><p class="first">elements: a strategy that will be used to generate the individual
values in the series. If None, we will attempt to infer a suitable
default from the dtype.</p>
</li>
<li><p class="first">dtype: the dtype of the resulting series and may be any value
that can be passed to <code class="xref py py-class docutils literal"><span class="pre">numpy.dtype</span></code>. If None, will use
pandas’s standard behaviour to infer it from the type of the elements
values. Note that if the type of values that comes out of your
elements strategy varies, then so will the resulting dtype of the
series.</p>
</li>
<li><p class="first">index: If not None, a strategy for generating indexes for the
resulting Series. This can generate either <code class="xref py py-class docutils literal"><span class="pre">pandas.Index</span></code>
objects or any sequence of values (which will be passed to the
Index constructor).</p>
<p>You will probably find it most convenient to use the
<a class="reference internal" href="#hypothesis.extra.pandas.indexes" title="hypothesis.extra.pandas.indexes"><code class="xref py py-func docutils literal"><span class="pre">indexes()</span></code></a> or
<a class="reference internal" href="#hypothesis.extra.pandas.range_indexes" title="hypothesis.extra.pandas.range_indexes"><code class="xref py py-func docutils literal"><span class="pre">range_indexes()</span></code></a> function to produce
values for this argument.</p>
</li>
</ul>
<p>Usage:</p>
<div class="highlight-pycon"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">series</span><span class="p">(</span><span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span><span class="o">.</span><span class="n">example</span><span class="p">()</span>
<span class="go">0 -2001747478</span>
<span class="go">1 1153062837</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="hypothesis.extra.pandas.column">
<em class="property">class </em><code class="descclassname">hypothesis.extra.pandas.</code><code class="descname">column</code><span class="sig-paren">(</span><em>name=None</em>, <em>elements=None</em>, <em>dtype=None</em>, <em>fill=None</em>, <em>unique=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/pandas/impl.html#column"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.pandas.column" title="Permalink to this definition">¶</a></dt>
<dd><p>Data object for describing a column in a DataFrame.</p>
<p>Arguments:</p>
<ul class="simple">
<li>name: the column name, or None to default to the column position. Must
be hashable, but can otherwise be any value supported as a pandas column
name.</li>
<li>elements: the strategy for generating values in this column, or None
to infer it from the dtype.</li>
<li>dtype: the dtype of the column, or None to infer it from the element
strategy. At least one of dtype or elements must be provided.</li>
<li>fill: A default value for elements of the column. See
<a class="reference internal" href="#hypothesis.extra.numpy.arrays" title="hypothesis.extra.numpy.arrays"><code class="xref py py-func docutils literal"><span class="pre">arrays()</span></code></a> for a full explanation.</li>
<li>unique: If all values in this column should be distinct.</li>
</ul>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.pandas.columns">
<code class="descclassname">hypothesis.extra.pandas.</code><code class="descname">columns</code><span class="sig-paren">(</span><em>names_or_number</em>, <em>dtype=None</em>, <em>elements=None</em>, <em>fill=None</em>, <em>unique=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/pandas/impl.html#columns"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.pandas.columns" title="Permalink to this definition">¶</a></dt>
<dd><p>A convenience function for producing a list of <a class="reference internal" href="#hypothesis.extra.pandas.column" title="hypothesis.extra.pandas.column"><code class="xref py py-class docutils literal"><span class="pre">column</span></code></a> objects
of the same general shape.</p>
<p>The names_or_number argument is either a sequence of values, the
elements of which will be used as the name for individual column
objects, or a number, in which case that many unnamed columns will
be created. All other arguments are passed through verbatim to
create the columns.</p>
</dd></dl>
<dl class="function">
<dt id="hypothesis.extra.pandas.data_frames">
<code class="descclassname">hypothesis.extra.pandas.</code><code class="descname">data_frames</code><span class="sig-paren">(</span><em>columns=None</em>, <em>rows=None</em>, <em>index=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/hypothesis/extra/pandas/impl.html#data_frames"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#hypothesis.extra.pandas.data_frames" title="Permalink to this definition">¶</a></dt>
<dd><p>Provides a strategy for producing a <code class="xref py py-class docutils literal"><span class="pre">pandas.DataFrame</span></code>.</p>
<p>Arguments:</p>
<ul>
<li><p class="first">columns: An iterable of <a class="reference internal" href="#hypothesis.extra.pandas.column" title="hypothesis.extra.pandas.column"><code class="xref py py-class docutils literal"><span class="pre">column</span></code></a> objects describing the shape
of the generated DataFrame.</p>
</li>
<li><p class="first">rows: A strategy for generating a row object. Should generate
either dicts mapping column names to values or a sequence mapping
column position to the value in that position (note that unlike the
<code class="xref py py-class docutils literal"><span class="pre">pandas.DataFrame</span></code> constructor, single values are not allowed
here. Passing e.g. an integer is an error, even if there is only one
column).</p>
<p>At least one of rows and columns must be provided. If both are
provided then the generated rows will be validated against the
columns and an error will be raised if they don’t match.</p>
<p>Caveats on using rows:</p>
<ul class="simple">
<li>In general you should prefer using columns to rows, and only use
rows if the columns interface is insufficiently flexible to
describe what you need - you will get better performance and
example quality that way.</li>
<li>If you provide rows and not columns, then the shape and dtype of
the resulting DataFrame may vary. e.g. if you have a mix of int
and float in the values for one column in your row entries, the
column will sometimes have an integral dtype and sometimes a float.</li>
</ul>
</li>
<li><p class="first">index: If not None, a strategy for generating indexes for the
resulting DataFrame. This can generate either <code class="xref py py-class docutils literal"><span class="pre">pandas.Index</span></code>
objects or any sequence of values (which will be passed to the
Index constructor).</p>
<p>You will probably find it most convenient to use the
<a class="reference internal" href="#hypothesis.extra.pandas.indexes" title="hypothesis.extra.pandas.indexes"><code class="xref py py-func docutils literal"><span class="pre">indexes()</span></code></a> or
<a class="reference internal" href="#hypothesis.extra.pandas.range_indexes" title="hypothesis.extra.pandas.range_indexes"><code class="xref py py-func docutils literal"><span class="pre">range_indexes()</span></code></a> function to produce
values for this argument.</p>
</li>
</ul>
<p>Usage:</p>
<p>The expected usage pattern is that you use <a class="reference internal" href="#hypothesis.extra.pandas.column" title="hypothesis.extra.pandas.column"><code class="xref py py-class docutils literal"><span class="pre">column</span></code></a> and
<a class="reference internal" href="#hypothesis.extra.pandas.columns" title="hypothesis.extra.pandas.columns"><code class="xref py py-func docutils literal"><span class="pre">columns()</span></code></a> to specify a fixed shape of the DataFrame you want as
follows. For example the following gives a two column data frame:</p>
<div class="highlight-pycon"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis.extra.pandas</span> <span class="kn">import</span> <span class="n">column</span><span class="p">,</span> <span class="n">data_frames</span>
<span class="gp">>>> </span><span class="n">data_frames</span><span class="p">([</span>
<span class="gp">... </span><span class="n">column</span><span class="p">(</span><span class="s1">'A'</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">),</span> <span class="n">column</span><span class="p">(</span><span class="s1">'B'</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">)])</span><span class="o">.</span><span class="n">example</span><span class="p">()</span>
<span class="go"> A B</span>
<span class="go">0 2021915903 1.793898e+232</span>
<span class="go">1 1146643993 inf</span>
<span class="go">2 -2096165693 1.000000e+07</span>
</pre></div>
</div>
<p>If you want the values in different columns to interact in some way you
can use the rows argument. For example the following gives a two column
DataFrame where the value in the first column is always at most the value
in the second:</p>
<div class="highlight-pycon"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis.extra.pandas</span> <span class="kn">import</span> <span class="n">column</span><span class="p">,</span> <span class="n">data_frames</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">hypothesis.strategies</span> <span class="kn">as</span> <span class="nn">st</span>
<span class="gp">>>> </span><span class="n">data_frames</span><span class="p">(</span>
<span class="gp">... </span> <span class="n">rows</span><span class="o">=</span><span class="n">st</span><span class="o">.</span><span class="n">tuples</span><span class="p">(</span><span class="n">st</span><span class="o">.</span><span class="n">floats</span><span class="p">(</span><span class="n">allow_nan</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">st</span><span class="o">.</span><span class="n">floats</span><span class="p">(</span><span class="n">allow_nan</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="nb">sorted</span><span class="p">)</span>
<span class="gp">... </span><span class="p">)</span><span class="o">.</span><span class="n">example</span><span class="p">()</span>
<span class="go"> 0 1</span>
<span class="go">0 -3.402823e+38 9.007199e+15</span>
<span class="go">1 -1.562796e-298 5.000000e-01</span>
</pre></div>
</div>
<p>You can also combine the two:</p>
<div class="highlight-pycon"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">hypothesis.extra.pandas</span> <span class="kn">import</span> <span class="n">columns</span><span class="p">,</span> <span class="n">data_frames</span>
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">hypothesis.strategies</span> <span class="kn">as</span> <span class="nn">st</span>
<span class="gp">>>> </span><span class="n">data_frames</span><span class="p">(</span>
<span class="gp">... </span> <span class="n">columns</span><span class="o">=</span><span class="n">columns</span><span class="p">([</span><span class="s2">"lo"</span><span class="p">,</span> <span class="s2">"hi"</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">float</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">rows</span><span class="o">=</span><span class="n">st</span><span class="o">.</span><span class="n">tuples</span><span class="p">(</span><span class="n">st</span><span class="o">.</span><span class="n">floats</span><span class="p">(</span><span class="n">allow_nan</span><span class="o">=</span><span class="bp">False</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">st</span><span class="o">.</span><span class="n">floats</span><span class="p">(</span><span class="n">allow_nan</span><span class="o">=</span><span class="bp">False</span><span class="p">))</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="nb">sorted</span><span class="p">)</span>
<span class="gp">... </span><span class="p">)</span><span class="o">.</span><span class="n">example</span><span class="p">()</span>
<span class="go"> lo hi</span>
<span class="go">0 9.314723e-49 4.353037e+45</span>
<span class="go">1 -9.999900e-01 1.000000e+07</span>
<span class="go">2 -2.152861e+134 -1.069317e-73</span>
</pre></div>
</div>
<p>(Note that the column dtype must still be specified and will not be
inferred from the rows. This restriction may be lifted in future).</p>
<p>Combining rows and columns has the following behaviour:</p>
<ul class="simple">
<li>The column names and dtypes will be used.</li>
<li>If the column is required to be unique, this will be enforced.</li>
<li>Any values missing from the generated rows will be provided using the
column’s fill.</li>
<li>Any values in the row not present in the column specification (if
dicts are passed, if there are keys with no corresponding column name,
if sequences are passed if there are too many items) will result in
InvalidArgument being raised.</li>
</ul>
</dd></dl>
<div class="section" id="supported-versions">
<h3>Supported Versions<a class="headerlink" href="#supported-versions" title="Permalink to this headline">¶</a></h3>
<p>There is quite a lot of variation between pandas versions. We only
commit to supporting the latest version of pandas, but older minor versions are
supported on a “best effort” basis. Hypothesis is currently tested against
and confirmed working with Pandas 0.19, 0.20, and 0.21.</p>
<p>Releases that are not the latest patch release of their minor version are not
tested or officially supported, but will probably also work unless you hit a
pandas bug.</p>
</div>
</div>
</div>
</div>
<div class="articleComments">
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="healthchecks.html" class="btn btn-neutral float-right" title="Health checks" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="django.html" class="btn btn-neutral" title="Hypothesis for Django users" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2013-2018, David R. MacIver.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'3.44.1',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
|