Skip to content

Commit

Permalink
Add slice functionality (ray-project#1832)
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-petersohn authored and robertnishihara committed Apr 16, 2018
1 parent f505f06 commit 3c817ad
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions python/ray/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2945,9 +2945,7 @@ def __getitem__(self, key):
# see if we can slice the rows
indexer = self._row_metadata.convert_to_index_sliceable(key)
if indexer is not None:
raise NotImplementedError("To contribute to Pandas on Ray, please"
"visit github.com/ray-project/ray.")
# return self._getitem_slice(indexer)
return self._getitem_slice(indexer)

if isinstance(key, (pd.Series, np.ndarray, pd.Index, list)):
return self._getitem_array(key)
Expand Down Expand Up @@ -3015,6 +3013,15 @@ def _getitem_indiv_col(self, key, part):
lambda df: df.__getitem__(index),
self._col_partitions[part])

def _getitem_slice(self, key):
new_cols = _map_partitions(lambda df: df[key],
self._col_partitions)

index = self.index[key]
return DataFrame(col_partitions=new_cols,
index=index,
columns=self.columns)

def __getattr__(self, key):
"""After regular attribute access, looks up the name in the columns
Expand Down

0 comments on commit 3c817ad

Please sign in to comment.