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

BUG: deprecation for ignored corrcoef args #5683

Merged
merged 2 commits into from
Mar 21, 2015

Conversation

matthew-brett
Copy link
Contributor

The ddof and bias arguments to corrcoef cancel in the math of the
correlation coefficient, so there is no point in passing these values, and it
is confusing to the user to see these in the docstring.

Remove, deprecate, and test.

When the bias argument goes away, we will need to make the
allow_masked argument to ma.corrcoef into a keyword-only argument; warn
about this change.

@charris
Copy link
Member

charris commented Mar 15, 2015

This also needs a note iin doc/release/1.10.0-notes.rst under Deprecations.

@charris
Copy link
Member

charris commented Mar 15, 2015

Tests are failing ERROR: Failure: ImportError (No module named warnutils).

@matthew-brett
Copy link
Contributor Author

Oops - should be fixed now.

@charris
Copy link
Member

charris commented Mar 15, 2015

I think we can simplify this further if we add a NoValue class to numpy/__init__.py. Something like

class NoValue(object):
    """Special keyword value.

    This class may be used as the default value assigned to a
    deprecated keyword in order to check if it has been given a user
    defined value.

    """
    pass

Then it can be used as the default value of bias and ddof and checked like so

if bias is not NoValue:
    <warning>

The argument count is then handled by python itself.

@matthew-brett
Copy link
Contributor Author

Right - sort of like _DefaultArg. I went for the args, kwargs things in part to remove bias and ddof from the function signature, but perhaps it isn't worth the hassle.

@charris
Copy link
Member

charris commented Mar 15, 2015

And then perhaps a single warning message, maybe bias and ddof have no affect and are deprecated.

@matthew-brett
Copy link
Contributor Author

Do we really want NoValue in the top-level numpy namespace?

@matthew-brett
Copy link
Contributor Author

Also - that won't work for deprecating allow_masked as a positional argument - I don't think.

@matthew-brett
Copy link
Contributor Author

I implemented your suggestion - do you like how it looks?

@charris
Copy link
Member

charris commented Mar 15, 2015

Yeah, it won't work for positional arguments. The ma.corrcoef looks OK, though.

ma.corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None)

We won't be able to remove the arguments anytime soon ;) But using *arg and **kwargs doesn't remove the arguments either, it just makes them harder to find.

@matthew-brett
Copy link
Contributor Author

Current version OK with you then?

defined value.
"""
pass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two blank lines ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not export this publicly? Just call it _NoValue or something? We
have enough public clutter as it is, and this adds zero value.
On Mar 14, 2015 9:15 PM, "Charles Harris" notifications@github.com wrote:

In numpy/init.py
#5683 (comment):

@@ -132,6 +132,15 @@ class VisibleDeprecationWarning(UserWarning):
pass

+class NoValue:

  • """Special keyword value.
  • This class may be used as the default value assigned to a
  • deprecated keyword in order to check if it has been given a user
  • defined value.
  • """
  • pass

Two blank lines ;)


Reply to this email directly or view it on GitHub
https://github.com/numpy/numpy/pull/5683/files#r26444409.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess it doesn't need to be public, so _NoValue would work.

@@ -1975,28 +1975,27 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None):
variable, with observations in the columns. Otherwise, the relationship
is transposed: each column represents a variable, while the rows
contain observations.
bias : int, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably keep the documentation for both of these, but just say they have no affect and are deprecated. Like so

    bias :
        .. deprecated:: 1.10.0
        Has no affect, not used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make that

    bias : NoValue, optional
        .. deprecated:: 1.10.0
        Has no affect, do not use.

@charris
Copy link
Member

charris commented Mar 15, 2015

Almost there I think.

@matthew-brett
Copy link
Contributor Author

Can I leave it to you guys to decide on NoValue vs _NoValue?

@charris
Copy link
Member

charris commented Mar 15, 2015

Yes. @rgommers Probably need a third opinion for that.

@njsmith
Copy link
Member

njsmith commented Mar 15, 2015

There's just zero reason to expose it: the requirements are that it be a
value which (a) we can check for, (b) users won't pass in. Being public is
irrelevant to (a), and actually bad for (b). And it's an implementation
detail anyway.
On Mar 14, 2015 9:54 PM, "Charles Harris" notifications@github.com wrote:

Yes. @rgommers https://github.com/rgommers Probably need a third
opinion for that.


Reply to this email directly or view it on GitHub
#5683 (comment).

@charris
Copy link
Member

charris commented Mar 15, 2015

NVM, I think using _NoValue is the way to go.

@matthew-brett
Copy link
Contributor Author

Do you agree we need args, kwargs in ma.corrcoef for checking for positional argument to allow_masked? If so, I'll rebase ready for merge.

@charris
Copy link
Member

charris commented Mar 15, 2015

@matthew-brett I don't see why they are needed, all you need to know is if the argument is used. If allow_masked is used as a positional argument, it needs to be preceded by a positional value for bias and you will detect that. What is your thinking?

@matthew-brett
Copy link
Contributor Author

I believe we need to

a) give two warnings when bias and allow_masked get used as positional arguments together and
b) give a new warning about allow_masked if the user first calls corrcoef with bias (and gets a warning) and then calls corrcoef with bias AND allow_masked.

Did I miss how that can be done without using args, kwargs?

@charris
Copy link
Member

charris commented Mar 15, 2015

The way I see it is that the user will always get a warning if they use bias or ddof in any fashion, positional or otherwise. If they use bias as a keyword argument, no positional arguments can follow. If they use bias as a positional argument, they will need to use allow_masked as a keyward argument to remove the bias value and avoid the warning. In both cases the fix will be to use allow_masked as a keyword argument, which is what we want. Could add a note to docstring that the remaining arguments should all be treated as keyword arguments. Current practice in numpy/scipy is to avoid using *args and **kwargs, so there is also that.

I need to head off to bed now. To be continued tomorrow...

@matthew-brett
Copy link
Contributor Author

OK - you are saying that the user will in any case infer that allow_masked should be keyword only. Or, put another way, the only way to make the warnings go away is to use allow_masked as a keyword.

I don't feel strongly, happy to make the change. I currently test for the warnings in situations a, b above, but I can remove those tests.

the number of observations; this overrides the value implied by
``bias``. The default value is ``None``.
If False, raises an exception. Note: as of numpy 1.10 this argument is
deprecated as a positional argument and will become a keyword-only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like Because bias is deprecated, this argument needs to be treated as keyword only to avoid a warning.

@charris
Copy link
Member

charris commented Mar 15, 2015

@matthew-brett With that change I think this would be ready.

Add _NoValue class at top level to make it possible to detect when
non-default values got passed to a keyword argument, as in:

    def func(a, b=np._NoValue):
        if b is not np._NoValue:
            warnings.warn("Argument b is deprecated",
                          DeprecationWarning)
The bias and ddof arguments had no effect on the calculation of the
correlation coefficient because the value cancels in the calculation.

Deprecate these arguments to np.corrcoef and np.ma.corrcoef.
charris added a commit that referenced this pull request Mar 21, 2015
BUG: deprecation for ignored corrcoef args
@charris charris merged commit 59be917 into numpy:master Mar 21, 2015
@charris
Copy link
Member

charris commented Mar 21, 2015

Merged. Thanks Matthew.

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

Successfully merging this pull request may close these issues.

3 participants