Skip to content

Commit 49c6935

Browse files
committed
- raise an error instead of printing a warning in from_frame()
- updated documentation of from_frame(), df_aslarray() and read_hdf()
1 parent 7385d3e commit 49c6935

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

larray/inout/hdf.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ def read_hdf(filepath_or_buffer, key, fill_value=nan, na=nan, sort_rows=False, s
3131
Value used to fill cells corresponding to label combinations which are not present in the input.
3232
Defaults to NaN.
3333
sort_rows : bool, optional
34-
Whether or not to sort the rows alphabetically (sorting is more efficient than not sorting). Defaults to False.
34+
Whether or not to sort the rows alphabetically.
35+
Must be False if the read array has been dumped with an larray version >= 0.30.
36+
Defaults to False.
3537
sort_columns : bool, optional
36-
Whether or not to sort the columns alphabetically (sorting is more efficient than not sorting).
38+
Whether or not to sort the columns alphabetically.
39+
Must be False if the read array has been dumped with an larray version >= 0.30.
3740
Defaults to False.
3841
name : str, optional
3942
Name of the axis or group to return. If None, name is set to passed key.

larray/inout/pandas.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo
152152
columns Index of the dataframe unless argument unfold_last_axis_name is set to True.
153153
sort_rows : bool, optional
154154
Whether or not to sort the rows alphabetically (sorting is more efficient than not sorting).
155-
Not used if `cartesian_prod` is False. Defaults to False.
155+
Must be False if `cartesian_prod` is set to True.
156+
Defaults to False.
156157
sort_columns : bool, optional
157158
Whether or not to sort the columns alphabetically (sorting is more efficient than not sorting).
158-
Not used if `cartesian_prod` is False. Defaults to False.
159+
Must be False if `cartesian_prod` is set to True.
160+
Defaults to False.
159161
parse_header : bool, optional
160162
Whether or not to parse columns labels. Pandas treats column labels as strings.
161163
If True, column labels are converted into int, float or boolean when possible. Defaults to False.
@@ -171,7 +173,8 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo
171173
cartesian_prod : bool, optional
172174
Whether or not to expand the dataframe to a cartesian product dataframe as needed by LArray.
173175
This is an expensive operation but is absolutely required if you cannot guarantee your dataframe is already
174-
well formed. Defaults to True.
176+
well formed. If True, arguments `sort_rows` and `sort_columns` must be set to False.
177+
Defaults to True.
175178
176179
Returns
177180
-------
@@ -233,8 +236,8 @@ def from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfo
233236
fill_value=fill_value, **kwargs)
234237
else:
235238
if sort_rows or sort_columns:
236-
import warnings
237-
warnings.warn('sort_rows and sort_columns are not used when cartesian_prod is set to False', stacklevel=2)
239+
raise ValueError('sort_rows and sort_columns cannot not be used when cartesian_prod is set to False. '
240+
'Please call the method sort_axes on the returned array to sort rows or columns')
238241
axes_labels = index_to_labels(df.index, sort=False)
239242

240243
# Pandas treats column labels as column names (strings) so we need to convert them to values
@@ -258,9 +261,12 @@ def df_aslarray(df, sort_rows=False, sort_columns=False, raw=False, parse_header
258261
df : Pandas DataFrame
259262
Input dataframe.
260263
sort_rows : bool, optional
261-
Whether or not to sort the rows alphabetically (sorting is more efficient than not sorting). Defaults to False.
264+
Whether or not to sort the rows alphabetically (sorting is more efficient than not sorting).
265+
Must be False if `cartesian_prod` is set to True.
266+
Defaults to False.
262267
sort_columns : bool, optional
263268
Whether or not to sort the columns alphabetically (sorting is more efficient than not sorting).
269+
Must be False if `cartesian_prod` is set to True.
264270
Defaults to False.
265271
raw : bool, optional
266272
Whether or not to consider the input dataframe as a raw dataframe, i.e. read without index at all.
@@ -275,7 +281,8 @@ def df_aslarray(df, sort_rows=False, sort_columns=False, raw=False, parse_header
275281
cartesian_prod : bool, optional
276282
Whether or not to expand the dataframe to a cartesian product dataframe as needed by LArray.
277283
This is an expensive operation but is absolutely required if you cannot guarantee your dataframe is already
278-
well formed. Defaults to True.
284+
well formed. If True, arguments `sort_rows` and `sort_columns` must be set to False.
285+
Defaults to True.
279286
280287
Returns
281288
-------

0 commit comments

Comments
 (0)