Skip to content

Commit 7f5e41e

Browse files
committed
(issue 563): bypass cartesian_product_df() and only call index_to_labels() when we know that the DataFrame read from an HDF5 file is a saved LArray object
1 parent 2bd4569 commit 7f5e41e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

larray/inout/hdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s
7474
_meta = attrs.metadata if 'metadata' in attrs else None
7575
if _type == 'Array':
7676
res = df_aslarray(pd_obj, sort_rows=sort_rows, sort_columns=sort_columns, fill_value=fill_value,
77-
parse_header=False)
77+
parse_header=False, dense=True)
7878
if _meta is not None:
7979
res.meta = _meta
8080
elif _type == 'Axis':

larray/inout/pandas.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo
211211
a1 b0 4 5
212212
a1 b1 6 7
213213
"""
214+
dense = kwargs.pop('dense', False)
214215
axes_names = [decode(name, 'utf8') for name in df.index.names]
215216

216217
# handle 2 or more dimensions with the last axis name given using \
@@ -223,8 +224,11 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo
223224
else:
224225
axes_names += [df.columns.name]
225226

226-
df, axes_labels = cartesian_product_df(df, sort_rows=sort_rows, sort_columns=sort_columns,
227-
fill_value=fill_value, **kwargs)
227+
if dense:
228+
axes_labels = index_to_labels(df.index, sort=sort_rows)
229+
else:
230+
df, axes_labels = cartesian_product_df(df, sort_rows=sort_rows, sort_columns=sort_columns,
231+
fill_value=fill_value, **kwargs)
228232

229233
# Pandas treats column labels as column names (strings) so we need to convert them to values
230234
last_axis_labels = [parse(cell) for cell in df.columns.values] if parse_header else list(df.columns.values)

0 commit comments

Comments
 (0)