Skip to content

Commit

Permalink
move doctest to pytest for python3.5/3.6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
itholic committed Oct 18, 2019
1 parent 504ebe4 commit 9b5bee7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 48 deletions.
49 changes: 1 addition & 48 deletions databricks/koalas/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,54 +463,7 @@ def to_pandas(self) -> pd.MultiIndex:
# TODO: add 'name' parameter after pd.MultiIndex.name is implemented
def copy(self):
"""
Make a copy of this object. name sets those attributes on the new object.
Examples
--------
>>> midx = pd.MultiIndex([['a', 'b', 'c'],
... ['lama', 'cow', 'falcon'],
... ['speed', 'weight', 'length']],
... [[0, 0, 0, 0, 0, 0, 1, 1, 1],
... [0, 0, 0, 1, 1, 1, 2, 2, 2],
... [0, 0, 0, 0, 1, 2, 0, 1, 2]]
... )
>>> s = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3],
... index=midx)
>>> s
a lama speed 45.0
speed 200.0
speed 1.2
cow speed 30.0
weight 250.0
length 1.5
b falcon speed 320.0
weight 1.0
length 0.3
Name: 0, dtype: float64
>>> s.index
MultiIndex([('a', 'lama', 'speed'),
('a', 'lama', 'speed'),
('a', 'lama', 'speed'),
('a', 'cow', 'speed'),
('a', 'cow', 'weight'),
('a', 'cow', 'length'),
('b', 'falcon', 'speed'),
('b', 'falcon', 'weight'),
('b', 'falcon', 'length')],
)
>>> s.index.copy()
MultiIndex([('a', 'lama', 'speed'),
('a', 'lama', 'speed'),
('a', 'lama', 'speed'),
('a', 'cow', 'speed'),
('a', 'cow', 'weight'),
('a', 'cow', 'length'),
('b', 'falcon', 'speed'),
('b', 'falcon', 'weight'),
('b', 'falcon', 'length')],
)
Make a copy of this object.
"""
internal = self._kdf._internal.copy()
result = MultiIndex(ks.DataFrame(internal))
Expand Down
8 changes: 8 additions & 0 deletions databricks/koalas/tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ def test_multi_index_names(self):
with self.assertRaises(PandasNotImplementedError):
kidx.name = 'renamed'

def test_multi_index_copy(self):
arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
idx = pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
pdf = pd.DataFrame(np.random.randn(4, 5), idx)
kdf = ks.from_pandas(pdf)

self.assert_eq(kdf.index.copy(), pdf.index.copy())

def test_missing(self):
kdf = ks.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]})

Expand Down

0 comments on commit 9b5bee7

Please sign in to comment.