Skip to content

Commit

Permalink
fixed a whole bunch of doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Ivanov committed Dec 28, 2009
1 parent 5ba0199 commit e4f233e
Show file tree
Hide file tree
Showing 35 changed files with 363 additions and 185 deletions.
4 changes: 4 additions & 0 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
Code snippets are indicated by three greater-than signs::
>>> x = 42
>>> x = x + 1
Use the built-in ``help`` function to view a function's docstring::
>>> help(np.sort)
... # doctest: +SKIP
For some objects, ``np.info(obj)`` may provide additional help. This is
particularly true if you see the line "Help on ufunc object:" at the top
Expand All @@ -39,12 +41,14 @@
To search for documents containing a keyword, do::
>>> np.lookfor('keyword')
... # doctest: +SKIP
General-purpose documents like a glossary and help on the basic concepts
of numpy are available under the ``doc`` sub-module::
>>> from numpy import doc
>>> help(doc)
... # doctest: +SKIP
Available subpackages
---------------------
Expand Down
10 changes: 5 additions & 5 deletions numpy/add_newdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,12 @@
Examples
--------
>>> np.empty([2, 2])
array([[ -9.74499359e+001, 6.69583040e-309], #random data
[ 2.13182611e-314, 3.06959433e-309]])
array([[ -9.74499359e+001, 6.69583040e-309],
[ 2.13182611e-314, 3.06959433e-309]]) #random
>>> np.empty([2, 2], dtype=int)
array([[-1073741821, -1067949133], #random data
[ 496041986, 19249760]])
array([[-1073741821, -1067949133],
[ 496041986, 19249760]]) #random
""")

Expand Down Expand Up @@ -1516,7 +1516,7 @@
>>> np.ndarray(shape=(2,2), dtype=float, order='F')
array([[ -1.13698227e+002, 4.25087011e-303],
[ 2.88528414e-306, 3.27025015e-309]])
[ 2.88528414e-306, 3.27025015e-309]]) #random
Second mode:
Expand Down
5 changes: 5 additions & 0 deletions numpy/core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None,
>>> x**2 - (x + eps)**2
array([-0., -0., 0., 0.])
To put back the default options, you can use:
>>> np.set_printoptions(edgeitems=3,infstr='Inf',
... linewidth=75, nanstr='NaN', precision=8,
... suppress=False, threshold=1000)
"""

