Skip to content

Fix type annotations in pandas.core.ops #26377

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

Merged
merged 4 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ ignore_errors=True
[mypy-pandas.core.internals.blocks]
ignore_errors=True

[mypy-pandas.core.ops]
ignore_errors=True

[mypy-pandas.core.panel]
ignore_errors=True

Expand Down
14 changes: 10 additions & 4 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import datetime
import operator
import textwrap
from typing import Dict, Optional, Union, cast
import warnings

import numpy as np
Expand Down Expand Up @@ -625,16 +626,21 @@ def _get_op_name(op, special):
'desc': 'Greater than or equal to',
'reverse': None,
'series_examples': None}
}
} # type: Dict[str, Dict[str, Optional[Union[bool, str]]]]

# When TypedDict becomes available, this annotation would be much better and
# more readable if defined using that structure. The casts() below would not be
# necessary, because only the dictionary values keyed to 'reversed' would be
# typed as bool. See GH#26377.

_op_names = list(_op_descriptions.keys())
for key in _op_names:
_op_descriptions[key]['reversed'] = False
reverse_op = _op_descriptions[key]['reverse']
if reverse_op is not None:
_op_descriptions[reverse_op] = _op_descriptions[key].copy()
_op_descriptions[reverse_op]['reversed'] = True
_op_descriptions[reverse_op]['reverse'] = key
_op_descriptions[cast(str, reverse_op)] = _op_descriptions[key].copy()
_op_descriptions[cast(str, reverse_op)]['reversed'] = True
_op_descriptions[cast(str, reverse_op)]['reverse'] = key

_flex_doc_SERIES = """
Return {desc} of series and other, element-wise (binary operator `{op_name}`).
Expand Down