Skip to content

Commit 7797815

Browse files
authored
Revert "Implement symmetric_difference of Index & MultiIndex (#953)"
This reverts commit 5c59a82.
1 parent 5c59a82 commit 7797815

File tree

3 files changed

+2
-164
lines changed

3 files changed

+2
-164
lines changed

databricks/koalas/indexes.py

Lines changed: 0 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from databricks.koalas.internal import _InternalFrame
3737
from databricks.koalas.missing.indexes import _MissingPandasLikeIndex, _MissingPandasLikeMultiIndex
3838
from databricks.koalas.series import Series
39-
from databricks.koalas.internal import _InternalFrame
4039
from databricks.koalas.utils import name_like_string
4140

4241

@@ -465,70 +464,6 @@ def copy(self, name=None):
465464
result.name = name
466465
return result
467466

468-
def symmetric_difference(self, other, result_name=None, sort=None):
469-
"""
470-
Compute the symmetric difference of two Index objects.
471-
472-
Parameters
473-
----------
474-
other : Index or array-like
475-
result_name : str
476-
sort : True or None, default None
477-
Whether to sort the resulting index.
478-
* True : Attempt to sort the result.
479-
* None : Do not sort the result.
480-
481-
Returns
482-
-------
483-
symmetric_difference : Index
484-
485-
Notes
486-
-----
487-
``symmetric_difference`` contains elements that appear in either
488-
``idx1`` or ``idx2`` but not both. Equivalent to the Index created by
489-
``idx1.difference(idx2) | idx2.difference(idx1)`` with duplicates
490-
dropped.
491-
492-
Examples
493-
--------
494-
>>> s1 = ks.Series([1, 2, 3, 4], index=[1, 2, 3, 4])
495-
>>> s2 = ks.Series([1, 2, 3, 4], index=[2, 3, 4, 5])
496-
497-
>>> s1.index.symmetric_difference(s2.index)
498-
Int64Index([5, 1], dtype='int64')
499-
500-
You can set name of result Index.
501-
502-
>>> s1.index.symmetric_difference(s2.index, result_name='koalas')
503-
Int64Index([5, 1], dtype='int64', name='koalas')
504-
505-
You can set sort to `True`, if you want to sort the resulting index.
506-
507-
>>> s1.index.symmetric_difference(s2.index, sort=True)
508-
Int64Index([1, 5], dtype='int64')
509-
510-
You can also use the ``^`` operator:
511-
512-
>>> s1.index ^ s2.index
513-
Int64Index([5, 1], dtype='int64')
514-
"""
515-
sdf_self = self._kdf._sdf.select(self._internal.index_scols)
516-
sdf_other = other._kdf._sdf.select(other._internal.index_scols)
517-
518-
sdf_symdiff = sdf_self.union(sdf_other) \
519-
.subtract(sdf_self.intersect(sdf_other))
520-
521-
if sort:
522-
sdf_symdiff = sdf_symdiff.sort(self._internal.index_scols)
523-
524-
internal = self._kdf._internal.copy(sdf=sdf_symdiff)
525-
result = Index(DataFrame(internal))
526-
527-
if result_name:
528-
result.name = result_name
529-
530-
return result
531-
532467
def __getattr__(self, item: str) -> Any:
533468
if hasattr(_MissingPandasLikeIndex, item):
534469
property_or_func = getattr(_MissingPandasLikeIndex, item)
@@ -556,9 +491,6 @@ def __repr__(self):
556491
def __iter__(self):
557492
return _MissingPandasLikeIndex.__iter__(self)
558493

559-
def __xor__(self, other):
560-
return self.symmetric_difference(other)
561-
562494

