Skip to content

Commit 918e89a

Browse files
committed
move to integration of logic
1 parent eab8bee commit 918e89a

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

databricks/koalas/base.py

+33
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,39 @@ def is_monotonic_decreasing(self):
363363
window = Window.orderBy(monotonically_increasing_id()).rowsBetween(-1, -1)
364364
return self._with_new_scol((col <= F.lag(col, 1).over(window)) & col.isNotNull()).all()
365365

366+
@property
367+
def ndim(self):
368+
"""
369+
Return an int representing the number of array dimensions.
370+
371+
Return 1 for Series / Index / MultiIndex.
372+
373+
Examples
374+
--------
375+
376+
For Series
377+
378+
>>> s = ks.Series([None, 1, 2, 3, 4], index=[4, 5, 2, 1, 8])
379+
>>> s.ndim
380+
1
381+
382+
For Index
383+
384+
>>> s.index.ndim
385+
1
386+
387+
For MultiIndex
388+
389+
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'],
390+
... ['speed', 'weight', 'length']],
391+
... [[0, 0, 0, 1, 1, 1, 2, 2, 2],
392+
... [1, 1, 1, 1, 1, 2, 1, 2, 2]])
393+
>>> s = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], index=midx)
394+
>>> s.index.ndim
395+
1
396+
"""
397+
return 1
398+
366399
def astype(self, dtype):
367400
"""
368401
Cast a Koalas object to a specified dtype ``dtype``.

databricks/koalas/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def ndim(self):
382382
"""
383383
Return an int representing the number of array dimensions.
384384
385-
Return 1 if Series. Otherwise return 2 if DataFrame.
385+
return 2 for DataFrame.
386386
387387
Examples
388388
--------

databricks/koalas/indexes.py

-21
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,6 @@ def names(self, names: List[Union[str, Tuple[str, ...]]]) -> None:
151151
names = [name if isinstance(name, tuple) else (name,) for name in names]
152152
self._kdf._internal = internal.copy(index_map=list(zip(internal.index_columns, names)))
153153

154-
@property
155-
def ndim(self):
156-
"""
157-
Number of dimensions of the underlying data, by definition 1.
158-
159-
Examples
160-
--------
161-
>>> s = ks.Series([None, 1, 2, 3, 4], index=[4, 5, 2, 1, 8])
162-
>>> s.index.ndim
163-
1
164-
165-
>>> midx = pd.MultiIndex([['lama', 'cow', 'falcon'],
166-
... ['speed', 'weight', 'length']],
167-
... [[0, 0, 0, 1, 1, 1, 2, 2, 2],
168-
... [1, 1, 1, 1, 1, 2, 1, 2, 2]])
169-
>>> s = ks.Series([45, 200, 1.2, 30, 250, 1.5, 320, 1, 0.3], index=midx)
170-
>>> s.index.ndim
171-
1
172-
"""
173-
return 1
174-
175154
def rename(self, name: Union[str, Tuple[str, ...]], inplace: bool = False):
176155
"""
177156
Alter Index name.

databricks/koalas/series.py

-5
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,6 @@ def shape(self):
821821
"""Return a tuple of the shape of the underlying data."""
822822
return len(self),
823823

824-
@property
825-
def ndim(self):
826-
"""Returns number of dimensions of the Series."""
827-
return 1
828-
829824
@property
830825
def name(self) -> Union[str, Tuple[str, ...]]:
831826
"""Return name of the Series."""

0 commit comments

Comments
 (0)