112112from larray .utils import (table2str , size2str , unique , csv_open , unzip , long ,
113113 decode , basestring , unicode , bytes , izip , rproduct ,
114114 ReprString , duplicates , array_lookup2 , strip_rows ,
115- skip_comment_cells , find_closing_chr , PY3 )
115+ skip_comment_cells , find_closing_chr , StringIO , PY3 )
116+
116117
117118def _range_to_slice (seq , length = None ):
118119 """
@@ -9165,7 +9166,7 @@ def from_lists(data, nb_index=None, index_col=None):
91659166 return df_aslarray (df , raw = index_col is None , parse_header = False )
91669167
91679168
9168- def from_string (s , nb_index = None , index_col = None , sep = ',' ):
9169+ def from_string (s , nb_index = None , index_col = None , sep = ',' , ** kwargs ):
91699170 """Create an array from a multi-line string.
91709171
91719172 Parameters
@@ -9179,14 +9180,18 @@ def from_string(s, nb_index=None, index_col=None, sep=','):
91799180 List of columns for the index (ex. [0, 1, 2, 3]). Defaults to None (see nb_index above).
91809181 sep : str
91819182 delimiter used to split each line into cells.
9183+ \**kwargs
9184+ See arguments of Pandas read_csv function.
91829185
91839186 Returns
91849187 -------
91859188 LArray
91869189
91879190 Examples
91889191 --------
9189-
9192+ >>> from_string("sex,M,F\\ n,0,1")
9193+ sex | M | F
9194+ | 0 | 1
91909195 >>> from_string("nat\\ sex,M,F\\ nBE,0,1\\ nFO,2,3")
91919196 nat\sex | M | F
91929197 BE | 0 | 1
@@ -9200,6 +9205,16 @@ def from_string(s, nb_index=None, index_col=None, sep=','):
92009205 nat\sex | M | F
92019206 BE | 0 | 1
92029207 FO | 2 | 3
9208+ >>> from_string('''age,nat\\ sex, M, F
9209+ ... 0, BE, 0, 1
9210+ ... 0, FO, 2, 3
9211+ ... 1, BE, 4, 5
9212+ ... 1, FO, 6, 7''')
9213+ age | nat\sex | M | F
9214+ 0 | BE | 0 | 1
9215+ 0 | FO | 2 | 3
9216+ 1 | BE | 4 | 5
9217+ 1 | FO | 6 | 7
92039218
92049219 Empty lines at the beginning or end are ignored, so one can also format the string like this:
92059220
@@ -9212,9 +9227,8 @@ def from_string(s, nb_index=None, index_col=None, sep=','):
92129227 BE | 0 | 1
92139228 FO | 2 | 3
92149229 """
9215- data = [[cell .strip () for cell in line .split (sep )]
9216- for line in s .strip ().splitlines ()]
9217- return from_lists (data , nb_index = nb_index , index_col = index_col )
9230+
9231+ return read_csv (StringIO (s ), nb_index = nb_index , index_col = index_col , sep = sep , skipinitialspace = True , ** kwargs )
92189232
92199233
92209234def read_csv (filepath , nb_index = None , index_col = None , sep = ',' , headersep = None , na = np .nan ,
0 commit comments