Skip to content

Commit 63e7c1f

Browse files
committed
fix #497: fixed read_csv(sort_columns=True) for 1D arrays
1 parent 31272f2 commit 63e7c1f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/source/changes/version_0_26_1.rst.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ Fixes
1313
ambiguous with labels from other axes (closes :issue:`485`).
1414
1515
* fixed reading 1D arrays with non-string labels (closes :issue:`495`).
16+
17+
* fixed read_csv(sort_columns=True) for 1D arrays (closes :issue:`497`).

larray/inout/array.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ def df_aslarray(df, sort_rows=False, sort_columns=False, raw=False, parse_header
237237
df.columns = pd.Index([parse(cell) for cell in df.columns.values], name=df.columns.name)
238238
series = df.iloc[0]
239239
series.name = df.index.name
240-
return from_series(series, sort_rows=sort_rows)
240+
if sort_rows:
241+
raise ValueError('sort_rows=True is not valid for 1D arrays. Please use sort_columns instead.')
242+
return from_series(series, sort_rows=sort_columns)
241243
else:
242244
axes_names = [decode(name, 'utf8') for name in df.index.names]
243245
unfold_last_axis_name = isinstance(axes_names[-1], basestring) and '\\' in axes_names[-1]

larray/tests/test_array.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,6 +2497,10 @@ def test_read_csv(self):
24972497
res = read_csv(StringIO('a,1,2\n,0,1\n'))
24982498
assert_array_equal(res, ndrange('a=1,2'))
24992499

2500+
# sort_columns=True
2501+
res = read_csv(StringIO('a,a2,a0,a1\n,2,0,1\n'), sort_columns=True)
2502+
assert_array_equal(res, ndtest(3))
2503+
25002504
def test_read_eurostat(self):
25012505
la = read_eurostat(abspath('test5d_eurostat.csv'))
25022506
self.assertEqual(la.ndim, 5)

0 commit comments

Comments
 (0)