[Scipy-svn] r6382 - in trunk/scipy: io/matlab misc misc/tests ndimage ndimage/tests stats
scipy-svn at scipy.org
scipy-svn at scipy.org
Sat May 8 04:46:05 EDT 2010
Author: rgommers
Date: 2010-05-08 03:46:05 -0500 (Sat, 08 May 2010)
New Revision: 6382
Added:
trunk/scipy/misc/doccer.py
trunk/scipy/misc/tests/test_doccer.py
Removed:
trunk/scipy/ndimage/doccer.py
trunk/scipy/ndimage/tests/test_doccer.py
Modified:
trunk/scipy/io/matlab/miobase.py
trunk/scipy/ndimage/__init__.py
trunk/scipy/ndimage/filters.py
trunk/scipy/stats/distributions.py
Log:
Move ndimage.doccer to misc.doccer. Reason: stats should not depend on ndimage
Modified: trunk/scipy/io/matlab/miobase.py
===================================================================
--- trunk/scipy/io/matlab/miobase.py 2010-05-08 08:45:39 UTC (rev 6381)
+++ trunk/scipy/io/matlab/miobase.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -5,7 +5,7 @@
"""
import numpy as np
-from scipy.ndimage import doccer
+from scipy.misc import doccer
import byteordercodes as boc
@@ -139,7 +139,7 @@
dtypes : mapping
mapping where values have been replaced by
``np.dtype(val).newbyteorder(order_code)``
-
+
'''
dtypes = dtype_template.copy()
for k in dtypes:
@@ -221,8 +221,8 @@
def matdims(arr, oned_as='column'):
- ''' Determine equivalent matlab dimensions for given array
-
+ ''' Determine equivalent matlab dimensions for given array
+
Parameters
----------
arr : ndarray
@@ -377,7 +377,7 @@
self.mat_stream.seek(curpos-1)
return len(b) == 0
-
+
def arr_dtype_number(arr, num):
''' Return dtype for given number of items per element'''
return np.dtype(arr.dtype.str[:2] + str(num))
Copied: trunk/scipy/misc/doccer.py (from rev 6381, trunk/scipy/ndimage/doccer.py)
===================================================================
--- trunk/scipy/misc/doccer.py (rev 0)
+++ trunk/scipy/misc/doccer.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -0,0 +1,135 @@
+''' Utilities to allow inserting docstring fragments for common
+parameters into function and method docstrings'''
+
+import sys
+
+def docformat(docstring, docdict=None):
+ ''' Fill a function docstring from variables in dictionary
+
+ Adapt the indent of the inserted docs
+
+ Parameters
+ ----------
+ docstring : string
+ docstring from function, possibly with dict formatting strings
+ docdict : dict
+ dictionary with keys that match the dict formatting strings
+ and values that are docstring fragments to be inserted. The
+ indentation of the inserted docstrings is set to match the
+ minimum indentation of the ``docstring`` by adding this
+ indentation to all lines of the inserted string, except the
+ first
+
+ Returns
+ -------
+ outstring : string
+ string with requested ``docdict`` strings inserted
+
+ Examples
+ --------
+ >>> docformat(' Test string with %(value)s', {'value':'inserted value'})
+ ' Test string with inserted value'
+ >>> docstring = 'First line\\n Second line\\n %(value)s'
+ >>> inserted_string = "indented\\nstring"
+ >>> docdict = {'value': inserted_string}
+ >>> docformat(docstring, docdict)
+ 'First line\\n Second line\\n indented\\n string'
+ '''
+ if not docstring:
+ return docstring
+ if docdict is None:
+ docdict = {}
+ if not docdict:
+ return docstring
+ lines = docstring.expandtabs().splitlines()
+ # Find the minimum indent of the main docstring, after first line
+ if len(lines) < 2:
+ icount = 0
+ else:
+ icount = indentcount_lines(lines[1:])
+ indent = ' ' * icount
+ # Insert this indent to dictionary docstrings
+ indented = {}
+ for name, dstr in docdict.items():
+ lines = dstr.expandtabs().splitlines()
+ try:
+ newlines = [lines[0]]
+ for line in lines[1:]:
+ newlines.append(indent+line)
+ indented[name] = '\n'.join(newlines)
+ except IndexError:
+ indented[name] = dstr
+ return docstring % indented
+
+
+def indentcount_lines(lines):
+ ''' Minumum indent for all lines in line list
+
+ >>> lines = [' one', ' two', ' three']
+ >>> indentcount_lines(lines)
+ 1
+ >>> lines = []
+ >>> indentcount_lines(lines)
+ 0
+ >>> lines = [' one']
+ >>> indentcount_lines(lines)
+ 1
+ >>> indentcount_lines([' '])
+ 0
+ '''
+ indentno = sys.maxint
+ for line in lines:
+ stripped = line.lstrip()
+ if stripped:
+ indentno = min(indentno, len(line) - len(stripped))
+ if indentno == sys.maxint:
+ return 0
+ return indentno
+
+
+def filldoc(docdict, unindent_params=True):
+ ''' Return docstring decorator using docdict variable dictionary
+
+ Parameters
+ ----------
+ docdict : dictionary
+ dictionary containing name, docstring fragment pairs
+ unindent_params : {False, True}, boolean, optional
+ If True, strip common indentation from all parameters in
+ docdict
+
+ Returns
+ -------
+ decfunc : function
+ decorator that applies dictionary to input function docstring
+
+ '''
+ if unindent_params:
+ docdict = unindent_dict(docdict)
+ def decorate(f):
+ f.__doc__ = docformat(f.__doc__, docdict)
+ return f
+ return decorate
+
+
+def unindent_dict(docdict):
+ ''' Unindent all strings in a docdict '''
+ can_dict = {}
+ for name, dstr in docdict.items():
+ can_dict[name] = unindent_string(dstr)
+ return can_dict
+
+
+def unindent_string(docstring):
+ ''' Set docstring to minimum indent for all lines, including first
+
+ >>> unindent_string(' two')
+ 'two'
+ >>> unindent_string(' two\\n three')
+ 'two\\n three'
+ '''
+ lines = docstring.expandtabs().splitlines()
+ icount = indentcount_lines(lines)
+ if icount == 0:
+ return docstring
+ return '\n'.join([line[icount:] for line in lines])
Copied: trunk/scipy/misc/tests/test_doccer.py (from rev 6381, trunk/scipy/ndimage/tests/test_doccer.py)
===================================================================
--- trunk/scipy/misc/tests/test_doccer.py (rev 0)
+++ trunk/scipy/misc/tests/test_doccer.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -0,0 +1,89 @@
+''' Some tests for the documenting decorator and support functions '''
+
+import numpy as np
+
+from numpy.testing import assert_equal, assert_raises
+
+from nose.tools import assert_true
+
+from scipy.misc import doccer
+
+docstring = \
+"""Docstring
+ %(strtest1)s
+ %(strtest2)s
+ %(strtest3)s
+"""
+param_doc1 = \
+"""Another test
+ with some indent"""
+
+param_doc2 = \
+"""Another test, one line"""
+
+param_doc3 = \
+""" Another test
+ with some indent"""
+
+doc_dict = {'strtest1':param_doc1,
+ 'strtest2':param_doc2,
+ 'strtest3':param_doc3}
+
+filled_docstring = \
+"""Docstring
+ Another test
+ with some indent
+ Another test, one line
+ Another test
+ with some indent
+"""
+
+
+def test_unindent():
+ yield assert_equal, doccer.unindent_string(param_doc1), param_doc1
+ yield assert_equal, doccer.unindent_string(param_doc2), param_doc2
+ yield assert_equal, doccer.unindent_string(param_doc3), param_doc1
+
+
+def test_unindent_dict():
+ d2 = doccer.unindent_dict(doc_dict)
+ yield assert_equal, d2['strtest1'], doc_dict['strtest1']
+ yield assert_equal, d2['strtest2'], doc_dict['strtest2']
+ yield assert_equal, d2['strtest3'], doc_dict['strtest1']
+
+
+def test_docformat():
+ udd = doccer.unindent_dict(doc_dict)
+ formatted = doccer.docformat(docstring, udd)
+ yield assert_equal, formatted, filled_docstring
+ single_doc = 'Single line doc %(strtest1)s'
+ formatted = doccer.docformat(single_doc, doc_dict)
+ # Note - initial indent of format string does not
+ # affect subsequent indent of inserted parameter
+ yield assert_equal, formatted, """Single line doc Another test
+ with some indent"""
+
+
+def test_decorator():
+ # with unindentation of parameters
+ decorator = doccer.filldoc(doc_dict, True)
+ @decorator
+ def func():
+ """ Docstring
+ %(strtest3)s
+ """
+ yield assert_equal, func.__doc__, """ Docstring
+ Another test
+ with some indent
+ """
+ # without unindentation of parameters
+ decorator = doccer.filldoc(doc_dict, False)
+ @decorator
+ def func():
+ """ Docstring
+ %(strtest3)s
+ """
+ yield assert_equal, func.__doc__, """ Docstring
+ Another test
+ with some indent
+ """
Modified: trunk/scipy/ndimage/__init__.py
===================================================================
--- trunk/scipy/ndimage/__init__.py 2010-05-08 08:45:39 UTC (rev 6381)
+++ trunk/scipy/ndimage/__init__.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -36,6 +36,11 @@
from morphology import *
from io import *
+# doccer is moved to scipy.misc in scipy 0.8
+from scipy.misc import doccer
+doccer = numpy.deprecate(doccer, old_name='doccer',
+ new_name='scipy.misc.doccer')
+
from info import __doc__
__version__ = '2.0'
Deleted: trunk/scipy/ndimage/doccer.py
===================================================================
--- trunk/scipy/ndimage/doccer.py 2010-05-08 08:45:39 UTC (rev 6381)
+++ trunk/scipy/ndimage/doccer.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -1,135 +0,0 @@
-''' Utilities to allow inserting docstring fragments for common
-parameters into function and method docstrings'''
-
-import sys
-
-def docformat(docstring, docdict=None):
- ''' Fill a function docstring from variables in dictionary
-
- Adapt the indent of the inserted docs
-
- Parameters
- ----------
- docstring : string
- docstring from function, possibly with dict formatting strings
- docdict : dict
- dictionary with keys that match the dict formatting strings
- and values that are docstring fragments to be inserted. The
- indentation of the inserted docstrings is set to match the
- minimum indentation of the ``docstring`` by adding this
- indentation to all lines of the inserted string, except the
- first
-
- Returns
- -------
- outstring : string
- string with requested ``docdict`` strings inserted
-
- Examples
- --------
- >>> docformat(' Test string with %(value)s', {'value':'inserted value'})
- ' Test string with inserted value'
- >>> docstring = 'First line\\n Second line\\n %(value)s'
- >>> inserted_string = "indented\\nstring"
- >>> docdict = {'value': inserted_string}
- >>> docformat(docstring, docdict)
- 'First line\\n Second line\\n indented\\n string'
- '''
- if not docstring:
- return docstring
- if docdict is None:
- docdict = {}
- if not docdict:
- return docstring
- lines = docstring.expandtabs().splitlines()
- # Find the minimum indent of the main docstring, after first line
- if len(lines) < 2:
- icount = 0
- else:
- icount = indentcount_lines(lines[1:])
- indent = ' ' * icount
- # Insert this indent to dictionary docstrings
- indented = {}
- for name, dstr in docdict.items():
- lines = dstr.expandtabs().splitlines()
- try:
- newlines = [lines[0]]
- for line in lines[1:]:
- newlines.append(indent+line)
- indented[name] = '\n'.join(newlines)
- except IndexError:
- indented[name] = dstr
- return docstring % indented
-
-
-def indentcount_lines(lines):
- ''' Minumum indent for all lines in line list
-
- >>> lines = [' one', ' two', ' three']
- >>> indentcount_lines(lines)
- 1
- >>> lines = []
- >>> indentcount_lines(lines)
- 0
- >>> lines = [' one']
- >>> indentcount_lines(lines)
- 1
- >>> indentcount_lines([' '])
- 0
- '''
- indentno = sys.maxint
- for line in lines:
- stripped = line.lstrip()
- if stripped:
- indentno = min(indentno, len(line) - len(stripped))
- if indentno == sys.maxint:
- return 0
- return indentno
-
-
-def filldoc(docdict, unindent_params=True):
- ''' Return docstring decorator using docdict variable dictionary
-
- Parameters
- ----------
- docdict : dictionary
- dictionary containing name, docstring fragment pairs
- unindent_params : {False, True}, boolean, optional
- If True, strip common indentation from all parameters in
- docdict
-
- Returns
- -------
- decfunc : function
- decorator that applies dictionary to input function docstring
-
- '''
- if unindent_params:
- docdict = unindent_dict(docdict)
- def decorate(f):
- f.__doc__ = docformat(f.__doc__, docdict)
- return f
- return decorate
-
-
-def unindent_dict(docdict):
- ''' Unindent all strings in a docdict '''
- can_dict = {}
- for name, dstr in docdict.items():
- can_dict[name] = unindent_string(dstr)
- return can_dict
-
-
-def unindent_string(docstring):
- ''' Set docstring to minimum indent for all lines, including first
-
- >>> unindent_string(' two')
- 'two'
- >>> unindent_string(' two\\n three')
- 'two\\n three'
- '''
- lines = docstring.expandtabs().splitlines()
- icount = indentcount_lines(lines)
- if icount == 0:
- return docstring
- return '\n'.join([line[icount:] for line in lines])
Modified: trunk/scipy/ndimage/filters.py
===================================================================
--- trunk/scipy/ndimage/filters.py 2010-05-08 08:45:39 UTC (rev 6381)
+++ trunk/scipy/ndimage/filters.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -32,7 +32,7 @@
import numpy
import _ni_support
import _nd_image
-import doccer
+from scipy.misc import doccer
_input_doc = \
"""input : array-like
Deleted: trunk/scipy/ndimage/tests/test_doccer.py
===================================================================
--- trunk/scipy/ndimage/tests/test_doccer.py 2010-05-08 08:45:39 UTC (rev 6381)
+++ trunk/scipy/ndimage/tests/test_doccer.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -1,89 +0,0 @@
-''' Some tests for the documenting decorator and support functions '''
-
-import numpy as np
-
-from numpy.testing import assert_equal, assert_raises
-
-from nose.tools import assert_true
-
-import scipy.ndimage.doccer as sndd
-
-docstring = \
-"""Docstring
- %(strtest1)s
- %(strtest2)s
- %(strtest3)s
-"""
-param_doc1 = \
-"""Another test
- with some indent"""
-
-param_doc2 = \
-"""Another test, one line"""
-
-param_doc3 = \
-""" Another test
- with some indent"""
-
-doc_dict = {'strtest1':param_doc1,
- 'strtest2':param_doc2,
- 'strtest3':param_doc3}
-
-filled_docstring = \
-"""Docstring
- Another test
- with some indent
- Another test, one line
- Another test
- with some indent
-"""
-
-
-def test_unindent():
- yield assert_equal, sndd.unindent_string(param_doc1), param_doc1
- yield assert_equal, sndd.unindent_string(param_doc2), param_doc2
- yield assert_equal, sndd.unindent_string(param_doc3), param_doc1
-
-
-def test_unindent_dict():
- d2 = sndd.unindent_dict(doc_dict)
- yield assert_equal, d2['strtest1'], doc_dict['strtest1']
- yield assert_equal, d2['strtest2'], doc_dict['strtest2']
- yield assert_equal, d2['strtest3'], doc_dict['strtest1']
-
-
-def test_docformat():
- udd = sndd.unindent_dict(doc_dict)
- formatted = sndd.docformat(docstring, udd)
- yield assert_equal, formatted, filled_docstring
- single_doc = 'Single line doc %(strtest1)s'
- formatted = sndd.docformat(single_doc, doc_dict)
- # Note - initial indent of format string does not
- # affect subsequent indent of inserted parameter
- yield assert_equal, formatted, """Single line doc Another test
- with some indent"""
-
-
-def test_decorator():
- # with unindentation of parameters
- decorator = sndd.filldoc(doc_dict, True)
- @decorator
- def func():
- """ Docstring
- %(strtest3)s
- """
- yield assert_equal, func.__doc__, """ Docstring
- Another test
- with some indent
- """
- # without unindentation of parameters
- decorator = sndd.filldoc(doc_dict, False)
- @decorator
- def func():
- """ Docstring
- %(strtest3)s
- """
- yield assert_equal, func.__doc__, """ Docstring
- Another test
- with some indent
- """
Modified: trunk/scipy/stats/distributions.py
===================================================================
--- trunk/scipy/stats/distributions.py 2010-05-08 08:45:39 UTC (rev 6381)
+++ trunk/scipy/stats/distributions.py 2010-05-08 08:46:05 UTC (rev 6382)
@@ -62,7 +62,7 @@
import types
import stats as st
-from scipy.ndimage import doccer
+from scipy.misc import doccer
all = alltrue
sgf = vectorize
@@ -4990,7 +4990,7 @@
1-ncx2.cdf(2*mu1, 2*(x+1), 2*mu2))
return px
-# enable later
+# enable later
## def _cf(self, w, mu1, mu2):
## # characteristic function
## poisscf = poisson._cf
@@ -5020,6 +5020,6 @@
Parameters mu1 and mu2 must be strictly positive.
For details see: http://en.wikipedia.org/wiki/Skellam_distribution
-
+
"""
)
More information about the Scipy-svn
mailing list