@@ -58,7 +58,12 @@ def load_from_ts_file(
5858 Examples
5959 --------
6060 >>> from tsml.datasets import load_from_ts_file
61- >>> X, y = load_from_ts_file("MinimalChinatown/MinimalChinatown_TRAIN.ts")
61+ >>> path = (
62+ ... "MinimalChinatown/MinimalChinatown_TRAIN.ts"
63+ ... if os.path.exists("MinimalChinatown/MinimalChinatown_TRAIN.ts") else
64+ ... "tsml/datasets/MinimalChinatown/MinimalChinatown_TRAIN.ts"
65+ ... )
66+ >>> X, y = load_from_ts_file(path)
6267 """
6368 # Initialize flags and variables used when parsing the file
6469 timestamps = False
@@ -100,7 +105,8 @@ def load_from_ts_file(
100105 tokens = line .split (" " )
101106 if len (tokens ) == 1 :
102107 raise IOError (
103- "Invalid .ts file. @problemname tag requires str value (the problems name)."
108+ "Invalid .ts file. @problemname tag requires str value "
109+ "(the problems name)."
104110 )
105111 elif line .startswith ("@timestamps" ):
106112 tokens = line .split (" " )
@@ -154,14 +160,16 @@ def load_from_ts_file(
154160 tokens = line .split (" " )
155161 if len (tokens ) != 2 :
156162 raise IOError (
157- "Invalid .ts file. @dimension tag requires a int value (the number of dimensions for the problem)."
163+ "Invalid .ts file. @dimension tag requires a int value "
164+ "(the number of dimensions for the problem)."
158165 )
159166
160167 try :
161168 dimensions = int (tokens [1 ])
162169 except ValueError :
163170 raise IOError (
164- "Invalid .ts file. @dimension tag requires a int value (the number of dimensions for the problem)."
171+ "Invalid .ts file. @dimension tag requires a int value "
172+ "(the number of dimensions for the problem)."
165173 )
166174
167175 dimensions_tag = True
@@ -185,21 +193,24 @@ def load_from_ts_file(
185193 tokens = line .split (" " )
186194 if len (tokens ) != 2 :
187195 raise IOError (
188- "Invalid .ts file. @serieslength tag requires a int value (the number of dimensions for the problem)."
196+ "Invalid .ts file. @serieslength tag requires a int value "
197+ "(the number of dimensions for the problem)."
189198 )
190199
191200 try :
192201 serieslength = int (tokens [1 ])
193202 except ValueError :
194203 raise IOError (
195- "Invalid .ts file. @serieslength tag requires a int value (the number of dimensions for the problem)."
204+ "Invalid .ts file. @serieslength tag requires a int value "
205+ "(the number of dimensions for the problem)."
196206 )
197207
198208 serieslength_tag = True
199209 elif line .startswith ("@targetlabel" ):
200210 if classlabels_tag :
201211 raise IOError (
202- "Invalid .ts file. @targetlabel tag cannot be used with @classlabel tag."
212+ "Invalid .ts file. @targetlabel tag cannot be used with "
213+ "@classlabel tag."
203214 )
204215
205216 tokens = line .split (" " )
@@ -219,14 +230,16 @@ def load_from_ts_file(
219230
220231 if token_len > 2 :
221232 raise IOError (
222- f"Invalid .ts file. @targetlabel tag should not be accompanied with info apart from True/False, but found { tokens } ."
233+ f"Invalid .ts file. @targetlabel tag should not be accompanied "
234+ f"with info apart from True/False, but found { tokens } ."
223235 )
224236
225237 targetlabels_tag = True
226238 elif line .startswith ("@classlabel" ):
227239 if targetlabels_tag :
228240 raise IOError (
229- "Invalid .ts file. @classlabel tag cannot be used with @targetlabel tag."
241+ "Invalid .ts file. @classlabel tag cannot be used with "
242+ "@targetlabel tag."
230243 )
231244
232245 tokens = line .split (" " )
@@ -246,12 +259,14 @@ def load_from_ts_file(
246259
247260 if not classlabel and token_len > 2 :
248261 raise IOError (
249- f"Invalid .ts file. @classlabel tag should not be accompanied with additional info when False, but found { tokens } ."
262+ f"Invalid .ts file. @classlabel tag should not be accompanied "
263+ f"with additional info when False, but found { tokens } ."
250264 )
251265
252266 elif classlabel and token_len == 2 :
253267 raise IOError (
254- "Invalid .ts file. @classlabel tag is true but no Class values are supplied."
268+ "Invalid .ts file. @classlabel tag is true but no Class values "
269+ "are supplied."
255270 )
256271
257272 class_label_list = [token .strip () for token in tokens [2 :]]
@@ -272,7 +287,8 @@ def load_from_ts_file(
272287
273288 if len (lines ) == data_start_line + 1 :
274289 raise IOError (
275- "Invalid .ts file. A @data tag is present but no subsequent data is present."
290+ "Invalid .ts file. A @data tag is present but no subsequent data "
291+ "is present."
276292 )
277293 else :
278294 first_line = lines [data_start_line ].split (":" )
@@ -284,7 +300,8 @@ def load_from_ts_file(
284300 has_labels = classlabel
285301 else :
286302 raise IOError (
287- "Unable to read .ts file. A @classlabel or @targetlabel tag is required."
303+ "Unable to read .ts file. A @classlabel or @targetlabel tag is "
304+ "required."
288305 )
289306
290307 # Equal length tag is required.
@@ -309,7 +326,8 @@ def load_from_ts_file(
309326 not timestamps_tag or (timestamps_tag and not timestamps )
310327 ) and has_timestamps :
311328 raise IOError (
312- "Value mismatch in .ts file. @timestamps tag is missing or False but data has timestamps. Timestamps are currently not supported."
329+ "Value mismatch in .ts file. @timestamps tag is missing or False "
330+ "but data has timestamps. Timestamps are currently not supported."
313331 )
314332 elif has_timestamps :
315333 raise IOError (
@@ -322,17 +340,20 @@ def load_from_ts_file(
322340 not univariate_tag or (univariate_tag and univariate )
323341 ) and data_dims > 1 :
324342 raise IOError (
325- "Value mismatch in .ts file. @univariate tag is missing or True but data has more than one dimension."
343+ "Value mismatch in .ts file. @univariate tag is missing or True "
344+ "but data has more than one dimension."
326345 )
327346
328347 if dimensions_tag and dimensions != data_dims :
329348 raise IOError (
330- f"Value mismatch in .ts file. @dimensions tag value { dimensions } and read number of dimensions { data_dims } do not match."
349+ f"Value mismatch in .ts file. @dimensions tag value { dimensions } "
350+ f"and read number of dimensions { data_dims } do not match."
331351 )
332352
333353 if serieslength_tag and serieslength != data_length :
334354 raise IOError (
335- f"Value mismatch in .ts file. @serieslength tag value { serieslength } and read series length { data_length } do not match."
355+ f"Value mismatch in .ts file. @serieslength tag value "
356+ f"{ serieslength } and read series length { data_length } do not match."
336357 )
337358
338359 if equallength :
@@ -390,7 +411,8 @@ def load_from_ts_file(
390411
391412 if not data_started :
392413 raise IOError (
393- "Invalid .ts file. File contains metadata but no @data tag to signal the start of data."
414+ "Invalid .ts file. File contains metadata but no @data tag to signal the "
415+ "start of data."
394416 )
395417
396418 if has_labels :
0 commit comments