Skip to content

Commit 19cc65d

Browse files
committed
use .values in index difference
1 parent 43edd83 commit 19cc65d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

doc/source/whatsnew/v0.17.1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Performance Improvements
136136
~~~~~~~~~~~~~~~~~~~~~~~~
137137

138138
- Checking monotonic-ness before sorting on an index (:issue:`11080`)
139+
- Performance improvements in ``Index.difference``, particularly for ``PeriodIndex`` (:issue:`11278`)
139140
- ``Series.dropna`` performance improvement when its dtype can't contain ``NaN`` (:issue:`11159`)
140141
- 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`)
141142
- Release the GIL on some rolling algos: ``rolling_median``, ``rolling_mean``, ``rolling_max``, ``rolling_min``, ``rolling_var``, ``rolling_kurt``, ``rolling_skew`` (:issue:`11450`)

pandas/core/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,12 +1711,12 @@ def difference(self, other):
17111711
self._assert_can_do_setop(other)
17121712

17131713
if self.equals(other):
1714-
return Index([], name=self.name)
1714+
return self._shallow_copy([])
17151715

17161716
other, result_name = self._convert_can_do_setop(other)
17171717

1718-
theDiff = sorted(set(self) - set(other))
1719-
return Index(theDiff, name=result_name)
1718+
diff = sorted(set(self.values) - set(other.values))
1719+
return self._shallow_copy(diff, name=result_name)
17201720

17211721
diff = deprecate('diff', difference)
17221722

0 commit comments

Comments
 (0)