Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
itholic committed Dec 13, 2019
2 parents 9d75621 + f1ae487 commit 8ae7722
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 65 deletions.
6 changes: 6 additions & 0 deletions databricks/koalas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ def isnull(self):
>>> ser.rename("a").to_frame().set_index("a").index.isna()
Index([False, False, True], dtype='object', name='a')
"""
from databricks.koalas.indexes import MultiIndex
if isinstance(self, MultiIndex):
raise NotImplementedError("isna is not defined for MultiIndex")
if isinstance(self.spark_type, (FloatType, DoubleType)):
return self._with_new_scol(self._scol.isNull() | F.isnan(self._scol)).rename(self.name)
else:
Expand Down Expand Up @@ -599,6 +602,9 @@ def notnull(self):
>>> ser.rename("a").to_frame().set_index("a").index.notna()
Index([True, True, False], dtype='object', name='a')
"""
from databricks.koalas.indexes import MultiIndex
if isinstance(self, MultiIndex):
raise NotImplementedError("notna is not defined for MultiIndex")
return (~self.isnull()).rename(self.name)

notna = notnull
Expand Down
92 changes: 27 additions & 65 deletions databricks/koalas/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,31 @@ def _unfold(key, kseries):
return rows_sel, cols_sel


class AtIndexer(object):
class _IndexerLike(object):

def __init__(self, kdf_or_kser):
from databricks.koalas.frame import DataFrame
from databricks.koalas.series import Series
assert isinstance(kdf_or_kser, (DataFrame, Series)), \
'unexpected argument type: {}'.format(type(kdf_or_kser))
self._kdf_or_kser = kdf_or_kser

@property
def _is_df(self):
from databricks.koalas.frame import DataFrame
return isinstance(self._kdf_or_kser, DataFrame)

@property
def _is_series(self):
from databricks.koalas.series import Series
return isinstance(self._kdf_or_kser, Series)

@property
def _internal(self):
return self._kdf_or_kser._internal


class AtIndexer(_IndexerLike):
"""
Access a single value for a row/column label pair.
If the index is not unique, all matching pairs are returned as an array.
Expand Down Expand Up @@ -122,26 +146,6 @@ class AtIndexer(object):
>>> kdf.at[5, 'B']
array([ 4, 20])
"""
def __init__(self, kdf_or_kser):
from databricks.koalas.frame import DataFrame
from databricks.koalas.series import Series
assert isinstance(kdf_or_kser, (DataFrame, Series)), \
'unexpected argument type: {}'.format(type(kdf_or_kser))
self._kdf_or_kser = kdf_or_kser

@property
def _is_df(self):
from databricks.koalas.frame import DataFrame
return isinstance(self._kdf_or_kser, DataFrame)

@property
def _is_series(self):
from databricks.koalas.series import Series
return isinstance(self._kdf_or_kser, Series)

@property
def _internal(self):
return self._kdf_or_kser._internal

def __getitem__(self, key):
if self._is_df:
Expand Down Expand Up @@ -181,7 +185,7 @@ def __getitem__(self, key):
or len(values) > 1) else values[0]


class LocIndexer(object):
class LocIndexer(_IndexerLike):
"""
Access a group of rows and columns by label(s) or a boolean Series.
Expand Down Expand Up @@ -357,27 +361,6 @@ class LocIndexer(object):
9 7 8
"""

def __init__(self, kdf_or_kser):
from databricks.koalas.frame import DataFrame
from databricks.koalas.series import Series
assert isinstance(kdf_or_kser, (DataFrame, Series)), \
'unexpected argument type: {}'.format(type(kdf_or_kser))
self._kdf_or_kser = kdf_or_kser

@property
def _is_df(self):
from databricks.koalas.frame import DataFrame
return isinstance(self._kdf_or_kser, DataFrame)

@property
def _is_series(self):
from databricks.koalas.series import Series
return isinstance(self._kdf_or_kser, Series)

@property
def _internal(self):
return self._kdf_or_kser._internal

def __getitem__(self, key):
from databricks.koalas.frame import DataFrame
from databricks.koalas.series import Series
Expand Down Expand Up @@ -563,7 +546,7 @@ def __setitem__(self, key, value):
self._kdf_or_kser[col_sel] = value


class ILocIndexer(object):
class ILocIndexer(_IndexerLike):
"""
Purely integer-location based indexing for selection by position.
Expand Down Expand Up @@ -677,27 +660,6 @@ class ILocIndexer(object):
2 1000 3000
"""

def __init__(self, kdf_or_kser):
from databricks.koalas.frame import DataFrame
from databricks.koalas.series import Series
assert isinstance(kdf_or_kser, (DataFrame, Series)), \
'unexpected argument type: {}'.format(type(kdf_or_kser))
self._kdf_or_kser = kdf_or_kser

@property
def _is_df(self):
from databricks.koalas.frame import DataFrame
return isinstance(self._kdf_or_kser, DataFrame)

@property
def _is_series(self):
from databricks.koalas.series import Series
return isinstance(self._kdf_or_kser, Series)

@property
def _internal(self):
return self._kdf_or_kser._internal

def __getitem__(self, key):
from databricks.koalas.frame import DataFrame
from databricks.koalas.indexes import Index
Expand Down
23 changes: 23 additions & 0 deletions databricks/koalas/tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,26 @@ def test_sort_values(self):

self.assert_eq(pidx.sort_values(), kidx.sort_values())
self.assert_eq(pidx.sort_values(ascending=False), kidx.sort_values(ascending=False))

def test_multiindex_isna(self):
kidx = ks.MultiIndex.from_tuples([('a', 'x', 1), ('b', 'y', 2), ('c', 'z', 3)])

with self.assertRaisesRegex(
NotImplementedError,
"isna is not defined for MultiIndex"):
kidx.isna()

with self.assertRaisesRegex(
NotImplementedError,
"isna is not defined for MultiIndex"):
kidx.isnull()

with self.assertRaisesRegex(
NotImplementedError,
"notna is not defined for MultiIndex"):
kidx.notna()

with self.assertRaisesRegex(
NotImplementedError,
"notna is not defined for MultiIndex"):
kidx.notnull()

0 comments on commit 8ae7722

Please sign in to comment.