MCPcopy Index your code
hub / github.com/huggingface/datasets / __array__

Method __array__

src/datasets/features/features.py:881–899  ·  view source on GitHub ↗

Convert to NumPy Array. Note that Pandas expects a 1D array when dtype is set to object. But for other dtypes, the returned shape is the same as the one of ``data``. More info about pandas 1D requirement for PandasExtensionArray here: https://pandas.pydata.o

(self, dtype=None)

Source from the content-addressed store, hash-verified

879 self._dtype = PandasArrayExtensionDtype(data.dtype)
880
881 def __array__(self, dtype=None):
882 """
883 Convert to NumPy Array.
884 Note that Pandas expects a 1D array when dtype is set to object.
885 But for other dtypes, the returned shape is the same as the one of ``data``.
886
887 More info about pandas 1D requirement for PandasExtensionArray here:
888 https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.api.extensions.ExtensionArray.html#pandas.api.extensions.ExtensionArray
889
890 """
891 if dtype == np.dtype(object):
892 out = np.empty(len(self._data), dtype=object)
893 for i in range(len(self._data)):
894 out[i] = self._data[i]
895 return out
896 if dtype is None:
897 return self._data
898 else:
899 return self._data.astype(dtype)
900
901 def copy(self, deep: bool = False) -> "PandasArrayExtensionArray":
902 return PandasArrayExtensionArray(self._data, copy=True)

Callers

nothing calls this directly

Calls 1

dtypeMethod · 0.80

Tested by

no test coverage detected