MCPcopy Create free account
hub / github.com/apache/arrow / _deserialize_column_index

Function _deserialize_column_index

python/pyarrow/pandas_compat.py:965–995  ·  view source on GitHub ↗
(block_table, all_columns, column_indexes)

Source from the content-addressed store, hash-verified

963
964
965def _deserialize_column_index(block_table, all_columns, column_indexes):
966 if all_columns:
967 columns_name_dict = {
968 c.get('field_name', _column_name_to_strings(c['name'])): c['name']
969 for c in all_columns
970 }
971 columns_values = [
972 columns_name_dict.get(name, name) for name in block_table.column_names
973 ]
974 else:
975 columns_values = block_table.column_names
976
977 # Construct the base index
978 if len(column_indexes) > 1:
979 # If we're passed multiple column indexes then evaluate with
980 # ast.literal_eval, since the column index values show up as a list of
981 # tuples
982 columns = _pandas_api.pd.MultiIndex.from_tuples(
983 list(map(ast.literal_eval, columns_values)),
984 names=[col_index['name'] for col_index in column_indexes],
985 )
986 else:
987 columns = _pandas_api.pd.Index(
988 columns_values, name=column_indexes[0]["name"] if column_indexes else None
989 )
990
991 # if we're reconstructing the index
992 if len(column_indexes) > 0:
993 columns = _reconstruct_columns_from_metadata(columns, column_indexes)
994
995 return columns
996
997
998def _reconstruct_index(table, index_descriptors, all_columns, types_mapper=None):

Callers 1

table_to_dataframeFunction · 0.85

Calls 6

_column_name_to_stringsFunction · 0.85
lenFunction · 0.85
listFunction · 0.85
mapFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected