diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 61d093d19e4be..d093d7a145382 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -342,7 +342,7 @@ def wrap_results(self): results = self.results # see if we can infer the results - if len(results) > 0 and is_sequence(results[0]): + if len(results) > 0 and 0 in results and is_sequence(results[0]): return self.wrap_results_for_axis() diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 62662edb692a7..8aff0bc19d68d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2588,8 +2588,9 @@ def intersection(self, other, sort=False): try: indexer = Index(rvals).get_indexer(lvals) indexer = indexer.take((indexer != -1).nonzero()[0]) - except Exception: - # duplicates + except (InvalidIndexError, IncompatibleFrequency): + # InvalidIndexError raised by get_indexer if non-unique + # IncompatibleFrequency raised by PeriodIndex.get_indexer indexer = algos.unique1d(Index(rvals).get_indexer_non_unique(lvals)[0]) indexer = indexer[indexer != -1] diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 44cb399336d62..b0683fb8b0dfb 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1591,10 +1591,7 @@ def execute(self, *args, **kwargs): else: cur = self.con.cursor() try: - if kwargs: - cur.execute(*args, **kwargs) - else: - cur.execute(*args) + cur.execute(*args, **kwargs) return cur except Exception as exc: try: diff --git a/pandas/io/stata.py b/pandas/io/stata.py index c67106e897727..0b674b556b2ee 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -2388,16 +2388,16 @@ def write_file(self): self._write_map() except Exception as exc: self._close() - try: - if self._own_file: + if self._own_file: + try: os.unlink(self._fname) - except Exception: - warnings.warn( - "This save was not successful but {0} could not " - "be deleted. This file is not " - "valid.".format(self._fname), - ResourceWarning, - ) + except OSError: + warnings.warn( + "This save was not successful but {0} could not " + "be deleted. This file is not " + "valid.".format(self._fname), + ResourceWarning, + ) raise exc else: self._close()