From 8afd7cb6953ef8a8e3fd6fb81ac90933651a3277 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 10:28:49 -0700 Subject: [PATCH 01/11] remove unused util, closes #19676 --- pandas/util/_decorators.py | 46 -------------------------------------- 1 file changed, 46 deletions(-) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 7d5753d03f4fc..82cd44113cb25 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -1,7 +1,6 @@ from pandas.compat import callable, signature, PY2 from pandas._libs.properties import cache_readonly # noqa import inspect -import types import warnings from textwrap import dedent, wrap from functools import wraps, update_wrapper, WRAPPER_ASSIGNMENTS @@ -339,48 +338,3 @@ def make_signature(func): if spec.keywords: args.append('**' + spec.keywords) return args, spec.args - - -class docstring_wrapper(object): - """ - Decorator to wrap a function and provide - a dynamically evaluated doc-string. - - Parameters - ---------- - func : callable - creator : callable - return the doc-string - default : str, optional - return this doc-string on error - """ - _attrs = ['__module__', '__name__', - '__qualname__', '__annotations__'] - - def __init__(self, func, creator, default=None): - self.func = func - self.creator = creator - self.default = default - update_wrapper( - self, func, [attr for attr in self._attrs - if hasattr(func, attr)]) - - def __get__(self, instance, cls=None): - - # we are called with a class - if instance is None: - return self - - # we want to return the actual passed instance - return types.MethodType(self, instance) - - def __call__(self, *args, **kwargs): - return self.func(*args, **kwargs) - - @property - def __doc__(self): - try: - return self.creator() - except Exception as exc: - msg = self.default or str(exc) - return msg From f224eae4760c1bffd27f0325a0f5dfd5489ccbe5 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 10:33:22 -0700 Subject: [PATCH 02/11] command line option to enable cython coverage; closes #21991 --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 85c5970af018f..8f2ab1611387a 100755 --- a/setup.py +++ b/setup.py @@ -438,9 +438,12 @@ def get_tag(self): # enable coverage by building cython files by setting the environment variable -# "PANDAS_CYTHON_COVERAGE" (with a Truthy value) +# "PANDAS_CYTHON_COVERAGE" (with a Truthy value) or by running build_ext +# with `--with-cython-coverage`enabled linetrace = os.environ.get('PANDAS_CYTHON_COVERAGE', False) -CYTHON_TRACE = str(int(bool(linetrace))) +if '--with-cython-coverage' in sys.argv: + linetrace = True + sys.argv.remove('--with-cython-coverage') # Note: if not using `cythonize`, coverage can be enabled by # pinning `ext.cython_directives = directives` to each ext in extensions. From c0892eff320d910ca18dfb09f50b0c45c116f681 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 10:49:40 -0700 Subject: [PATCH 03/11] cimport from libc.stdint; fixes numpy 1.7 warnings --- pandas/_libs/tslibs/ccalendar.pxd | 3 +-- pandas/_libs/tslibs/ccalendar.pyx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/ccalendar.pxd b/pandas/_libs/tslibs/ccalendar.pxd index 04fb6eaf49c84..954e32f037356 100644 --- a/pandas/_libs/tslibs/ccalendar.pxd +++ b/pandas/_libs/tslibs/ccalendar.pxd @@ -2,8 +2,7 @@ # cython: profile=False from cython cimport Py_ssize_t - -from numpy cimport int64_t, int32_t +from libc.stdint cimport int64_t, int32_t cdef int dayofweek(int y, int m, int d) nogil diff --git a/pandas/_libs/tslibs/ccalendar.pyx b/pandas/_libs/tslibs/ccalendar.pyx index 12d35f7ce2f58..eee1b6d116da9 100644 --- a/pandas/_libs/tslibs/ccalendar.pyx +++ b/pandas/_libs/tslibs/ccalendar.pyx @@ -8,7 +8,7 @@ Cython implementations of functions resembling the stdlib calendar module cimport cython from cython cimport Py_ssize_t -from numpy cimport int64_t, int32_t +from libc.stdint cimport int64_t, int32_t from locale import LC_TIME from strptime import LocaleTime From 23e3311989cd85b2aef0e2a248b04c87c9bd6643 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 10:58:23 -0700 Subject: [PATCH 04/11] fix npy deprecated warning on internals.pyx --- pandas/_libs/internals.pyx | 3 ++- pandas/_libs/src/compat_helper.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/internals.pyx b/pandas/_libs/internals.pyx index 68698f45d5623..776b383cbd8eb 100644 --- a/pandas/_libs/internals.pyx +++ b/pandas/_libs/internals.pyx @@ -3,6 +3,8 @@ cimport cython from cython cimport Py_ssize_t +from libc.stdint cimport int64_t + from cpython cimport PyObject from cpython.slice cimport PySlice_Check @@ -10,7 +12,6 @@ cdef extern from "Python.h": Py_ssize_t PY_SSIZE_T_MAX import numpy as np -from numpy cimport int64_t cdef extern from "compat_helper.h": cdef int slice_get_indices(PyObject* s, Py_ssize_t length, diff --git a/pandas/_libs/src/compat_helper.h b/pandas/_libs/src/compat_helper.h index bdff61d7d4150..116cd91070a60 100644 --- a/pandas/_libs/src/compat_helper.h +++ b/pandas/_libs/src/compat_helper.h @@ -11,7 +11,7 @@ The full license is in the LICENSE file, distributed with this software. #define PANDAS__LIBS_SRC_COMPAT_HELPER_H_ #include "Python.h" -#include "numpy_helper.h" +#include "helper.h" /* PySlice_GetIndicesEx changes signature in PY3 From 73a7895dac5878f8b50eb5901a93559663176c1f Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 11:02:56 -0700 Subject: [PATCH 05/11] fix npy deprecated warning in skiplist --- pandas/_libs/skiplist.pxd | 3 +-- pandas/_libs/skiplist.pyx | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pandas/_libs/skiplist.pxd b/pandas/_libs/skiplist.pxd index 82a0862112199..5a23813039f44 100644 --- a/pandas/_libs/skiplist.pxd +++ b/pandas/_libs/skiplist.pxd @@ -3,7 +3,6 @@ from cython cimport Py_ssize_t -from numpy cimport double_t cdef extern from "src/skiplist.h": @@ -33,7 +32,7 @@ cdef extern from "src/skiplist.h": # Node itself not intended to be exposed. cdef class Node: cdef public: - double_t value + double value list next list width diff --git a/pandas/_libs/skiplist.pyx b/pandas/_libs/skiplist.pyx index 5ede31b24118d..23836ef7f4de9 100644 --- a/pandas/_libs/skiplist.pyx +++ b/pandas/_libs/skiplist.pyx @@ -9,9 +9,6 @@ from libc.math cimport log import numpy as np -cimport numpy as cnp -from numpy cimport double_t -cnp.import_array() # MSVC does not have log2! @@ -26,11 +23,11 @@ from random import random cdef class Node: # cdef public: - # double_t value + # double value # list next # list width - def __init__(self, double_t value, list next, list width): + def __init__(self, double value, list next, list width): self.value = value self.next = next self.width = width From c1ca93e0f1e5a275196409dddf6c0f4b7f3eb57e Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 11:17:23 -0700 Subject: [PATCH 06/11] fix bare exception --- pandas/util/_print_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/_print_versions.py b/pandas/util/_print_versions.py index 01198fc541e0c..5600834f3b615 100644 --- a/pandas/util/_print_versions.py +++ b/pandas/util/_print_versions.py @@ -114,7 +114,7 @@ def show_versions(as_json=False): if (as_json): try: import json - except: + except ImportError: import simplejson as json j = dict(system=dict(sys_info), dependencies=dict(deps_blob)) From ecac37d92af32ab8bbf2d2434e53f7611b1696be Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 11:23:14 -0700 Subject: [PATCH 07/11] fix bare except:s --- pandas/core/tools/timedeltas.py | 2 +- pandas/io/s3.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/tools/timedeltas.py b/pandas/core/tools/timedeltas.py index 63ab120833ba1..4dc4fcb00d84d 100644 --- a/pandas/core/tools/timedeltas.py +++ b/pandas/core/tools/timedeltas.py @@ -131,7 +131,7 @@ def _validate_timedelta_unit(arg): """ provide validation / translation for timedelta short units """ try: return _unit_map[arg] - except: + except (KeyError, TypeError): if arg is None: return 'ns' raise ValueError("invalid timedelta unit {arg} provided" diff --git a/pandas/io/s3.py b/pandas/io/s3.py index bd2286c5c8569..7d1360934fd53 100644 --- a/pandas/io/s3.py +++ b/pandas/io/s3.py @@ -3,7 +3,7 @@ try: import s3fs from botocore.exceptions import NoCredentialsError -except: +except ImportError: raise ImportError("The s3fs library is required to handle s3 files") if compat.PY3: From 69da162c61517dc32a439088596a19e885ddf2be Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 11:32:29 -0700 Subject: [PATCH 08/11] catch specific errors --- pandas/tests/frame/test_missing.py | 2 +- pandas/tests/io/generate_legacy_storage_files.py | 2 +- pandas/tests/io/test_pickle.py | 2 +- pandas/tests/io/test_sql.py | 2 +- pandas/tests/series/test_missing.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 9567c08781856..136299a4b81be 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -27,7 +27,7 @@ import scipy _is_scipy_ge_0190 = (LooseVersion(scipy.__version__) >= LooseVersion('0.19.0')) -except: +except ImportError: _is_scipy_ge_0190 = False diff --git a/pandas/tests/io/generate_legacy_storage_files.py b/pandas/tests/io/generate_legacy_storage_files.py index eb40e5521f7f1..aa020ba4c0623 100755 --- a/pandas/tests/io/generate_legacy_storage_files.py +++ b/pandas/tests/io/generate_legacy_storage_files.py @@ -303,7 +303,7 @@ def write_legacy_pickles(output_dir): # make sure we are < 0.13 compat (in py3) try: from pandas.compat import zip, cPickle as pickle # noqa - except: + except ImportError: import pickle version = pandas.__version__ diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index 45cbbd43cd6a8..c71e26ae56e8e 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -218,7 +218,7 @@ def c_unpickler(path): with open(path, 'rb') as fh: fh.seek(0) return c_pickle.load(fh) - except: + except ImportError: c_pickler = None c_unpickler = None diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index f8f742c5980ac..4b0edfce89174 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -468,7 +468,7 @@ def _transaction_test(self): with self.pandasSQL.run_transaction() as trans: trans.execute(ins_sql) raise Exception('error') - except: + except Exception: # ignore raised exception pass res = self.pandasSQL.read_query('SELECT * FROM test_trans') diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 2bc44cb1c683f..ab3fdd8cbf84f 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -27,7 +27,7 @@ import scipy _is_scipy_ge_0190 = (LooseVersion(scipy.__version__) >= LooseVersion('0.19.0')) -except: +except ImportError: _is_scipy_ge_0190 = False From a5202130a4fccddbc1dc84ce50a977d66e4f4809 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 15:06:04 -0700 Subject: [PATCH 09/11] flake8 fixup --- pandas/_libs/skiplist.pxd | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/skiplist.pxd b/pandas/_libs/skiplist.pxd index 5a23813039f44..78f206962bcfc 100644 --- a/pandas/_libs/skiplist.pxd +++ b/pandas/_libs/skiplist.pxd @@ -4,7 +4,6 @@ from cython cimport Py_ssize_t - cdef extern from "src/skiplist.h": ctypedef struct node_t: node_t **next From f21efb9515a20d4d907f91e25c0faebb134b8d30 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 17:06:10 -0700 Subject: [PATCH 10/11] restore numpy cimports --- pandas/_libs/tslibs/ccalendar.pxd | 3 ++- pandas/_libs/tslibs/ccalendar.pyx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/ccalendar.pxd b/pandas/_libs/tslibs/ccalendar.pxd index 954e32f037356..04fb6eaf49c84 100644 --- a/pandas/_libs/tslibs/ccalendar.pxd +++ b/pandas/_libs/tslibs/ccalendar.pxd @@ -2,7 +2,8 @@ # cython: profile=False from cython cimport Py_ssize_t -from libc.stdint cimport int64_t, int32_t + +from numpy cimport int64_t, int32_t cdef int dayofweek(int y, int m, int d) nogil diff --git a/pandas/_libs/tslibs/ccalendar.pyx b/pandas/_libs/tslibs/ccalendar.pyx index eee1b6d116da9..12d35f7ce2f58 100644 --- a/pandas/_libs/tslibs/ccalendar.pyx +++ b/pandas/_libs/tslibs/ccalendar.pyx @@ -8,7 +8,7 @@ Cython implementations of functions resembling the stdlib calendar module cimport cython from cython cimport Py_ssize_t -from libc.stdint cimport int64_t, int32_t +from numpy cimport int64_t, int32_t from locale import LC_TIME from strptime import LocaleTime From 69eb78d6aac0f62daeeb696fae20226aa11e516e Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Mon, 23 Jul 2018 17:06:38 -0700 Subject: [PATCH 11/11] restore numpy cimport --- pandas/_libs/internals.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/_libs/internals.pyx b/pandas/_libs/internals.pyx index 776b383cbd8eb..68698f45d5623 100644 --- a/pandas/_libs/internals.pyx +++ b/pandas/_libs/internals.pyx @@ -3,8 +3,6 @@ cimport cython from cython cimport Py_ssize_t -from libc.stdint cimport int64_t - from cpython cimport PyObject from cpython.slice cimport PySlice_Check @@ -12,6 +10,7 @@ cdef extern from "Python.h": Py_ssize_t PY_SSIZE_T_MAX import numpy as np +from numpy cimport int64_t cdef extern from "compat_helper.h": cdef int slice_get_indices(PyObject* s, Py_ssize_t length,