global _summaryThreshold, _summaryEdgeItems, _float_output_precision, \
Expand Down
36 changes: 19 additions & 17 deletions numpy/core/defchararray.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def count(a, sub, start=0, end=None):
--------
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
>>> c
array(['aAaAaA', ' aA', 'abBABba'],
array(['aAaAaA', ' aA ', 'abBABba'],
dtype='|S7')
>>> np.char.count(c, 'A')
array([3, 1, 1])
Expand Down Expand Up @@ -505,7 +505,7 @@ def decode(a, encoding=None, errors=None):
--------
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
>>> c
array(['aAaAaA', ' aA', 'abBABba'],
array(['aAaAaA', ' aA ', 'abBABba'],
dtype='|S7')
>>> np.char.encode(c, encoding='cp037')
array(['\\x81\\xc1\\x81\\xc1\\x81\\xc1', '@@\\x81\\xc1@@',
Expand Down Expand Up @@ -584,9 +584,9 @@ def endswith(a, suffix, start=0, end=None):
>>> s
array(['foo', 'bar'],
dtype='|S3')
>>> np.charendswith(s, 'ar')
>>> np.char.endswith(s, 'ar')
array([False, True], dtype=bool)
>>> s.endswith(s, 'a', start=1, end=2)
>>> np.char.endswith(s, 'a', start=1, end=2)
array([False, True], dtype=bool)
"""
Expand Down Expand Up @@ -1010,15 +1010,17 @@ def lstrip(a, chars=None):
--------
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
>>> c
array(['aAaAaA', ' aA', 'abBABba'],
array(['aAaAaA', ' aA ', 'abBABba'],
dtype='|S7')
>>> np.char.lstrip(c, 'a') # 'a' unstripped from c[1] because whitespace leading
array(['AaAaA', ' aA', 'bBABba'],
dtype='|S6')
array(['AaAaA', ' aA ', 'bBABba'],
dtype='|S7')
>>> np.char.lstrip(c, 'A') # leaves c unchanged
array(['aAaAaA', ' aA', 'abBABba'],
array(['aAaAaA', ' aA ', 'abBABba'],
dtype='|S7')
>>> (np.char.lstrip(c, ' ') == np.char.lstrip(c, '')).all()
... # XXX: is this a regression? this line now returns False
... # np.char.lstrip(c,'') does not modify c at all.
True
>>> (np.char.lstrip(c, ' ') == np.char.lstrip(c, None)).all()
True
Expand Down Expand Up @@ -1313,7 +1315,7 @@ def rstrip(a, chars=None):
dtype='|S7')
>>> np.char.rstrip(c, 'a')
array(['aAaAaA', 'abBABb'],
dtype='|S6')
dtype='|S7')
>>> np.char.rstrip(c, 'A')
array(['aAaAa', 'abBABba'],
dtype='|S7')
Expand Down Expand Up @@ -1444,16 +1446,16 @@ def strip(a, chars=None):
--------
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
>>> c
array(['aAaAaA', ' aA', 'abBABba'],
array(['aAaAaA', ' aA ', 'abBABba'],
dtype='|S7')
>>> np.char.strip(c)
array(['aAaAaA', 'aA', 'abBABba'],
dtype='|S7')
>>> np.char.strip(c, 'a') # 'a' unstripped from c[1] because whitespace leads
array(['AaAaA', ' aA', 'bBABb'],
dtype='|S6')
array(['AaAaA', ' aA ', 'bBABb'],
dtype='|S7')
>>> np.char.strip(c, 'A') # 'A' unstripped from c[1] because (unprinted) ws trails
array(['aAaAa', ' aA', 'abBABba'],
array(['aAaAa', ' aA ', 'abBABba'],
dtype='|S7')
"""
Expand Down Expand Up @@ -1523,7 +1525,7 @@ def title(a):
array(['a1b c', '1b ca', 'b ca1', 'ca1b'],
dtype='|S5')
>>> np.char.title(c)
chararray(['A1B C', '1B Ca', 'B Ca1', 'Ca1B'],
array(['A1B C', '1B Ca', 'B Ca1', 'Ca1B'],
dtype='|S5')
"""
a_arr = numpy.asarray(a)
Expand Down Expand Up @@ -1590,7 +1592,7 @@ def upper(a):
>>> c = np.array(['a1b c', '1bca', 'bca1']); c
array(['a1b c', '1bca', 'bca1'],
dtype='|S5')
>>> numpy.char.upper(c)
>>> np.char.upper(c)
array(['A1B C', '1BCA', 'BCA1'],
dtype='|S5')
"""
Expand Down Expand Up @@ -1742,15 +1744,15 @@ class adds the following functionality:
Examples
--------
>>> charar = np.chararray((3, 3))
>>> charar[:, :] = 'abc'
>>> charar[:] = 'a'
>>> charar
chararray([['a', 'a', 'a'],
['a', 'a', 'a'],
['a', 'a', 'a']],
dtype='|S1')
>>> charar = np.chararray(charar.shape, itemsize=5)
>>> charar[:, :] = 'abc'
>>> charar[:] = 'abc'
>>> charar
chararray([['abc', 'abc', 'abc'],
['abc', 'abc', 'abc'],
Expand Down
7 changes: 4 additions & 3 deletions numpy/core/fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,9 @@ def clip(a, a_min, a_max, out=None):
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.clip(a, 3, 6, out=a)
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a = np.arange(10)
>>> a
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.clip(a, [3,4,1,1,1,4,4,4,4,4], 8)
array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])
Expand Down Expand Up @@ -1500,7 +1501,7 @@ def any(a,axis=None, out=None):
>>> # Check now that z is a reference to o
>>> z is o
True
>>> id(z), id(o) # identity of z and o
>>> id(z), id(o) # identity of z and o # doctest: +SKIP
(191614240, 191614240)
"""
Expand Down Expand Up @@ -1563,7 +1564,7 @@ def all(a,axis=None, out=None):
>>> o=np.array([False])
>>> z=np.all([-1, 4, 5], out=o)
>>> id(z), id(o), z
>>> id(z), id(o), z # doctest: +SKIP
(28293632, 28293632, array([ True], dtype=bool))
"""
Expand Down
10 changes: 9 additions & 1 deletion numpy/core/function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False):
>>> x1 = np.linspace(0, 10, N, endpoint=True)
>>> x2 = np.linspace(0, 10, N, endpoint=False)
>>> plt.plot(x1, y, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.plot(x2, y + 0.5, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.ylim([-0.5, 1])
(-0.5, 1)
>>> plt.show()
"""
Expand Down Expand Up @@ -129,8 +132,10 @@ def logspace(start,stop,num=50,endpoint=True,base=10.0):
-----
Logspace is equivalent to the code
>>> y = linspace(start, stop, num=num, endpoint=endpoint)
>>> y = np.linspace(start, stop, num=num, endpoint=endpoint)
... # doctest: +SKIP
>>> power(base, y)
... # doctest: +SKIP
Examples
--------
Expand All @@ -149,8 +154,11 @@ def logspace(start,stop,num=50,endpoint=True,base=10.0):
>>> x2 = np.logspace(0.1, 1, N, endpoint=False)
>>> y = np.zeros(N)
>>> plt.plot(x1, y, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.plot(x2, y + 0.5, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.ylim([-0.5, 1])
(-0.5, 1)
>>> plt.show()
"""
Expand Down
Loading

0 comments on commit e4f233e

Please sign in to comment.