Skip to content

[BLD] [CLN] Close assorted issues - bare exceptions, unused func #22030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 26, 2018
4 changes: 1 addition & 3 deletions pandas/_libs/skiplist.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from cython cimport Py_ssize_t

from numpy cimport double_t


cdef extern from "src/skiplist.h":
ctypedef struct node_t:
Expand Down Expand Up @@ -33,7 +31,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

Expand Down
7 changes: 2 additions & 5 deletions pandas/_libs/skiplist.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/src/compat_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/generate_legacy_storage_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
46 changes: 0 additions & 46 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -339,48 +338,3 @@ def make_signature(func):
if spec.keywords:
args.append('**' + spec.keywords)
return args, spec.args


class docstring_wrapper(object):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah was going to use this a while back, but didn't need

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
2 changes: 1 addition & 1 deletion pandas/util/_print_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down