Skip to content

Commit 25e648e

Browse files
Progress on pandas-dev#18419
1 parent 98e797a commit 25e648e

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

doc/source/conf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -565,19 +565,19 @@ def linkcode_resolve(domain, info):
565565
for part in fullname.split('.'):
566566
try:
567567
obj = getattr(obj, part)
568-
except:
568+
except AttributeError:
569569
return None
570570

571571
try:
572572
fn = inspect.getsourcefile(obj)
573-
except:
573+
except TypeError:
574574
fn = None
575575
if not fn:
576576
return None
577577

578578
try:
579579
source, lineno = inspect.getsourcelines(obj)
580-
except:
580+
except OSError:
581581
lineno = None
582582

583583
if lineno:

pandas/compat/pickle_compat.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def load_reduce(self):
3333
cls = args[0]
3434
stack[-1] = object.__new__(cls)
3535
return
36-
except:
36+
except Exception:
3737
pass
3838

3939
# try to re-encode the arguments
@@ -44,7 +44,7 @@ def load_reduce(self):
4444
try:
4545
stack[-1] = func(*args)
4646
return
47-
except:
47+
except Exception:
4848
pass
4949

5050
# unknown exception, re-raise
@@ -182,7 +182,7 @@ def load_newobj_ex(self):
182182

183183
try:
184184
Unpickler.dispatch[pkl.NEWOBJ_EX[0]] = load_newobj_ex
185-
except:
185+
except Exception:
186186
pass
187187

188188

@@ -200,15 +200,11 @@ def load(fh, encoding=None, compat=False, is_verbose=False):
200200
compat: provide Series compatibility mode, boolean, default False
201201
is_verbose: show exception output
202202
"""
203+
fh.seek(0)
204+
if encoding is not None:
205+
up = Unpickler(fh, encoding=encoding)
206+
else:
207+
up = Unpickler(fh)
208+
up.is_verbose = is_verbose
203209

204-
try:
205-
fh.seek(0)
206-
if encoding is not None:
207-
up = Unpickler(fh, encoding=encoding)
208-
else:
209-
up = Unpickler(fh)
210-
up.is_verbose = is_verbose
211-
212-
return up.load()
213-
except:
214-
raise
210+
return up.load()

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3161,7 +3161,7 @@ def _ensure_valid_index(self, value):
31613161
if not len(self.index) and is_list_like(value):
31623162
try:
31633163
value = Series(value)
3164-
except:
3164+
except ValueError:
31653165
raise ValueError('Cannot set a frame with no defined index '
31663166
'and a value that cannot be converted to a '
31673167
'Series')
@@ -7598,7 +7598,7 @@ def convert(v):
75987598
values = np.array([convert(v) for v in values])
75997599
else:
76007600
values = convert(values)
7601-
except:
7601+
except Exception:
76027602
values = convert(values)
76037603

76047604
else:

pandas/core/indexing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,7 @@ def _getitem_tuple(self, tup):
21462146
self._has_valid_tuple(tup)
21472147
try:
21482148
return self._getitem_lowerdim(tup)
2149-
except:
2149+
except IndexingError:
21502150
pass
21512151

21522152
retval = self.obj
@@ -2705,13 +2705,13 @@ def maybe_droplevels(index, key):
27052705
for _ in key:
27062706
try:
27072707
index = index.droplevel(0)
2708-
except:
2708+
except ValueError:
27092709
# we have dropped too much, so back out
27102710
return original_index
27112711
else:
27122712
try:
27132713
index = index.droplevel(0)
2714-
except:
2714+
except ValueError:
27152715
pass
27162716

27172717
return index

pandas/core/nanops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def reduction(values, axis=None, skipna=True):
503503
try:
504504
result = getattr(values, meth)(axis, dtype=dtype_max)
505505
result.fill(np.nan)
506-
except:
506+
except AttributeError:
507507
result = np.nan
508508
else:
509509
result = getattr(values, meth)(axis)

pandas/util/_print_versions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_sys_info():
2121
stdout=subprocess.PIPE,
2222
stderr=subprocess.PIPE)
2323
so, serr = pipe.communicate()
24-
except:
24+
except ValueError:
2525
pass
2626
else:
2727
if pipe.returncode == 0:
@@ -50,7 +50,7 @@ def get_sys_info():
5050
("LANG", "{lang}".format(lang=os.environ.get('LANG', "None"))),
5151
("LOCALE", '.'.join(map(str, locale.getlocale()))),
5252
])
53-
except:
53+
except Exception:
5454
pass
5555

5656
return blob
@@ -108,7 +108,7 @@ def show_versions(as_json=False):
108108
mod = importlib.import_module(modname)
109109
ver = ver_f(mod)
110110
deps_blob.append((modname, ver))
111-
except:
111+
except Exception:
112112
deps_blob.append((modname, None))
113113

114114
if (as_json):

pandas/util/_validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _check_for_default_values(fname, arg_val_dict, compat_args):
5959

6060
# could not compare them directly, so try comparison
6161
# using the 'is' operator
62-
except:
62+
except Exception:
6363
match = (arg_val_dict[key] is compat_args[key])
6464

6565
if not match:

0 commit comments

Comments
 (0)