Skip to content

Commit

Permalink
ENH: impl array protocol for series and index
Browse files Browse the repository at this point in the history
  • Loading branch information
UranusSeven committed Jun 16, 2023
1 parent f0f72c2 commit 6f9be17
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/xorbits/_mars/dataframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,16 @@ def __str__(self):
def __repr__(self):
return self._to_str(representation=True)

def _to_arr(self):
if len(self._executed_sessions) == 0:
raise NotImplementedError

data = self.fetch(session=self._executed_sessions[-1])
return np.asarray(data)

def __array__(self):
return self._to_arr()

def _to_mars_tensor(self, dtype=None, order="K", extract_multi_index=False):
tensor = self.to_tensor(extract_multi_index=extract_multi_index)
dtype = dtype if dtype is not None else tensor.dtype
Expand Down Expand Up @@ -1413,6 +1423,16 @@ def __str__(self):
def __repr__(self):
return self._to_str(representation=False)

def _to_arr(self):
if len(self._executed_sessions) == 0:
raise NotImplementedError

data = self.fetch(session=self._executed_sessions[-1])
return np.asarray(data)

def __array__(self):
return self._to_arr()

@property
def dtype(self):
return getattr(self, "_dtype", None) or getattr(self.op, "dtype", None)
Expand Down

0 comments on commit 6f9be17

Please sign in to comment.