@@ -5057,26 +5057,22 @@ cdef class VariableShapeTensorArray(ExtensionArray):
50575057 """
50585058
50595059 @staticmethod
5060- def from_numpy_ndarray (obj , dim_names = None , permutation = None , uniform_shape = None ,
5061- value_type = None , ndim = None ):
5060+ def from_numpy_ndarray (obj , dim_names = None , permutation = None , uniform_shape = None ):
50625061 """
50635062 Convert a sequence of numpy.ndarrays to a variable shape tensor extension array.
50645063 The length of the input sequence becomes the length of the output array.
50655064
50665065 Parameters
50675066 ----------
50685067 obj : Sequence[numpy.ndarray]
5069- Sequence of ndarrays with matching dtype, ndim, and memory permutation.
5068+ Non-empty sequence of ndarrays with matching dtype, ndim, and
5069+ memory permutation.
50705070 dim_names : tuple or list of strings, default None
50715071 Explicit names to tensor dimensions.
50725072 permutation : tuple or list of integers, default None
50735073 Physical permutation for all input arrays. If None, inferred from strides.
50745074 uniform_shape : tuple or list of integers or None, default None
50755075 Optional known uniform dimensions in physical order. If None, inferred.
5076- value_type : pyarrow.DataType or numpy dtype, default None
5077- Optional explicit tensor value type. Required with empty input.
5078- ndim : int, default None
5079- Optional explicit tensor rank. Required with empty input.
50805076
50815077 Returns
50825078 -------
@@ -5095,56 +5091,23 @@ cdef class VariableShapeTensorArray(ExtensionArray):
50955091 cdef:
50965092 list arrays
50975093 list shape_rows
5098- int array_ndim
5094+ int ndim
50995095 int i
51005096 object base_dtype
51015097 DataType arrow_type
51025098 list normalized_permutation
51035099 list permutation_metadata
5104- DataType shape_type
51055100 Array values
51065101 Array shapes
51075102 StructArray struct_arr
51085103 VariableShapeTensorType ext_type
51095104
5110- if isinstance (obj, np.ndarray):
5111- raise TypeError (" obj must be a sequence of numpy arrays" )
51125105 if not isinstance (obj, Sequence) or isinstance (obj, (str , bytes)):
51135106 raise TypeError (" obj must be a sequence of numpy arrays" )
51145107 arrays = list (obj)
51155108
5116- if value_type is not None and not isinstance (value_type, DataType):
5117- try :
5118- value_type = from_numpy_dtype(np.dtype(value_type))
5119- except (TypeError , ValueError ) as exc:
5120- raise TypeError (
5121- " value_type must be a pyarrow.DataType or numpy dtype"
5122- ) from exc
5123-
51245109 if len (arrays) == 0 :
5125- if value_type is None or ndim is None :
5126- raise ValueError (
5127- " For empty input, both value_type and ndim must be provided" )
5128- if ndim < 0 :
5129- raise ValueError (" ndim must be non-negative" )
5130-
5131- _validate_dim_names(dim_names, ndim)
5132- permutation = _validate_permutation(permutation, ndim)
5133- _validate_uniform_shape(uniform_shape, ndim)
5134-
5135- shape_type = list_(int32(), list_size = ndim)
5136- values = array([], list_(value_type))
5137- shapes = array([], shape_type)
5138- struct_arr = StructArray.from_arrays(
5139- [values, shapes], names = [" data" , " shape" ])
5140- ext_type = variable_shape_tensor(
5141- value_type,
5142- ndim,
5143- dim_names = dim_names,
5144- permutation = permutation,
5145- uniform_shape = uniform_shape
5146- )
5147- return ExtensionArray.from_storage(ext_type, struct_arr)
5110+ raise ValueError (" Expected a non-empty sequence of ndarrays" )
51485111
51495112 for i, arr in enumerate (arrays):
51505113 if not isinstance (arr, np.ndarray):
@@ -5153,18 +5116,9 @@ cdef class VariableShapeTensorArray(ExtensionArray):
51535116 raise ValueError (" Cannot convert scalar to variable shape tensor array" )
51545117
51555118 base_dtype = arrays[0 ].dtype
5156- array_ndim = arrays[0 ].ndim
5119+ ndim = arrays[0 ].ndim
51575120 arrow_type = from_numpy_dtype(base_dtype)
51585121
5159- if value_type is not None and value_type != arrow_type:
5160- raise TypeError (
5161- f" numpy array dtype {base_dtype} does not match value_type {value_type}" )
5162-
5163- if ndim is not None and ndim != array_ndim:
5164- raise ValueError (
5165- f" ndim must match numpy arrays ndim ({array_ndim}). Got {ndim}." )
5166- ndim = array_ndim
5167-
51685122 for i, arr in enumerate (arrays[1 :], start = 1 ):
51695123 if arr.dtype != base_dtype:
51705124 raise TypeError (
0 commit comments