(df, schema, preserve_index, columns)
| 385 | |
| 386 | |
| 387 | def _get_columns_to_convert(df, schema, preserve_index, columns): |
| 388 | columns = _resolve_columns_of_interest(df, schema, columns) |
| 389 | |
| 390 | if not df.columns.is_unique: |
| 391 | raise ValueError( |
| 392 | f'Duplicate column names found: {list(df.columns)}' |
| 393 | ) |
| 394 | |
| 395 | if schema is not None: |
| 396 | return _get_columns_to_convert_given_schema(df, schema, preserve_index) |
| 397 | |
| 398 | column_names = [] |
| 399 | column_field_names = [] |
| 400 | |
| 401 | index_levels = ( |
| 402 | _get_index_level_values(df.index) if preserve_index is not False |
| 403 | else [] |
| 404 | ) |
| 405 | |
| 406 | columns_to_convert = [] |
| 407 | convert_fields = [] |
| 408 | |
| 409 | for name in columns: |
| 410 | col = df[name] |
| 411 | name = _column_name_to_strings(name) |
| 412 | |
| 413 | if _pandas_api.is_sparse(col): |
| 414 | raise TypeError( |
| 415 | f"Sparse pandas data (column {name}) not supported.") |
| 416 | |
| 417 | columns_to_convert.append(col) |
| 418 | convert_fields.append(None) |
| 419 | column_names.append(name) |
| 420 | column_field_names.append(str(name)) |
| 421 | |
| 422 | index_descriptors = [] |
| 423 | index_column_names = [] |
| 424 | for i, index_level in enumerate(index_levels): |
| 425 | name = _index_level_name( |
| 426 | index_level, i, column_names + index_column_names |
| 427 | ) |
| 428 | if (isinstance(index_level, _pandas_api.pd.RangeIndex) and |
| 429 | preserve_index is None): |
| 430 | descr = _get_range_index_descriptor(index_level) |
| 431 | else: |
| 432 | columns_to_convert.append(index_level) |
| 433 | convert_fields.append(None) |
| 434 | descr = name |
| 435 | index_column_names.append(name) |
| 436 | index_descriptors.append(descr) |
| 437 | |
| 438 | all_names = column_field_names + index_column_names |
| 439 | |
| 440 | # all_names : all of the columns in the resulting table including the data |
| 441 | # columns and serialized index columns |
| 442 | # column_names : the names of the data columns |
| 443 | # index_column_names : the names of the serialized index columns |
| 444 | # index_descriptors : descriptions of each index to be used for |
no test coverage detected