Skip to content

Commit d238878

Browse files
committed
Merge remote-tracking branch 'upstream/master' into issue-26023
2 parents 83e8834 + 6de8133 commit d238878

File tree

10 files changed

+32
-63
lines changed

10 files changed

+32
-63
lines changed

mypy.ini

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,6 @@ ignore_errors=True
170170
[mypy-pandas.plotting._core]
171171
ignore_errors=True
172172

173-
[mypy-pandas.tseries.frequencies]
174-
ignore_errors=True
175-
176-
[mypy-pandas.tseries.holiday]
177-
ignore_errors=True
178-
179-
[mypy-pandas.tseries.offsets]
180-
ignore_errors=True
181-
182173
[mypy-pandas.util._doctools]
183174
ignore_errors=True
184175

pandas/compat/__init__.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import platform
2525
import types
2626
import struct
27-
import inspect
28-
from collections import namedtuple
2927

3028
PY2 = sys.version_info[0] == 2
3129
PY3 = sys.version_info[0] >= 3
@@ -64,32 +62,6 @@ def str_to_bytes(s, encoding=None):
6462
def bytes_to_str(b, encoding=None):
6563
return b.decode(encoding or 'utf-8')
6664

67-
# The signature version below is directly copied from Django,
68-
# https://github.com/django/django/pull/4846
69-
def signature(f):
70-
sig = inspect.signature(f)
71-
args = [
72-
p.name for p in sig.parameters.values()
73-
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
74-
]
75-
varargs = [
76-
p.name for p in sig.parameters.values()
77-
if p.kind == inspect.Parameter.VAR_POSITIONAL
78-
]
79-
varargs = varargs[0] if varargs else None
80-
keywords = [
81-
p.name for p in sig.parameters.values()
82-
if p.kind == inspect.Parameter.VAR_KEYWORD
83-
]
84-
keywords = keywords[0] if keywords else None
85-
defaults = [
86-
p.default for p in sig.parameters.values()
87-
if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
88-
and p.default is not p.empty
89-
] or None
90-
argspec = namedtuple('Signature', ['args', 'defaults',
91-
'varargs', 'keywords'])
92-
return argspec(args, defaults, varargs, keywords)
9365
else:
9466
# Python 2
9567
_name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$")
@@ -103,9 +75,6 @@ def str_to_bytes(s, encoding='ascii'):
10375
def bytes_to_str(b, encoding='ascii'):
10476
return b
10577

106-
def signature(f):
107-
return inspect.getargspec(f)
108-
10978
if PY2:
11079
def iteritems(obj, **kw):
11180
return obj.iteritems(**kw)

pandas/core/apply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import inspect
12
import warnings
23

34
import numpy as np
45

56
from pandas._libs import reduction
6-
import pandas.compat as compat
77
from pandas.util._decorators import cache_readonly
88