563495
class MultiIndex(Index):
564496
"""
@@ -717,88 +649,6 @@ def copy(self):
717649
result = MultiIndex(ks.DataFrame(internal))
718650
return result
719651

720-
def symmetric_difference(self, other, result_name=None, sort=None):
721-
"""
722-
Compute the symmetric difference of two MultiIndex objects.
723-
724-
Parameters
725-
----------
726-
other : Index or array-like
727-
result_name : list
728-
sort : True or None, default None
729-
Whether to sort the resulting index.
730-
* True : Attempt to sort the result.
731-
* None : Do not sort the result.
732-
733-
Returns
734-
-------
735-
symmetric_difference : MiltiIndex
736-
737-
Notes
738-
-----
739-
``symmetric_difference`` contains elements that appear in either
740-
``idx1`` or ``idx2`` but not both. Equivalent to the Index created by
741-
``idx1.difference(idx2) | idx2.difference(idx1)`` with duplicates
742-
dropped.
743-
744-
Examples
745-
--------
746-
>>> midx1 = pd.MultiIndex([['lama', 'cow', 'falcon'],
747-
... ['speed', 'weight', 'length']],
748-
... [[0, 0, 0, 1, 1, 1, 2, 2, 2],
749-
... [0, 0, 0, 0, 1, 2, 0, 1, 2]])
750-
>>> midx2 = pd.MultiIndex([['koalas', 'cow', 'falcon'],
751-
... ['speed', 'weight', 'length']],
752-
... [[0, 0, 0, 1, 1, 1, 2, 2, 2],
753-
... [0, 0, 0, 0, 1, 2, 0, 1, 2]])
754-
>>> s1 = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
755-
... index=midx1)
756-
>>> s2 = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
757-
... index=midx2)
758-
759-
>>> s1.index.symmetric_difference(s2.index) # doctest: +SKIP
760-
MultiIndex([('koalas', 'speed'),
761-
( 'lama', 'speed')],
762-
)
763-
764-
You can set names of result Index.
765-
766-
>>> s1.index.symmetric_difference(s2.index, result_name=['a', 'b']) # doctest: +SKIP
767-
MultiIndex([('koalas', 'speed'),
768-
( 'lama', 'speed')],
769-
names=['a', 'b'])
770-
771-
You can set sort to `True`, if you want to sort the resulting index.
772-
773-
>>> s1.index.symmetric_difference(s2.index, sort=True) # doctest: +SKIP
774-
MultiIndex([('koalas', 'speed'),
775-
( 'lama', 'speed')],
776-
)
777-
778-
You can also use the ``^`` operator:
779-
780-
>>> s1.index ^ s2.index # doctest: +SKIP
781-
MultiIndex([('koalas', 'speed'),
782-
( 'lama', 'speed')],
783-
)
784-
"""
785-
sdf_self = self._kdf._sdf.select(self._internal.index_scols)
786-
sdf_other = other._kdf._sdf.select(other._internal.index_scols)
787-
788-
sdf_symdiff = sdf_self.union(sdf_other) \
789-
.subtract(sdf_self.intersect(sdf_other))
790-
791-
if sort:
792-
sdf_symdiff = sdf_symdiff.sort(self._internal.index_scols)
793-
794-
internal = self._kdf._internal.copy(sdf=sdf_symdiff)
795-
result = MultiIndex(DataFrame(internal))
796-
797-
if result_name:
798-
result.names = result_name
799-
800-
return result
801-
802652
def __getattr__(self, item: str) -> Any:
803653
if hasattr(_MissingPandasLikeMultiIndex, item):
804654
property_or_func = getattr(_MissingPandasLikeMultiIndex, item)

databricks/koalas/missing/indexes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class _MissingPandasLikeIndex(object):
9292
sort = unsupported_function('sort')
9393
sort_values = unsupported_function('sort_values')
9494
sortlevel = unsupported_function('sortlevel')
95+
symmetric_difference = unsupported_function('symmetric_difference')
9596
take = unsupported_function('take')
9697
to_flat_index = unsupported_function('to_flat_index')
9798
to_frame = unsupported_function('to_frame')
@@ -198,6 +199,7 @@ class _MissingPandasLikeMultiIndex(object):
198199
sort_values = unsupported_function('sort_values')
199200
sortlevel = unsupported_function('sortlevel')
200201
swaplevel = unsupported_function('swaplevel')
202+
symmetric_difference = unsupported_function('symmetric_difference')
201203
take = unsupported_function('take')
202204
to_flat_index = unsupported_function('to_flat_index')
203205
to_frame = unsupported_function('to_frame')

docs/source/reference/indexing.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ Conversion
5757

5858
.. _api.multiindex:
5959

60-
Combining / joining / set operations
61-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62-
.. autosummary::
63-
:toctree: api/
64-
65-
Index.symmetric_difference
66-
6760
Selecting
6861
~~~~~~~~~
6962
.. autosummary::
@@ -99,10 +92,3 @@ MultiIndex Modifying and computations
9992
:toctree: api/
10093

10194
Index.copy
102-
103-
MultiIndex Combining / joining / set operations
104-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105-
.. autosummary::
106-
:toctree: api/
107-
108-
MultiIndex.symmetric_difference

0 commit comments

Comments
 (0)