From 19cc65db96a92e1f1cd54be4501cf36cf861e003 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 9 Oct 2015 21:07:01 -0400 Subject: [PATCH] use .values in index difference --- doc/source/whatsnew/v0.17.1.txt | 1 + pandas/core/index.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index d8e92b41c6593..58b136827a62b 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -136,6 +136,7 @@ Performance Improvements ~~~~~~~~~~~~~~~~~~~~~~~~ - Checking monotonic-ness before sorting on an index (:issue:`11080`) +- Performance improvements in ``Index.difference``, particularly for ``PeriodIndex`` (:issue:`11278`) - ``Series.dropna`` performance improvement when its dtype can't contain ``NaN`` (:issue:`11159`) - Release the GIL on most datetime field operations (e.g. ``DatetimeIndex.year``, ``Series.dt.year``), normalization, and conversion to and from ``Period``, ``DatetimeIndex.to_period`` and ``PeriodIndex.to_timestamp`` (:issue:`11263`) - Release the GIL on some rolling algos: ``rolling_median``, ``rolling_mean``, ``rolling_max``, ``rolling_min``, ``rolling_var``, ``rolling_kurt``, ``rolling_skew`` (:issue:`11450`) diff --git a/pandas/core/index.py b/pandas/core/index.py index fa23f2e1efe3f..d1f421fffb252 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -1711,12 +1711,12 @@ def difference(self, other): self._assert_can_do_setop(other) if self.equals(other): - return Index([], name=self.name) + return self._shallow_copy([]) other, result_name = self._convert_can_do_setop(other) - theDiff = sorted(set(self) - set(other)) - return Index(theDiff, name=result_name) + diff = sorted(set(self.values) - set(other.values)) + return self._shallow_copy(diff, name=result_name) diff = deprecate('diff', difference)