Skip to content

Commit

Permalink
Interpret astype(object) as 'cast to an array of numpy arrays'
Browse files Browse the repository at this point in the history
  • Loading branch information
frreiss committed Jul 7, 2021
1 parent 5b1b9fb commit 3f54198
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions text_extensions_for_pandas/array/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ def astype(self, dtype, copy=True):
return dtype.construct_array_type()._from_sequence(values, copy=False)
else:
return values
elif pd.api.types.is_object_dtype(dtype):
# Interpret astype(object) as "cast to an array of numpy arrays"
values = np.empty(len(self), dtype=object)
for i in range(len(self)):
values[i] = self._tensor[i]
else:
values = self._tensor.astype(dtype, copy=copy)
return values
Expand Down

0 comments on commit 3f54198

Please sign in to comment.