Skip to content

Commit a51ce85

Browse files
committed
ugly hack to avoid anonymous axes converted as axes with name 'Unnamed: x' by pandas
1 parent 0f9589e commit a51ce85

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

larray/inout/pandas.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,18 @@ def df_asarray(df, sort_rows=False, sort_columns=False, raw=False, parse_header=
325325
series.name = df.index.name
326326
if sort_rows:
327327
raise ValueError('sort_rows=True is not valid for 1D arrays. Please use sort_columns instead.')
328-
return from_series(series, sort_rows=sort_columns)
328+
res = from_series(series, sort_rows=sort_columns)
329329
else:
330330
axes_names = [decode(name, 'utf8') if isinstance(name, basestring) else name
331331
for name in df.index.names]
332332
unfold_last_axis_name = isinstance(axes_names[-1], basestring) and '\\' in axes_names[-1]
333-
return from_frame(df, sort_rows=sort_rows, sort_columns=sort_columns, parse_header=parse_header,
334-
unfold_last_axis_name=unfold_last_axis_name, cartesian_prod=cartesian_prod, **kwargs)
333+
res = from_frame(df, sort_rows=sort_rows, sort_columns=sort_columns, parse_header=parse_header,
334+
unfold_last_axis_name=unfold_last_axis_name, cartesian_prod=cartesian_prod, **kwargs)
335+
336+
# ugly hack to avoid anonymous axes converted as axes with name 'Unnamed: x' by pandas
337+
# TODO : find a more robust and elegant solution
338+
res = res.rename({axis: None for axis in res.axes if isinstance(axis.name, basestring) and 'Unnamed' in axis.name})
339+
return res
335340

336341

337342
# #################################### #

0 commit comments

Comments
 (0)