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

Function _deserialize_column_index

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

Source from the content-addressed store, hash-verified

948
949
950def _deserialize_column_index(block_table, all_columns, column_indexes):
951 if all_columns:
952 columns_name_dict = {
953 c.get('field_name', _column_name_to_strings(c['name'])): c['name']
954 for c in all_columns
955 }
956 columns_values = [
957 columns_name_dict.get(name, name) for name in block_table.column_names
958 ]
959 else:
960 columns_values = block_table.column_names
961
962 # Construct the base index
963 if len(column_indexes) > 1:
964 # If we're passed multiple column indexes then evaluate with
965 # ast.literal_eval, since the column index values show up as a list of
966 # tuples
967 columns = _pandas_api.pd.MultiIndex.from_tuples(
968 list(map(ast.literal_eval, columns_values)),
969 names=[col_index['name'] for col_index in column_indexes],
970 )
971 else:
972 columns = _pandas_api.pd.Index(
973 columns_values, name=column_indexes[0]["name"] if column_indexes else None
974 )
975
976 # if we're reconstructing the index
977 if len(column_indexes) > 0:
978 columns = _reconstruct_columns_from_metadata(columns, column_indexes)
979
980 return columns
981
982
983def _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