-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WIP: ensure names are pinned correctly #24429
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2584331
Implement PandasMeta
jbrockmendel 9042230
assert instead of printing
jbrockmendel cc0b725
Merge branch 'master' of https://github.com/pandas-dev/pandas into meta
jbrockmendel 3db4457
use type comparison
jbrockmendel 6b9dec9
Merge branch 'master' of https://github.com/pandas-dev/pandas into meta
jbrockmendel 3ada68d
use __subclasses__ instead of metaclass
jbrockmendel 04b5606
flake8 fixup
jbrockmendel 20e68aa
Merge branch 'master' of https://github.com/pandas-dev/pandas into meta
jbrockmendel e247ec8
revert non-central changes
jbrockmendel 9420548
either fix or kludge all the names
jbrockmendel bf1a6bd
py3 compat for sorted
jbrockmendel 1a9a1f5
Merge branch 'master' of https://github.com/pandas-dev/pandas into meta
jbrockmendel 07ef007
make cls_kludge prettier
jbrockmendel 0a2aeac
one more special
jbrockmendel 602cb0e
Merge branch 'master' of https://github.com/pandas-dev/pandas into meta
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
|
||
import inspect | ||
import re | ||
import sys | ||
from datetime import datetime, timedelta | ||
|
@@ -1273,3 +1274,48 @@ def test_to_numpy_dtype(as_series): | |
expected = np.array(['2000-01-01T05', '2001-01-01T05'], | ||
dtype='M8[ns]') | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
def check_pinned_names(cls): | ||
""" | ||
Check that the any dynamically-defined methods have the correct | ||
names, i.e. not 'wrapper'. | ||
""" | ||
special_cases = { | ||
"isnull": "isna", | ||
"notnull": "notna", | ||
"take": "take_nd", # Categorical | ||
"to_list": "tolist", # Categorical | ||
"iteritems": "items", | ||
"__bool__": "__nonzero__", | ||
} | ||
ignore = { | ||
"_create_comparison_method", | ||
} | ||
if 'Subclassed' in cls.__name__: | ||
# dummy classes defined in tests | ||
return | ||
for name in dir(cls): | ||
try: | ||
# e.g. properties may not be accessible on the class | ||
attr = getattr(cls, name) | ||
except Exception: | ||
continue | ||
if name in ignore: | ||
continue | ||
if inspect.ismethod(attr) or isinstance(attr, property): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Python3 methods on (non-instantiated) classes are functions, so for those ismethod will fail. You need to add inspect.isfunction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks |
||
expected = special_cases.get(name, name) | ||
result = attr.__name__ | ||
assert result == expected, (result, expected, name, | ||
cls.__name__) | ||
|
||
|
||
@pytest.mark.parametrize('klass', | ||
PandasObject.__subclasses__() + [ | ||
pd.Timestamp, | ||
pd.Period, | ||
pd.Timedelta, | ||
pd.Interval | ||
]) | ||
def test_pinned_names(klass): | ||
check_pinned_names(klass) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This iteration looks heavy. What time does it take to run through all cases defined in the test_pinned_names parametrization? Should test_pinned_names below get a pytest slow marker?
Would it not be better to do specific tests for the cases where methods are generated dynamically instead of this broader test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locally
python -m pytest pandas/tests/test_base.py -k test_pinned_names
takes 1.02 seconds.No, that's an invitation to have things fall through the cracks down the road.