From 9b5bee74159dd6eb0855c98f2e8fa7e455285f55 Mon Sep 17 00:00:00 2001 From: itholic Date: Fri, 18 Oct 2019 18:57:56 +0900 Subject: [PATCH] move doctest to pytest for python3.5/3.6 compatibility --- databricks/koalas/indexes.py | 49 +------------------------ databricks/koalas/tests/test_indexes.py | 8 ++++ 2 files changed, 9 insertions(+), 48 deletions(-) diff --git a/databricks/koalas/indexes.py b/databricks/koalas/indexes.py index b3c2f79f1d..8b8322812c 100644 --- a/databricks/koalas/indexes.py +++ b/databricks/koalas/indexes.py @@ -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)) diff --git a/databricks/koalas/tests/test_indexes.py b/databricks/koalas/tests/test_indexes.py index fdfd23162b..ce5aa1f080 100644 --- a/databricks/koalas/tests/test_indexes.py +++ b/databricks/koalas/tests/test_indexes.py @@ -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]})