File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed
Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change @@ -165,22 +165,24 @@ def _classify_columns(
165165 Returns:
166166 A ColumnClassification object containing lists of column names for each category.
167167 """
168- # Maps column names to their structural category to simplify list building.
169- categories : dict [str , str ] = {}
170168
171- for col , dtype in dataframe .dtypes .items ():
172- col_name = str (col )
169+ def get_category (dtype : pd .api .extensions .ExtensionDtype ) -> str :
173170 pa_type = getattr (dtype , "pyarrow_dtype" , None )
171+ if pa_type :
172+ if pa .types .is_struct (pa_type ):
173+ return "struct"
174+ if pa .types .is_list (pa_type ):
175+ return (
176+ "array_of_struct"
177+ if pa .types .is_struct (pa_type .value_type )
178+ else "array"
179+ )
180+ return "clear"
174181
175- if not pa_type :
176- categories [col_name ] = "clear"
177- elif pa .types .is_struct (pa_type ):
178- categories [col_name ] = "struct"
179- elif pa .types .is_list (pa_type ):
180- is_struct_array = pa .types .is_struct (pa_type .value_type )
181- categories [col_name ] = "array_of_struct" if is_struct_array else "array"
182- else :
183- categories [col_name ] = "clear"
182+ # Maps column names to their structural category to simplify list building.
183+ categories = {
184+ str (col ): get_category (dtype ) for col , dtype in dataframe .dtypes .items ()
185+ }
184186
185187 return ColumnClassification (
186188 struct_columns = tuple (c for c , cat in categories .items () if cat == "struct" ),
You can’t perform that action at this time.
0 commit comments