rewrote table module adjustments to not make use of _io module
This commit is contained in:
parent
db21e82fe3
commit
dd82c3c8f0
|
@ -2,7 +2,6 @@ import re
|
||||||
import copy
|
import copy
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Union, Optional, Tuple, List, TextIO
|
from typing import Union, Optional, Tuple, List, TextIO
|
||||||
from _io import TextIOWrapper
|
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
@ -240,13 +239,11 @@ class Table:
|
||||||
Table data from file.
|
Table data from file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(fname, TextIOWrapper):
|
if isinstance(fname, (str, pathlib.Path)):
|
||||||
f = fname
|
|
||||||
f.seek(0)
|
|
||||||
elif isinstance(fname, (str, pathlib.Path)):
|
|
||||||
f = open(fname)
|
f = open(fname)
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
f = fname
|
||||||
|
f.seek(0)
|
||||||
|
|
||||||
comments = []
|
comments = []
|
||||||
line = f.readline().strip()
|
line = f.readline().strip()
|
||||||
|
@ -299,13 +296,11 @@ class Table:
|
||||||
Table data from file.
|
Table data from file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(fname, TextIOWrapper):
|
if isinstance(fname, (str, pathlib.Path)):
|
||||||
f = fname
|
|
||||||
f.seek(0)
|
|
||||||
elif isinstance(fname, (str, pathlib.Path)):
|
|
||||||
f = open(fname)
|
f = open(fname)
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
f = fname
|
||||||
|
f.seek(0)
|
||||||
|
|
||||||
content = f.readlines()
|
content = f.readlines()
|
||||||
|
|
||||||
|
@ -573,12 +568,10 @@ class Table:
|
||||||
labels += [f'{util.srepr(self.shapes[l],"x")}:{i+1}_{l}' \
|
labels += [f'{util.srepr(self.shapes[l],"x")}:{i+1}_{l}' \
|
||||||
for i in range(np.prod(self.shapes[l]))]
|
for i in range(np.prod(self.shapes[l]))]
|
||||||
|
|
||||||
if isinstance(fname, TextIOWrapper):
|
if isinstance(fname, (str, pathlib.Path)):
|
||||||
fhandle = fname
|
|
||||||
elif isinstance(fname, (str, pathlib.Path)):
|
|
||||||
fhandle = open(fname,'w',newline='\n')
|
fhandle = open(fname,'w',newline='\n')
|
||||||
else:
|
else:
|
||||||
raise TypeError
|
fhandle = fname
|
||||||
|
|
||||||
fhandle.write('\n'.join([f'# {c}' for c in self.comments] + [' '.join(labels)])+'\n')
|
fhandle.write('\n'.join([f'# {c}' for c in self.comments] + [' '.join(labels)])+'\n')
|
||||||
self.data.to_csv(fhandle,sep=' ',na_rep='nan',index=False,header=False)
|
self.data.to_csv(fhandle,sep=' ',na_rep='nan',index=False,header=False)
|
||||||
|
|
Loading…
Reference in New Issue