99
from pandas.core.dtypes.common import (
@@ -123,7 +123,7 @@ def get_result(self):
123123
# Some methods (shift, etc.) require the axis argument, others
124124
# don't, so inspect and insert if necessary.
125125
func = getattr(self.obj, self.f)
126-
sig = compat.signature(func)
126+
sig = inspect.getfullargspec(func)
127127
if 'axis' in sig.args:
128128
self.kwds['axis'] = self.axis
129129
return func(*self.args, **self.kwds)

pandas/core/generic.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8781,22 +8781,22 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
87818781
.. versionadded:: 0.18.1
87828782
A callable can be used as other.
87838783
8784-
inplace : boolean, default False
8784+
inplace : bool, default False
87858785
Whether to perform the operation in place on the data.
87868786
axis : int, default None
87878787
Alignment axis if needed.
87888788
level : int, default None
87898789
Alignment level if needed.
8790-
errors : str, {'raise', 'ignore'}, default `raise`
8790+
errors : str, {'raise', 'ignore'}, default 'raise'
87918791
Note that currently this parameter won't affect
87928792
the results and will always coerce to a suitable dtype.
87938793
8794-
- `raise` : allow exceptions to be raised.
8795-
- `ignore` : suppress exceptions. On error return original object.
8794+
- 'raise' : allow exceptions to be raised.
8795+
- 'ignore' : suppress exceptions. On error return original object.
87968796
8797-
try_cast : boolean, default False
8797+
try_cast : bool, default False
87988798
Try to cast the result back to the input type (if possible).
8799-
raise_on_error : boolean, default True
8799+
raise_on_error : bool, default True
88008800
Whether to raise on invalid data types (e.g. trying to where on
88018801
strings).
88028802
@@ -8806,7 +8806,7 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
88068806
88078807
Returns
88088808
-------
8809-
wh : same type as caller
8809+
Same type as caller
88108810
88118811
See Also
88128812
--------
@@ -8855,6 +8855,13 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
88558855
dtype: int64
88568856
88578857
>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
8858+
>>> df
8859+
A B
8860+
0 0 1
8861+
1 2 3
8862+
2 4 5
8863+
3 6 7
8864+
4 8 9
88588865
>>> m = df %% 3 == 0
88598866
>>> df.where(m, -df)
88608867
A B

pandas/tests/reductions/test_stat_reductions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
Tests for statistical reductions of 2nd moment or higher: var, skew, kurt, ...
44
"""
5+
import inspect
56

67
import numpy as np
78
import pytest
@@ -10,7 +11,7 @@
1011
import pandas.util._test_decorators as td
1112

1213
import pandas as pd
13-
from pandas import DataFrame, Series, compat
14+
from pandas import DataFrame, Series
1415
import pandas.util.testing as tm
1516

1617

@@ -75,7 +76,7 @@ def _check_stat_op(self, name, alternate, string_series_,
7576
f(string_series_, axis=1)
7677

7778
# Unimplemented numeric_only parameter.
78-
if 'numeric_only' in compat.signature(f).args:
79+
if 'numeric_only' in inspect.getfullargspec(f).args:
7980
with pytest.raises(NotImplementedError, match=name):
8081
f(string_series_, numeric_only=True)
8182

pandas/tseries/frequencies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from datetime import timedelta
33
import re
4+
from typing import Dict
45

56
import numpy as np
67
from pytz import AmbiguousTimeError
@@ -37,7 +38,7 @@
3738
# Offset names ("time rules") and related functions
3839

3940
#: cache of previously seen offsets
40-
_offset_map = {}
41+
_offset_map = {} # type: Dict[str, DateOffset]
4142

4243

4344
def get_period_alias(offset_str):

pandas/tseries/holiday.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
from typing import List
23
import warnings
34

45
from dateutil.relativedelta import FR, MO, SA, SU, TH, TU, WE # noqa
@@ -329,7 +330,7 @@ class AbstractHolidayCalendar(object):
329330
Abstract interface to create holidays following certain rules.
330331
"""
331332
__metaclass__ = HolidayCalendarMetaClass
332-
rules = []
333+
rules = [] # type: List[Holiday]
333334
start_date = Timestamp(datetime(1970, 1, 1))
334335
end_date = Timestamp(datetime(2030, 12, 31))
335336
_cache = None

pandas/tseries/offsets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import date, datetime, timedelta
33
import functools
44
import operator
5+
from typing import Optional
56

67
from dateutil.easter import easter
78
import numpy as np
@@ -1582,8 +1583,8 @@ class QuarterOffset(DateOffset):
15821583
"""
15831584
Quarter representation - doesn't call super.
15841585
"""
1585-
_default_startingMonth = None
1586-
_from_name_startingMonth = None
1586+
_default_startingMonth = None # type: Optional[int]
1587+
_from_name_startingMonth = None # type: Optional[int]
15871588
_adjust_dst = True
15881589
_attributes = frozenset(['n', 'normalize', 'startingMonth'])
15891590
# TODO: Consider combining QuarterOffset and YearOffset __init__ at some

pandas/util/_decorators.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import warnings
55

66
from pandas._libs.properties import cache_readonly # noqa
7-
from pandas.compat import signature
87

98

109
def deprecate(name, alternative, version, alt_name=None,
@@ -335,7 +334,7 @@ def make_signature(func):
335334
(['a', 'b', 'c=2'], ['a', 'b', 'c'])
336335
"""
337336

338-
spec = signature(func)
337+
spec = inspect.getfullargspec(func)
339338
if spec.defaults is None:
340339
n_wo_defaults = len(spec.args)
341340
defaults = ('',) * n_wo_defaults
@@ -347,6 +346,6 @@ def make_signature(func):
347346
args.append(var if default == '' else var + '=' + repr(default))
348347
if spec.varargs:
349348
args.append('*' + spec.varargs)
350-
if spec.keywords:
351-
args.append('**' + spec.keywords)
349+
if spec.varkw:
350+
args.append('**' + spec.varkw)
352351
return args, spec.args

scripts/validate_docstrings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050

5151
sys.path.insert(0, os.path.join(BASE_PATH))
5252
import pandas
53-
from pandas.compat import signature
5453

5554
sys.path.insert(1, os.path.join(BASE_PATH, 'doc', 'sphinxext'))
5655
from numpydoc.docscrape import NumpyDocString
@@ -420,16 +419,16 @@ def signature_parameters(self):
420419
# accessor classes have a signature but don't want to show this
421420
return tuple()
422421
try:
423-
sig = signature(self.obj)
422+
sig = inspect.getfullargspec(self.obj)
424423
except (TypeError, ValueError):
425424
# Some objects, mainly in C extensions do not support introspection
426425
# of the signature
427426
return tuple()
428427
params = sig.args
429428
if sig.varargs:
430429
params.append("*" + sig.varargs)
431-
if sig.keywords:
432-
params.append("**" + sig.keywords)
430+
if sig.varkw:
431+
params.append("**" + sig.varkw)
433432
params = tuple(params)
434433
if params and params[0] in ('self', 'cls'):
435434
return params[1:]

0 commit comments

Comments
 (0)