Skip to content

Commit 69eb269

Browse files
jbrockmendelJosiah Baker
authored and
Josiah Baker
committed
CLN: more Exceptions (pandas-dev#28642)
1 parent d676440 commit 69eb269

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

pandas/core/apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def wrap_results(self):
342342
results = self.results
343343

344344
# see if we can infer the results
345-
if len(results) > 0 and is_sequence(results[0]):
345+
if len(results) > 0 and 0 in results and is_sequence(results[0]):
346346

347347
return self.wrap_results_for_axis()
348348

pandas/core/indexes/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2588,8 +2588,9 @@ def intersection(self, other, sort=False):
25882588
try:
25892589
indexer = Index(rvals).get_indexer(lvals)
25902590
indexer = indexer.take((indexer != -1).nonzero()[0])
2591-
except Exception:
2592-
# duplicates
2591+
except (InvalidIndexError, IncompatibleFrequency):
2592+
# InvalidIndexError raised by get_indexer if non-unique
2593+
# IncompatibleFrequency raised by PeriodIndex.get_indexer
25932594
indexer = algos.unique1d(Index(rvals).get_indexer_non_unique(lvals)[0])
25942595
indexer = indexer[indexer != -1]
25952596

pandas/io/sql.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1591,10 +1591,7 @@ def execute(self, *args, **kwargs):
15911591
else:
15921592
cur = self.con.cursor()
15931593
try:
1594-
if kwargs:
1595-
cur.execute(*args, **kwargs)
1596-
else:
1597-
cur.execute(*args)
1594+
cur.execute(*args, **kwargs)
15981595
return cur
15991596
except Exception as exc:
16001597
try:

pandas/io/stata.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -2388,16 +2388,16 @@ def write_file(self):
23882388
self._write_map()
23892389
except Exception as exc:
23902390
self._close()
2391-
try:
2392-
if self._own_file:
2391+
if self._own_file:
2392+
try:
23932393
os.unlink(self._fname)
2394-
except Exception:
2395-
warnings.warn(
2396-
"This save was not successful but {0} could not "
2397-
"be deleted. This file is not "
2398-
"valid.".format(self._fname),
2399-
ResourceWarning,
2400-
)
2394+
except OSError:
2395+
warnings.warn(
2396+
"This save was not successful but {0} could not "
2397+
"be deleted. This file is not "
2398+
"valid.".format(self._fname),
2399+
ResourceWarning,
2400+
)
24012401
raise exc
24022402
else:
24032403
self._close()

0 commit comments

Comments
 (0)