Skip to content

Commit fbc3543

Browse files
brmcTomAugspurger
authored andcommitted
CLN: added typing requirements for python 2.7. GH14468
CLN: created foundation for complex type annotations (GH14468) This is mostly just a stub file for now until a more clear picture develops What has been noticed so far: * numpy has no clear definition of what array_like means. all of these are valid: - Python scalars - tuples - lists - buffers - scalars in both python and numpy - more? * similar story but not so extreme with dtypes * python and numpy scalar helpers have been defined CLN: annotated IndexOpsMixin (GH14468) CLN: fixed a couple mistakes in IndexOpsMixin (GH14468) CLN: cleaned up some import statements and reverted a file commited by accident (GH14468) CLN: temporary work around for buffer error in python3 (GH14468) CLN: temporary work around for buffer error in python3 part 2 (GH14468) add trivial mypy check Fixup
1 parent 80abd97 commit fbc3543

File tree

10 files changed

+211
-22
lines changed

10 files changed

+211
-22
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ matrix:
5050
- python-gtk2
5151
- os: linux
5252
env:
53-
- JOB="3.5" TEST_ARGS="--skip-slow --skip-network" COVERAGE=true
53+
- JOB="3.5" TEST_ARGS="--skip-slow --skip-network" COVERAGE=true TYPING=true
5454
addons:
5555
apt:
5656
packages:
@@ -116,6 +116,7 @@ script:
116116
- ci/script_single.sh
117117
- ci/script_multi.sh
118118
- ci/lint.sh
119+
- ci/typing.sh
119120
- echo "script done"
120121

121122
after_success:

ci/install_travis.sh

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ if [ "$LINT" ]; then
114114
pip install cpplint
115115
fi
116116

117+
if [ "$TYPING" ]; then
118+
pip install mypy-lang
119+
fi
120+
117121
if [ "$COVERAGE" ]; then
118122
pip install coverage pytest-cov
119123
fi

ci/requirements-2.7.pip

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ py
66
PyCrypto
77
mock
88
ipython
9+
typing

ci/typing.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
echo "inside $0"
4+
5+
source activate pandas
6+
7+
RET=0
8+
9+
if [ "$TYPING" ]; then
10+
11+
echo "Typing *.py"
12+
mypy -2 pandas/core/base.py
13+
if [ $? -ne "0" ]; then
14+
RET=1
15+
fi
16+
echo "Typing *.py DONE"
17+
18+
else
19+
echo "NOT checking typing"
20+
fi
21+
22+
exit $RET

pandas/core/algorithms.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
from pandas.compat import string_types
3434
from pandas._libs import algos, lib, hashtable as htable
3535
from pandas._libs.tslib import iNaT
36+
import pandas.types.hinting as T # noqa
37+
from pandas.core.dtypes.dtypes import ExtensionDtype # noqa
3638

3739

3840
# --------------- #
3941
# dtype access #
4042
# --------------- #
4143

42-
def _ensure_data(values, dtype=None):
44+
def _ensure_data(values, # type: T.ArrayLike
45+
dtype=None # type: T.Optional[ExtensionDtype]
46+
):
47+
# type: (...) -> T.Tuple[T.ArrayLike, str, str]
4348
"""
4449
routine to ensure that our data is of the correct
4550
input dtype for lower-level routines
@@ -130,6 +135,7 @@ def _ensure_data(values, dtype=None):
130135

131136

132137
def _reconstruct_data(values, dtype, original):
138+
# type: (T.ArrayLike, str, str) -> T.ArrayLike
133139
"""
134140
reverse of _ensure_data
135141
@@ -156,6 +162,7 @@ def _reconstruct_data(values, dtype, original):
156162

157163

158164
def _ensure_arraylike(values):
165+
# type: (T.Iterable) -> T.ArrayLike
159166
"""
160167
ensure that we are arraylike if not already
161168
"""
@@ -179,6 +186,7 @@ def _ensure_arraylike(values):
179186

180187

181188
def _get_hashtable_algo(values):
189+
# type: (T.ArrayLike) -> T.Tuple(type, str, str)
182190
"""
183191
Parameters
184192
----------

0 commit comments

Comments
 (0)