Skip to content

Commit

Permalink
CLN: added typing requirements for python 2.7. GH14468
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brmc authored and TomAugspurger committed May 8, 2017
1 parent 80abd97 commit fbc3543
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -50,7 +50,7 @@ matrix:
- python-gtk2
- os: linux
env:
- JOB="3.5" TEST_ARGS="--skip-slow --skip-network" COVERAGE=true
- JOB="3.5" TEST_ARGS="--skip-slow --skip-network" COVERAGE=true TYPING=true
addons:
apt:
packages:
Expand Down Expand Up @@ -116,6 +116,7 @@ script:
- ci/script_single.sh
- ci/script_multi.sh
- ci/lint.sh
- ci/typing.sh
- echo "script done"

after_success:
Expand Down
4 changes: 4 additions & 0 deletions ci/install_travis.sh
Expand Up @@ -114,6 +114,10 @@ if [ "$LINT" ]; then
pip install cpplint
fi

if [ "$TYPING" ]; then
pip install mypy-lang
fi

if [ "$COVERAGE" ]; then
pip install coverage pytest-cov
fi
Expand Down
1 change: 1 addition & 0 deletions ci/requirements-2.7.pip
Expand Up @@ -6,3 +6,4 @@ py
PyCrypto
mock
ipython
typing
22 changes: 22 additions & 0 deletions ci/typing.sh
@@ -0,0 +1,22 @@
#!/bin/bash

echo "inside $0"

source activate pandas

RET=0

if [ "$TYPING" ]; then

echo "Typing *.py"
mypy -2 pandas/core/base.py
if [ $? -ne "0" ]; then
RET=1
fi
echo "Typing *.py DONE"

else
echo "NOT checking typing"
fi

exit $RET
10 changes: 9 additions & 1 deletion pandas/core/algorithms.py
Expand Up @@ -33,13 +33,18 @@
from pandas.compat import string_types
from pandas._libs import algos, lib, hashtable as htable
from pandas._libs.tslib import iNaT
import pandas.types.hinting as T # noqa
from pandas.core.dtypes.dtypes import ExtensionDtype # noqa


# --------------- #
# dtype access #
# --------------- #

def _ensure_data(values, dtype=None):
def _ensure_data(values, # type: T.ArrayLike
dtype=None # type: T.Optional[ExtensionDtype]
):
# type: (...) -> T.Tuple[T.ArrayLike, str, str]
"""
routine to ensure that our data is of the correct
input dtype for lower-level routines
Expand Down Expand Up @@ -130,6 +135,7 @@ def _ensure_data(values, dtype=None):


def _reconstruct_data(values, dtype, original):
# type: (T.ArrayLike, str, str) -> T.ArrayLike
"""
reverse of _ensure_data
Expand All @@ -156,6 +162,7 @@ def _reconstruct_data(values, dtype, original):


def _ensure_arraylike(values):
# type: (T.Iterable) -> T.ArrayLike
"""
ensure that we are arraylike if not already
"""
Expand All @@ -179,6 +186,7 @@ def _ensure_arraylike(values):


def _get_hashtable_algo(values):
# type: (T.ArrayLike) -> T.Tuple(type, str, str)
"""
Parameters
----------
Expand Down

0 comments on commit fbc3543

Please sign in to comment.