@@ -111,7 +111,10 @@ def _validate_data(
111111 return out
112112
113113 def _convert_X (
114- self , X : Union [np .ndarray , List [np .ndarray ]], concatenate_channels : bool = False
114+ self ,
115+ X : Union [np .ndarray , List [np .ndarray ]],
116+ pad_unequal : bool = False ,
117+ concatenate_channels : bool = False ,
115118 ) -> Union [np .ndarray , List [np .ndarray ]]:
116119 dtypes = self ._get_tags ()["X_types" ]
117120
@@ -123,9 +126,9 @@ def _convert_X(
123126 return X .reshape ((X .shape [0 ], - 1 ))
124127 else :
125128 raise ValueError (
126- "Can only convert 3D numpy array with 1 channel to 2D numpy "
127- f" array if concatenate_channels is True, found { X . shape [ 1 ] } "
128- " channels."
129+ "Can only convert 3D numpy array with more than 1 channel to "
130+ "2D numpy array if concatenate_channels is True, found "
131+ f" { X . shape [ 1 ] } channels."
129132 )
130133 elif dtypes [0 ] == "np_list" :
131134 return [x for x in X ]
@@ -142,6 +145,13 @@ def _convert_X(
142145 if "np_list" in dtypes :
143146 return X
144147 elif dtypes [0 ] == "3darray" :
148+ if not pad_unequal and not all (x .shape [1 ] == X [0 ].shape [1 ] for x in X ):
149+ raise ValueError (
150+ "Can only convert list of 2D numpy arrays with unequal length "
151+ "data to 3D numpy array if pad_unequal is True, found "
152+ "different series lengths."
153+ )
154+
145155 max_len = max (x .shape [1 ] for x in X )
146156 arr = np .zeros ((len (X ), X [0 ].shape [0 ], max_len ))
147157
@@ -151,6 +161,15 @@ def _convert_X(
151161 return arr
152162 elif dtypes [0 ] == "2darray" :
153163 if X [0 ].shape [0 ] == 1 or concatenate_channels :
164+ if not pad_unequal and not all (
165+ x .shape [1 ] == X [0 ].shape [1 ] for x in X
166+ ):
167+ raise ValueError (
168+ "Can only convert list of 2D numpy arrays with unequal "
169+ "length data to 2D numpy array if pad_unequal is True, "
170+ "found different series lengths."
171+ )
172+
154173 max_len = max (x .shape [1 ] for x in X )
155174 arr = np .zeros ((len (X ), X [0 ].shape [0 ], max_len ))
156175
@@ -160,9 +179,9 @@ def _convert_X(
160179 return arr .reshape ((arr .shape [0 ], - 1 ))
161180 else :
162181 raise ValueError (
163- "Can only convert list of 2D numpy arrays with 1 channel to 2D "
164- "numpy array if concatenate_channels is True, found "
165- f"{ X [0 ].shape [0 ]} channels."
182+ "Can only convert list of 2D numpy arrays with more than 1 "
183+ "channel to 2D numpy array if concatenate_channels is True, "
184+ f"found { X [0 ].shape [0 ]} channels."
166185 )
167186 else :
168187 raise ValueError (
0 commit comments