Skip to content

Commit d8af650

Browse files
committed
Merge branch 'master' into blacklist-dtypes
2 parents 6dae7ca + 6d9b702 commit d8af650

22 files changed

+114
-161
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ I/O
361361
- Bug in ``read_csv`` which would not raise ``ValueError`` if a column index in ``usecols`` was out of bounds (:issue:`25623`)
362362
- Improved the explanation for the failure when value labels are repeated in Stata dta files and suggested work-arounds (:issue:`25772`)
363363
- Improved :meth:`pandas.read_stata` and :class:`pandas.io.stata.StataReader` to read incorrectly formatted 118 format files saved by Stata (:issue:`25960`)
364+
- Fixed bug in loading objects from S3 that contain ``#`` characters in the URL (:issue:`25945`)
364365

365366
Plotting
366367
^^^^^^^^

mypy.ini

-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ ignore_errors=True
158158
[mypy-pandas.io.pytables]
159159
ignore_errors=True
160160

161-
[mypy-pandas.io.stata]
162-
ignore_errors=True
163-
164161
[mypy-pandas.util._doctools]
165162
ignore_errors=True
166163

pandas/__init__.py

+67-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
del hard_dependencies, dependency, missing_dependencies
2121

2222
# numpy compat
23-
from pandas.compat.numpy import *
23+
from pandas.compat.numpy import (
24+
_np_version_under1p14, _np_version_under1p15, _np_version_under1p16,
25+
_np_version_under1p17)
2426

2527
try:
2628
from pandas._libs import (hashtable as _hashtable,
@@ -42,14 +44,72 @@
4244
# let init-time option registration happen
4345
import pandas.core.config_init
4446

45-
from pandas.core.api import *
46-
from pandas.core.sparse.api import *
47-
from pandas.tseries.api import *
48-
from pandas.core.computation.api import *
49-
from pandas.core.reshape.api import *
47+
from pandas.core.api import (
48+
# dtype
49+
Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype, UInt8Dtype,
50+
UInt16Dtype, UInt32Dtype, UInt64Dtype, CategoricalDtype,
51+
PeriodDtype, IntervalDtype, DatetimeTZDtype,
52+
53+
# missing
54+
isna, isnull, notna, notnull,
55+
56+
# indexes
57+
Index, CategoricalIndex, Int64Index, UInt64Index, RangeIndex,
58+
Float64Index, MultiIndex, IntervalIndex, TimedeltaIndex,
59+
DatetimeIndex, PeriodIndex, IndexSlice,
60+
61+
# tseries
62+
NaT, Period, period_range, Timedelta, timedelta_range,
63+
Timestamp, date_range, bdate_range, Interval, interval_range,
64+
DateOffset,
65+
66+
# conversion
67+
to_numeric, to_datetime, to_timedelta,
68+
69+
# misc
70+
np, TimeGrouper, Grouper, factorize, unique, value_counts,
71+
array, Categorical, set_eng_float_format, Series, DataFrame,
72+
Panel)
73+
74+
from pandas.core.sparse.api import (
75+
SparseArray, SparseDataFrame, SparseSeries, SparseDtype)
76+
77+
from pandas.tseries.api import infer_freq
78+
from pandas.tseries import offsets
79+
80+
from pandas.core.computation.api import eval
81+
82+
from pandas.core.reshape.api import (
83+
concat, lreshape, melt, wide_to_long, merge, merge_asof,
84+
merge_ordered, crosstab, pivot, pivot_table, get_dummies,
85+
cut, qcut)
5086

5187
from pandas.util._print_versions import show_versions
52-
from pandas.io.api import *
88+
89+
from pandas.io.api import (
90+
# excel
91+
ExcelFile, ExcelWriter, read_excel,
92+
93+
# packers
94+
read_msgpack, to_msgpack,
95+
96+
# parsers
97+
read_csv, read_fwf, read_table,
98+
99+
# pickle
100+
read_pickle, to_pickle,
101+
102+
# pytables
103+
HDFStore, read_hdf,
104+
105+
# sql
106+
read_sql, read_sql_query,
107+
read_sql_table,
108+
109+
# misc
110+
read_clipboard, read_parquet, read_feather, read_gbq,
111+
read_html, read_json, read_stata, read_sas)
112+
53113
from pandas.util._tester import test
54114
import pandas.testing
55115
import pandas.arrays

pandas/_typing.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
from pathlib import Path
22
from typing import IO, AnyStr, Union
33

4+
import numpy as np
5+
6+
from pandas.core.dtypes.dtypes import ExtensionDtype
7+
from pandas.core.dtypes.generic import ABCExtensionArray
8+
9+
ArrayLike = Union[ABCExtensionArray, np.ndarray]
10+
Dtype = Union[str, np.dtype, ExtensionDtype]
411
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]

pandas/compat/__init__.py

+3-53
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* lists: lrange(), lmap(), lzip(), lfilter()
99
* iterable method compatibility: iteritems, iterkeys, itervalues
1010
* Uses the original method if available, otherwise uses items, keys, values.
11-
* bind_method: binds functions to classes
1211
* add_metaclass(metaclass) - class decorator that recreates class with with the
1312
given metaclass instead (and avoids intermediary class creation)
1413
@@ -22,18 +21,14 @@
2221
from distutils.version import LooseVersion
2322
import sys
2423
import platform
25-
import types
2624
import struct
2725

2826
PY2 = sys.version_info[0] == 2
2927
PY3 = sys.version_info[0] >= 3
30-
PY35 = sys.version_info >= (3, 5)
3128
PY36 = sys.version_info >= (3, 6)
3229
PY37 = sys.version_info >= (3, 7)
3330
PYPY = platform.python_implementation() == 'PyPy'
3431

35-
from pandas.compat.chainmap import DeepChainMap
36-
3732

3833
# list-producing versions of the major Python iterating functions
3934
def lrange(*args, **kwargs):
@@ -52,29 +47,6 @@ def lfilter(*args, **kwargs):
5247
return list(filter(*args, **kwargs))
5348

5449

55-
if PY3:
56-
def isidentifier(s):
57-
return s.isidentifier()
58-
59-
def str_to_bytes(s, encoding=None):
60-
return s.encode(encoding or 'ascii')
61-
62-
def bytes_to_str(b, encoding=None):
63-
return b.decode(encoding or 'utf-8')
64-
65-
else:
66-
# Python 2
67-
_name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$")
68-
69-
def isidentifier(s, dotted=False):
70-
return bool(_name_re.match(s))
71-
72-
def str_to_bytes(s, encoding='ascii'):
73-
return s
74-
75-
def bytes_to_str(b, encoding='ascii'):
76-
return b
77-
7850
if PY2:
7951
def iteritems(obj, **kw):
8052
return obj.iteritems(**kw)
@@ -95,30 +67,6 @@ def iterkeys(obj, **kw):
9567
def itervalues(obj, **kw):
9668
return iter(obj.values(**kw))
9769

98-
99-
def bind_method(cls, name, func):
100-
"""Bind a method to class, python 2 and python 3 compatible.
101-
102-
Parameters
103-
----------
104-
105-
cls : type
106-
class to receive bound method
107-
name : basestring
108-
name of method on class instance
109-
func : function
110-
function to be bound as method
111-
112-
113-
Returns
114-
-------
115-
None
116-
"""
117-
# only python 2 has bound/unbound method issue
118-
if not PY3:
119-
setattr(cls, name, types.MethodType(func, None, cls))
120-
else:
121-
setattr(cls, name, func)
12270
# ----------------------------------------------------------------------------
12371
# functions largely based / taken from the six module
12472

@@ -133,7 +81,7 @@ def to_str(s):
13381
Convert bytes and non-string into Python 3 str
13482
"""
13583
if isinstance(s, bytes):
136-
s = bytes_to_str(s)
84+
s = s.decode('utf-8')
13785
elif not isinstance(s, str):
13886
s = str(s)
13987
return s
@@ -172,6 +120,7 @@ def wrapper(cls):
172120
return metaclass(cls.__name__, cls.__bases__, orig_vars)
173121
return wrapper
174122

123+
175124
if PY3:
176125
def raise_with_traceback(exc, traceback=Ellipsis):
177126
if traceback == Ellipsis:
@@ -207,6 +156,7 @@ def raise_with_traceback(exc, traceback=Ellipsis):
207156
else:
208157
re_type = type(re.compile(''))
209158

159+
210160
# https://github.com/pandas-dev/pandas/pull/9123
211161
def is_platform_little_endian():
212162
""" am I little endian """

pandas/core/arrays/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ABCExtensionArray, ABCIndexClass, ABCSeries)
2222
from pandas.core.dtypes.missing import isna
2323

24+
from pandas._typing import ArrayLike
2425
from pandas.core import ops
2526

2627
_not_implemented_message = "{} does not implement {}."
@@ -338,7 +339,7 @@ def astype(self, dtype, copy=True):
338339
"""
339340
return np.array(self, dtype=dtype, copy=copy)
340341

341-
def isna(self) -> Union[ABCExtensionArray, np.ndarray]:
342+
def isna(self) -> ArrayLike:
342343
"""
343344
A 1-D array indicating if each value is missing.
344345

pandas/core/arrays/sparse.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numbers
66
import operator
77
import re
8-
from typing import Any, Callable, Type, Union
8+
from typing import Any, Callable
99
import warnings
1010

1111
import numpy as np
@@ -31,6 +31,7 @@
3131
ABCIndexClass, ABCSeries, ABCSparseArray, ABCSparseSeries)
3232
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna
3333

34+
from pandas._typing import Dtype
3435
from pandas.core.accessor import PandasDelegate, delegate_names
3536
import pandas.core.algorithms as algos
3637
from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
@@ -80,7 +81,7 @@ class SparseDtype(ExtensionDtype):
8081

8182
def __init__(
8283
self,
83-
dtype: Union[str, np.dtype, ExtensionDtype, Type] = np.float64,
84+
dtype: Dtype = np.float64,
8485
fill_value: Any = None
8586
) -> None:
8687
from pandas.core.dtypes.missing import na_value_for_dtype

pandas/core/computation/expr.py

+3-66
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
import numpy as np
1212

13-
from pandas.compat import lmap
13+
from pandas.compat import iteritems, lmap
1414

1515
import pandas as pd
16-
from pandas import compat
1716
from pandas.core import common as com
1817
from pandas.core.base import StringMixin
1918
from pandas.core.computation.common import (
@@ -301,7 +300,7 @@ def f(self, node, *args, **kwargs):
301300
def add_ops(op_classes):
302301
"""Decorator to add default implementation of ops."""
303302
def f(cls):
304-
for op_attr_name, op_class in compat.iteritems(op_classes):
303+
for op_attr_name, op_class in iteritems(op_classes):
305304
ops = getattr(cls, '{name}_ops'.format(name=op_attr_name))
306305
ops_map = getattr(cls, '{name}_op_nodes_map'.format(
307306
name=op_attr_name))
@@ -590,9 +589,7 @@ def visit_Attribute(self, node, **kwargs):
590589
raise ValueError("Invalid Attribute context {name}"
591590
.format(name=ctx.__name__))
592591

593-
def visit_Call_35(self, node, side=None, **kwargs):
594-
""" in 3.5 the starargs attribute was changed to be more flexible,
595-
#11097 """
592+
def visit_Call(self, node, side=None, **kwargs):
596593

597594
if isinstance(node.func, ast.Attribute):
598595
res = self.visit_Attribute(node.func)
@@ -641,58 +638,6 @@ def visit_Call_35(self, node, side=None, **kwargs):
641638

642639
return self.const_type(res(*new_args, **kwargs), self.env)
643640

644-
def visit_Call_legacy(self, node, side=None, **kwargs):
645-
646-
# this can happen with: datetime.datetime
647-
if isinstance(node.func, ast.Attribute):
648-
res = self.visit_Attribute(node.func)
649-
elif not isinstance(node.func, ast.Name):
650-
raise TypeError("Only named functions are supported")
651-
else:
652-
try:
653-
res = self.visit(node.func)
654-
except UndefinedVariableError:
655-
# Check if this is a supported function name
656-
try:
657-
res = FuncNode(node.func.id)
658-
except ValueError:
659-
# Raise original error
660-
raise
661-
662-
if res is None:
663-
raise ValueError("Invalid function call {func}"
664-
.format(func=node.func.id))
665-
if hasattr(res, 'value'):
666-
res = res.value
667-
668-
if isinstance(res, FuncNode):
669-
args = [self.visit(targ) for targ in node.args]
670-
671-
if node.starargs is not None:
672-
args += self.visit(node.starargs)
673-
674-
if node.keywords or node.kwargs:
675-
raise TypeError("Function \"{name}\" does not support keyword "
676-
"arguments".format(name=res.name))
677-
678-
return res(*args, **kwargs)
679-
680-
else:
681-
args = [self.visit(targ).value for targ in node.args]
682-
if node.starargs is not None:
683-
args += self.visit(node.starargs).value
684-
685-
keywords = {}
686-
for key in node.keywords:
687-
if not isinstance(key, ast.keyword):
688-
raise ValueError("keyword error in function call "
689-
"'{func}'".format(func=node.func.id))
690-
keywords[key.arg] = self.visit(key.value).value
691-
if node.kwargs is not None:
692-
keywords.update(self.visit(node.kwargs).value)
693-
694-
return self.const_type(res(*args, **keywords), self.env)
695-
696641
def translate_In(self, op):
697642
return op
698643

@@ -734,14 +679,6 @@ def visitor(x, y):
734679
return reduce(visitor, operands)
735680

736681

737-
# ast.Call signature changed on 3.5,
738-
# conditionally change which methods is named
739-
# visit_Call depending on Python version, #11097
740-
if compat.PY35:
741-
BaseExprVisitor.visit_Call = BaseExprVisitor.visit_Call_35
742-
else:
743-
BaseExprVisitor.visit_Call = BaseExprVisitor.visit_Call_legacy
744-
745682
_python_not_supported = frozenset(['Dict', 'BoolOp', 'In', 'NotIn'])
746683
_numexpr_supported_calls = frozenset(_reductions + _mathops)
747684

pandas/core/computation/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77

88
from pandas._libs.tslibs import Timedelta, Timestamp
9-
from pandas.compat import DeepChainMap
9+
from pandas.compat.chainmap import DeepChainMap
1010

1111
from pandas.core.dtypes.common import is_list_like
1212

pandas/core/computation/scope.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414

1515
from pandas._libs.tslibs import Timestamp
16-
from pandas.compat import DeepChainMap
16+
from pandas.compat.chainmap import DeepChainMap
1717

1818
from pandas.core.base import StringMixin
1919
import pandas.core.computation as compu

0 commit comments

Comments
 (0)