Skip to content

Implement deprecated_alias, with tests - #4015

Closed
jbrockmendel wants to merge 6 commits into
statsmodels:masterfrom
jbrockmendel:aliases
Closed

jbrockmendel wants to merge 6 commits into
statsmodels:masterfrom
jbrockmendel:aliases

Conversation

@jbrockmendel

Copy link
Copy Markdown
Contributor

Inconsistent names are An Issue. But we're not willing to go through and excise names that don't conform to current naming conventions.

This PR implements a deprecated_alias property-like attribute that warns on access but otherwise behaves normally. i.e. we can bring some consistency to the world, warn users of coming deprecations and maybe even eventually follow up on those deprecations.

One example is implemented in the basically-unmaintained tsa.varma_process. VarmaPoly.nvars corresponds to what we would now call neqs.

@josef-pkt

Copy link
Copy Markdown
Member

an you check whether that attribute deprecation is already handled by the similar numpy function.
We use that one to deprecate functions that have a new version or name.

quick search: np.deprecate
usage, e.g. here
https://github.com/statsmodels/statsmodels/pull/2478/files

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

I took a look at that and AFAICT it is best suited to functions. I didn't see anything I could crib from pandas either.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.006%) to 81.647% when pulling 4d9f8aa on jbrockmendel:aliases into 326ae0c on statsmodels:master.

1 similar comment
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.006%) to 81.647% when pulling 4d9f8aa on jbrockmendel:aliases into 326ae0c on statsmodels:master.

@classmethod
def setup_class(cls):

class Dummy(object):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there is either a tab instead of spaces or 8 instead of 4 spaces


'''

nvars = deprecated_alias('nvars', 'neqs', '0.11.0')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this could have a very short test (hopefully it can be added to an existing test)
I will need to be deleted again later

self.ma = ma
nlags, nvarall, nvars = ar.shape
self.nlags, self.nvarall, self.nvars = nlags, nvarall, nvars
self.nlags, self.nvarall, self.neqs = nlags, nvarall, nvars

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really make this change and deprecate this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is mainly an example case chosen to be small, clear, and out of the way. VARResults is a much more relevant case.

I'm not necessarily the person to ask; I think varma_process should be removed entirely and most of its functionality covered by wold.

Comment thread statsmodels/tools/decorators.py Outdated
return getattr(self, new_name)

def fset(self, value):
warnings.warn(msg)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does this need a warnings class, e.g. DeprecationWarning.
what kind of warn does numpy deprecate issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like np.deprecate does warnings.warn(depdoc, DeprecationWarning, stacklevel=2). This is easy to implement, a bit harder to test. I'll take a look for examples elsewhere.

@josef-pkt

Copy link
Copy Markdown
Member

Ok, then this looks fine to me. a few inline comments. (I didn't think hard about what the decorator function is doing)

To check: this warns only once, or does it warn repeatedly?

@coveralls

coveralls commented Oct 11, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.006%) to 81.647% when pulling 17ab2a9 on jbrockmendel:aliases into 326ae0c on statsmodels:master.

@codecov-io

codecov-io commented Oct 11, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #4015 into master will increase coverage by <.01%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4015      +/-   ##
==========================================
+ Coverage   79.32%   79.33%   +<.01%     
==========================================
  Files         544      545       +1     
  Lines       81714    81752      +38     
  Branches     9255     9256       +1     
==========================================
+ Hits        64820    64857      +37     
- Misses      14800    14801       +1     
  Partials     2094     2094
Impacted Files Coverage Δ
statsmodels/tsa/varma_process.py 0% <0%> (ø) ⬆️
statsmodels/tools/tests/test_decorators.py 100% <100%> (ø)
statsmodels/tools/decorators.py 80.2% <92.3%> (+1.63%) ⬆️
statsmodels/tsa/vector_ar/vecm.py 93.87% <0%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11d1c18...dc18ba6. Read the comment docs.

def __init__(self, ar, ma=None):
self.ar = ar
self.ma = ma
nlags, nvarall, nvars = ar.shape

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nvars -> negs here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To keep the diff small, I only changed it in the one line that sets self.nvars = nvars to set self.neqs = nvars instead.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

OK, changed the warning to specifically issue a DeprecationWarning. testing for that is a PITA, but is now implemented.

@bashtage bashtage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small suggestions. Otherwise looks ready.



def deprecated_alias(old_name, new_name, remove_version=None):
msg = '%s is a deprecated alias for %s' % (old_name, new_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sound you use modern syntax msg = '{0} is a ...'.format(old_name...



def deprecated_alias(old_name, new_name, remove_version=None):
msg = '%s is a deprecated alias for %s' % (old_name, new_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would a short docstring with an example help others find/use this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, will implement.



def deprecated_alias(old_name, new_name, remove_version=None):
msg = '%s is a deprecated alias for %s' % (old_name, new_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should modern string formatting be used '{0}'.format(var)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the pytest precedent is that its OK for me to take my time getting comfortable with that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would autopep all of SM, PRs be damned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would autopep all of SM, PRs be damned.

My foolish hope is that jpkt will delegate design-decision-free fixups to you and I so we can a) clear out the PR backlog and b) clean up the flaketastrophe.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

I was wrong about the tests for DeprecationWarning working (but right about it being a PITA). Just pushed a commit that emits a FutureWarning instead, doesn't require any magic to test.

@coveralls

coveralls commented Oct 24, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 81.798% when pulling 507ab74 on jbrockmendel:aliases into 326ae0c on statsmodels:master.

@coveralls

coveralls commented Oct 24, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 81.788% when pulling 507ab74 on jbrockmendel:aliases into 326ae0c on statsmodels:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.007%) to 81.894% when pulling dc18ba6 on jbrockmendel:aliases into 11d1c18 on statsmodels:master.

1 similar comment
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.007%) to 81.894% when pulling dc18ba6 on jbrockmendel:aliases into 11d1c18 on statsmodels:master.

@bashtage

bashtage commented Dec 25, 2017 via email

Copy link
Copy Markdown
Member

@jbrockmendel
jbrockmendel deleted the aliases branch September 21, 2018 03:46
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants