Skip to content

Commit

Permalink
Add DataFrame.items (alias of iteritems) (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
HyukjinKwon authored Sep 19, 2019
1 parent 1f552bf commit 216e524
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from functools import partial, reduce
import sys
from itertools import zip_longest
from typing import Any, Optional, List, Tuple, Union, Generic, TypeVar
from typing import Any, Optional, List, Tuple, Union, Generic, TypeVar, Iterable

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -916,7 +916,7 @@ def corr(self, method='pearson'):
"""
return corr(self, method)

def iteritems(self):
def iteritems(self) -> Iterable:
"""
Iterator over (column name, Series) pairs.
Expand Down Expand Up @@ -958,6 +958,10 @@ def iteritems(self):
cols = list(self.columns)
return list((col_name, self[col_name]) for col_name in cols)

def items(self) -> Iterable:
"""This is an alias of ``iteritems``."""
return self.iteritems()

def to_clipboard(self, excel=True, sep=None, **kwargs):
"""
Copy object to the system clipboard.
Expand Down Expand Up @@ -5508,13 +5512,13 @@ def astype(self, dtype) -> 'DataFrame':
if col_name not in self.columns:
raise KeyError('Only a column name can be used for the '
'key in a dtype mappings argument.')
for col_name, col in self.iteritems():
for col_name, col in self.items():
if col_name in dtype:
results.append(col.astype(dtype=dtype[col_name]))
else:
results.append(col)
else:
for col_name, col in self.iteritems():
for col_name, col in self.items():
results.append(col.astype(dtype=dtype))
sdf = self._sdf.select(
self._internal.index_scols + list(map(lambda ser: ser._scol, results)))
Expand Down
1 change: 0 additions & 1 deletion databricks/koalas/missing/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class _MissingPandasLikeDataFrame(object):
info = unsupported_function('info')
insert = unsupported_function('insert')
interpolate = unsupported_function('interpolate')
items = unsupported_function('items')
iterrows = unsupported_function('iterrows')
itertuples = unsupported_function('itertuples')
keys = unsupported_function('keys')
Expand Down
1 change: 1 addition & 0 deletions docs/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Indexing, iteration
DataFrame.head
DataFrame.loc
DataFrame.iloc
DataFrame.items
DataFrame.iteritems
DataFrame.get

Expand Down

0 comments on commit 216e524

Please sign in to comment.