Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Cannot have test within function name #1003

Closed
mortonjt opened this issue Jun 21, 2016 · 3 comments
Closed

ERROR: Cannot have test within function name #1003

mortonjt opened this issue Jun 21, 2016 · 3 comments

Comments

@mortonjt
Copy link

I have written up a bunch of tests. The tests pass just fine if I run the following

python test_permutation.py

Now if I were to run nosetests as follows

nosetests .

I get the following error

======================================================================
ERROR: Conducts a fishers test on a contingency table.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mortonjt/miniconda3/envs/canvas/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Users/mortonjt/miniconda3/envs/canvas/lib/python2.7/site-packages/nose/util.py", line 620, in newfunc
    return func(*arg, **kw)
TypeError: fisher_mean_test() takes at least 2 arguments (0 given)

----------------------------------------------------------------------

Now the function that I'm trying to test is under permutation.py, the function signature+docstring is as follows

def fisher_mean_test(table, grouping, permutations=1000, random_state=None):
    """ Conducts a fishers test on a contingency table.

    This module will conduct a mean permutation test using
    numpy matrix algebra.

    table: pd.DataFrame
        Contingency table of where columns correspond to features
        and rows correspond to samples.
    grouping : pd.Series
        Vector indicating the assignment of samples to groups.  For example,
        these could be strings or integers denoting which group a sample
        belongs to.  It must be the same length as the samples in `table`.
        The index must be the same on `table` and `grouping` but need not be
        in the same order.
    permutations: int
         Number of permutations to calculate
    random_state : int or RandomState, optional
        Pseudo number generator state used for random sampling.

    Return
    ------
    pd.DataFrame
        A table of features, their t-statistics and p-values
        `"m"` is the t-statistic.
        `"pvalue"` is the p-value calculated from the permutation test.

    Examples
    --------
    >>> from canvas.stats.permutation import fisher_mean
    >>> import pandas as pd
    >>> table = pd.DataFrame([[12, 11, 10, 10, 10, 10, 10],
    ...                       [9,  11, 12, 10, 10, 10, 10],
    ...                       [1,  11, 10, 11, 10, 5,  9],
    ...                       [22, 21, 9,  10, 10, 10, 10],
    ...                       [20, 22, 10, 10, 13, 10, 10],
    ...                       [23, 21, 14, 10, 10, 10, 10]],
    ...                      index=['s1','s2','s3','s4','s5','s6'],
    ...                      columns=['b1','b2','b3','b4','b5','b6','b7'])
    >>> grouping = pd.Series([0, 0, 0, 1, 1, 1],
    ...                      index=['s1','s2','s3','s4','s5','s6'])
    >>> results = fisher_mean(table, grouping,
    ...                       permutations=100, random_state=0)
    >>> results
                m    pvalue
    b1  14.333333  0.108910
    b2  10.333333  0.108910
    b3   0.333333  1.000000
    b4   0.333333  1.000000
    b5   1.000000  1.000000
    b6   1.666667  0.108910
    b7   0.333333  1.000000

    Notes
    -----
    Only works on binary classes.
    """

It took me a few hours to realize that nosetest was treating this function as a unittest, and was trying to execute it. Just because the word test is inside the function name. The nosetests worked when I renamed the function the fisher_mean

I'm not sure what the best way around this problem is, but it took a while to hunt down this problem and it would be nice to at least document this issue.

@jszakmeister
Copy link
Contributor

It is documented: http://nose.readthedocs.io/en/latest/writing_tests.html#writing-tests

You can use the @nottest decorator to mark it as not being a test, if you want to keep the old name:

from nose.tools import *

@nottest
def fisher_mean_test(table, grouping, permutations=1000, random_state=None):
    # ...

@mortonjt
Copy link
Author

Thanks!

On Tue, Jun 21, 2016 at 12:21 PM, John Szakmeister <notifications@github.com

wrote:

It is documented:
http://nose.readthedocs.io/en/latest/writing_tests.html#writing-tests

You can use the @nottest decorator to mark it as not being a test, if you
want to keep the old name:

from nose.tools import *
@nottestdef fisher_mean_test(table, grouping, permutations=1000, random_state=None):
# ...


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#1003 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AD_a3Y4UyYtUcKvPV_axVcMJOOc1TlFRks5qODnKgaJpZM4I7DaE
.

@eggachecat
Copy link

@mortonjt @jszakmeister you saved my life!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants