Skip to content

Commit e6c23cb

Browse files
jbrockmendelvictor
authored and
victor
committed
[BLD] [CLN] Close assorted issues - bare exceptions, unused func (pandas-dev#22030)
1 parent 1ce5972 commit e6c23cb

13 files changed

+17
-65
lines changed

pandas/_libs/skiplist.pxd

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
from cython cimport Py_ssize_t
55

6-
from numpy cimport double_t
7-
86

97
cdef extern from "src/skiplist.h":
108
ctypedef struct node_t:
@@ -33,7 +31,7 @@ cdef extern from "src/skiplist.h":
3331
# Node itself not intended to be exposed.
3432
cdef class Node:
3533
cdef public:
36-
double_t value
34+
double value
3735
list next
3836
list width
3937

pandas/_libs/skiplist.pyx

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
from libc.math cimport log
1010

1111
import numpy as np
12-
cimport numpy as cnp
13-
from numpy cimport double_t
14-
cnp.import_array()
1512

1613

1714
# MSVC does not have log2!
@@ -26,11 +23,11 @@ from random import random
2623

2724
cdef class Node:
2825
# cdef public:
29-
# double_t value
26+
# double value
3027
# list next
3128
# list width
3229

33-
def __init__(self, double_t value, list next, list width):
30+
def __init__(self, double value, list next, list width):
3431
self.value = value
3532
self.next = next
3633
self.width = width

pandas/_libs/src/compat_helper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The full license is in the LICENSE file, distributed with this software.
1111
#define PANDAS__LIBS_SRC_COMPAT_HELPER_H_
1212

1313
#include "Python.h"
14-
#include "numpy_helper.h"
14+
#include "helper.h"
1515

1616
/*
1717
PySlice_GetIndicesEx changes signature in PY3

pandas/core/tools/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _validate_timedelta_unit(arg):
131131
""" provide validation / translation for timedelta short units """
132132
try:
133133
return _unit_map[arg]
134-
except:
134+
except (KeyError, TypeError):
135135
if arg is None:
136136
return 'ns'
137137
raise ValueError("invalid timedelta unit {arg} provided"

pandas/io/s3.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
try:
44
import s3fs
55
from botocore.exceptions import NoCredentialsError
6-
except:
6+
except ImportError:
77
raise ImportError("The s3fs library is required to handle s3 files")
88

99
if compat.PY3:

pandas/tests/frame/test_missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import scipy
2828
_is_scipy_ge_0190 = (LooseVersion(scipy.__version__) >=
2929
LooseVersion('0.19.0'))
30-
except:
30+
except ImportError:
3131
_is_scipy_ge_0190 = False
3232

3333

pandas/tests/io/generate_legacy_storage_files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def write_legacy_pickles(output_dir):
303303
# make sure we are < 0.13 compat (in py3)
304304
try:
305305
from pandas.compat import zip, cPickle as pickle # noqa
306-
except:
306+
except ImportError:
307307
import pickle
308308

309309
version = pandas.__version__

pandas/tests/io/test_pickle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def c_unpickler(path):
218218
with open(path, 'rb') as fh:
219219
fh.seek(0)
220220
return c_pickle.load(fh)
221-
except:
221+
except ImportError:
222222
c_pickler = None
223223
c_unpickler = None
224224

pandas/tests/io/test_sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def _transaction_test(self):
468468
with self.pandasSQL.run_transaction() as trans:
469469
trans.execute(ins_sql)
470470
raise Exception('error')
471-
except:
471+
except Exception:
472472
# ignore raised exception
473473
pass
474474
res = self.pandasSQL.read_query('SELECT * FROM test_trans')

pandas/tests/series/test_missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import scipy
2828
_is_scipy_ge_0190 = (LooseVersion(scipy.__version__) >=
2929
LooseVersion('0.19.0'))
30-
except:
30+
except ImportError:
3131
_is_scipy_ge_0190 = False
3232

3333

pandas/util/_decorators.py

-46
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pandas.compat import callable, signature, PY2
22
from pandas._libs.properties import cache_readonly # noqa
33
import inspect
4-
import types
54
import warnings
65
from textwrap import dedent, wrap
76
from functools import wraps, update_wrapper, WRAPPER_ASSIGNMENTS
@@ -339,48 +338,3 @@ def make_signature(func):
339338
if spec.keywords:
340339
args.append('**' + spec.keywords)
341340
return args, spec.args
342-
343-
344-
class docstring_wrapper(object):
345-
"""
346-
Decorator to wrap a function and provide
347-
a dynamically evaluated doc-string.
348-
349-
Parameters
350-
----------
351-
func : callable
352-
creator : callable
353-
return the doc-string
354-
default : str, optional
355-
return this doc-string on error
356-
"""
357-
_attrs = ['__module__', '__name__',
358-
'__qualname__', '__annotations__']
359-
360-
def __init__(self, func, creator, default=None):
361-
self.func = func
362-
self.creator = creator
363-
self.default = default
364-
update_wrapper(
365-
self, func, [attr for attr in self._attrs
366-
if hasattr(func, attr)])
367-
368-
def __get__(self, instance, cls=None):
369-
370-
# we are called with a class
371-
if instance is None:
372-
return self
373-
374-
# we want to return the actual passed instance
375-
return types.MethodType(self, instance)
376-
377-
def __call__(self, *args, **kwargs):
378-
return self.func(*args, **kwargs)
379-
380-
@property
381-
def __doc__(self):
382-
try:
383-
return self.creator()
384-
except Exception as exc:
385-
msg = self.default or str(exc)
386-
return msg

pandas/util/_print_versions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def show_versions(as_json=False):
114114
if (as_json):
115115
try:
116116
import json
117-
except:
117+
except ImportError:
118118
import simplejson as json
119119

120120
j = dict(system=dict(sys_info), dependencies=dict(deps_blob))

setup.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,12 @@ def get_tag(self):
438438

439439

440440
# enable coverage by building cython files by setting the environment variable
441-
# "PANDAS_CYTHON_COVERAGE" (with a Truthy value)
441+
# "PANDAS_CYTHON_COVERAGE" (with a Truthy value) or by running build_ext
442+
# with `--with-cython-coverage`enabled
442443
linetrace = os.environ.get('PANDAS_CYTHON_COVERAGE', False)
443-
CYTHON_TRACE = str(int(bool(linetrace)))
444+
if '--with-cython-coverage' in sys.argv:
445+
linetrace = True
446+
sys.argv.remove('--with-cython-coverage')
444447

445448
# Note: if not using `cythonize`, coverage can be enabled by
446449
# pinning `ext.cython_directives = directives` to each ext in extensions.

0 commit comments

Comments
 (0)