File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -15,14 +15,19 @@ class Config:
15
15
16
16
@staticmethod
17
17
@validate_arguments
18
- def from_path (path : Path ):
18
+ def from_path (
19
+ path : Path ,
20
+ raise_on_malformed_data : bool = True ,
21
+ ):
19
22
"""
20
23
Loads positions from .kmm or .kmm2 file.
21
24
"""
22
25
if path .suffix == ".kmm" :
23
26
dataframe = kmm .positions .read_kmm (path )
24
27
elif path .suffix == ".kmm2" :
25
- dataframe = kmm .positions .read_kmm2 (path )
28
+ dataframe = kmm .positions .read_kmm2 (
29
+ path , raise_on_malformed_data = raise_on_malformed_data
30
+ )
26
31
else :
27
32
raise ValueError (f"Unable to parse file type { path .suffix } " )
28
33
@@ -42,7 +47,7 @@ def read_sync_adjust(
42
47
"""
43
48
header = kmm .Header .from_path (header_path , raise_on_malformed_data )
44
49
return (
45
- Positions .from_path (kmm_path )
50
+ Positions .from_path (kmm_path , raise_on_malformed_data )
46
51
.sync_frame_index (header , adjustment , raise_on_malformed_data )
47
52
.geodetic ()
48
53
)
Original file line number Diff line number Diff line change 46
46
47
47
48
48
@validate_arguments
49
- def read_kmm2 (path : Path ):
49
+ def read_kmm2 (path : Path , raise_on_malformed_data : bool = True ):
50
50
skiprows = [
51
51
index
52
52
for index , line in enumerate (path .read_text (encoding = "latin1" ).splitlines ())
53
53
if pattern .match (line ) or pattern2 .match (line )
54
54
]
55
-
55
+ with open (path , "r" , encoding = "latin1" ) as f :
56
+ line = f .readline ()
57
+ if line .startswith ("VER" ):
58
+ skiprows = [0 ] + skiprows
59
+ elif raise_on_malformed_data and not line .startswith ("POS" ):
60
+ raise ValueError ("Malformed data, first line is not POS or VER" )
56
61
try :
57
62
try :
58
63
df = pd .read_csv (
59
64
path ,
60
- skiprows = [ 0 ] + skiprows ,
65
+ skiprows = skiprows ,
61
66
delimiter = "\t " ,
62
67
encoding = "latin1" ,
63
68
low_memory = False ,
69
+ header = None ,
64
70
)
65
71
except pd .errors .EmptyDataError :
66
72
return pd .DataFrame (columns = expected_columns )
You can’t perform that action at this time.
0 commit comments