in core/maxframe/dataframe/utils.py [0:0]
def merge_index_value(to_merge_index_values: dict, store_data: bool = False):
"""
Merge index value according to their chunk index.
Parameters
----------
to_merge_index_values : dict
index to index_value
store_data : bool
store data in index_value
Returns
-------
merged_index_value
"""
pd_index = None
min_val, min_val_close, max_val, max_val_close = None, None, None, None
for _, chunk_index_value in sorted(to_merge_index_values.items()):
if pd_index is None:
pd_index = chunk_index_value.to_pandas()
min_val, min_val_close, max_val, max_val_close = (
chunk_index_value.min_val,
chunk_index_value.min_val_close,
chunk_index_value.max_val,
chunk_index_value.max_val_close,
)
else:
cur_pd_index = chunk_index_value.to_pandas()
if store_data or (
isinstance(pd_index, pd.RangeIndex)
and isinstance(cur_pd_index, pd.RangeIndex)
and cur_pd_index.step == pd_index.step
and cur_pd_index.start == pd_index.stop
):
# range index that is continuous
pd_index = pd_index.append(cur_pd_index)
else:
pd_index = pd.Index([], dtype=pd_index.dtype)
if chunk_index_value.min_val is not None:
try:
if min_val is None or min_val > chunk_index_value.min_val:
min_val = chunk_index_value.min_val
min_val_close = chunk_index_value.min_val_close
except TypeError:
# min_value has different types that cannot compare
# just stop compare
continue
if chunk_index_value.max_val is not None:
if max_val is None or max_val < chunk_index_value.max_val:
max_val = chunk_index_value.max_val
max_val_close = chunk_index_value.max_val_close
index_value = parse_index(pd_index, store_data=store_data)
if not index_value.has_value():
index_value._index_value._min_val = min_val
index_value._index_value._min_val_close = min_val_close
index_value._index_value._max_val = max_val
index_value._index_value._max_val_close = max_val_close
return index_value