mirror of
https://github.com/echemdata/galvani.git
synced 2025-12-14 09:15:34 +00:00
Remove str3 compatibility function
This commit is contained in:
@@ -10,17 +10,10 @@ from os import SEEK_SET
|
|||||||
import time
|
import time
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from collections import defaultdict, OrderedDict
|
from collections import defaultdict, OrderedDict
|
||||||
import functools
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info.major <= 2:
|
|
||||||
str3 = str
|
|
||||||
else:
|
|
||||||
str3 = functools.partial(str, encoding='ascii')
|
|
||||||
|
|
||||||
|
|
||||||
def fieldname_to_dtype(fieldname):
|
def fieldname_to_dtype(fieldname):
|
||||||
"""Converts a column header from the MPT file into a tuple of
|
"""Converts a column header from the MPT file into a tuple of
|
||||||
canonical name and appropriate numpy dtype"""
|
canonical name and appropriate numpy dtype"""
|
||||||
@@ -53,7 +46,7 @@ def comma_converter(float_text):
|
|||||||
return float(float_text.translate(trans_table))
|
return float(float_text.translate(trans_table))
|
||||||
|
|
||||||
|
|
||||||
def MPTfile(file_or_path):
|
def MPTfile(file_or_path, encoding='ascii'):
|
||||||
"""Opens .mpt files as numpy record arrays
|
"""Opens .mpt files as numpy record arrays
|
||||||
|
|
||||||
Checks for the correct headings, skips any comments and returns a
|
Checks for the correct headings, skips any comments and returns a
|
||||||
@@ -80,7 +73,7 @@ def MPTfile(file_or_path):
|
|||||||
# make three lines. Every additional line is a comment line.
|
# make three lines. Every additional line is a comment line.
|
||||||
comments = [next(mpt_file) for i in range(nb_headers - 3)]
|
comments = [next(mpt_file) for i in range(nb_headers - 3)]
|
||||||
|
|
||||||
fieldnames = str3(next(mpt_file)).strip().split('\t')
|
fieldnames = next(mpt_file).decode(encoding).strip().split('\t')
|
||||||
record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames)))
|
record_type = np.dtype(list(map(fieldname_to_dtype, fieldnames)))
|
||||||
|
|
||||||
# Must be able to parse files where commas are used for decimal points
|
# Must be able to parse files where commas are used for decimal points
|
||||||
@@ -356,9 +349,9 @@ class MPRfile:
|
|||||||
self.npts = n_data_points
|
self.npts = n_data_points
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tm = time.strptime(str3(settings_mod['date']), '%m/%d/%y')
|
tm = time.strptime(settings_mod['date'].decode('ascii'), '%m/%d/%y')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
tm = time.strptime(str3(settings_mod['date']), '%m-%d-%y')
|
tm = time.strptime(settings_mod['date'].decode('ascii'), '%m-%d-%y')
|
||||||
self.startdate = date(tm.tm_year, tm.tm_mon, tm.tm_mday)
|
self.startdate = date(tm.tm_year, tm.tm_mon, tm.tm_mday)
|
||||||
|
|
||||||
if maybe_loop_module:
|
if maybe_loop_module:
|
||||||
@@ -374,9 +367,9 @@ class MPRfile:
|
|||||||
if maybe_log_module:
|
if maybe_log_module:
|
||||||
log_module, = maybe_log_module
|
log_module, = maybe_log_module
|
||||||
try:
|
try:
|
||||||
tm = time.strptime(str3(log_module['date']), '%m/%d/%y')
|
tm = time.strptime(log_module['date'].decode('ascii'), '%m/%d/%y')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
tm = time.strptime(str3(log_module['date']), '%m-%d-%y')
|
tm = time.strptime(log_module['date'].decode('ascii'), '%m-%d-%y')
|
||||||
self.enddate = date(tm.tm_year, tm.tm_mon, tm.tm_mday)
|
self.enddate = date(tm.tm_year, tm.tm_mon, tm.tm_mday)
|
||||||
|
|
||||||
# There is a timestamp at either 465 or 469 bytes
|
# There is a timestamp at either 465 or 469 bytes
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from numpy.testing import assert_array_almost_equal, assert_array_equal
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from galvani import BioLogic, MPTfile, MPRfile
|
from galvani import BioLogic, MPTfile, MPRfile
|
||||||
from galvani.BioLogic import MPTfileCSV, str3 # not exported
|
from galvani.BioLogic import MPTfileCSV # not exported
|
||||||
|
|
||||||
|
|
||||||
def test_open_MPT(testdata_dir):
|
def test_open_MPT(testdata_dir):
|
||||||
@@ -103,7 +103,7 @@ def timestamp_from_comments(comments):
|
|||||||
for line in comments:
|
for line in comments:
|
||||||
time_match = re.match(b'Acquisition started on : ([0-9/]+ [0-9:]+)', line)
|
time_match = re.match(b'Acquisition started on : ([0-9/]+ [0-9:]+)', line)
|
||||||
if time_match:
|
if time_match:
|
||||||
timestamp = datetime.strptime(str3(time_match.group(1)),
|
timestamp = datetime.strptime(time_match.group(1).decode('ascii'),
|
||||||
'%m/%d/%Y %H:%M:%S')
|
'%m/%d/%Y %H:%M:%S')
|
||||||
return timestamp
|
return timestamp
|
||||||
raise AttributeError("No timestamp in comments")
|
raise AttributeError("No timestamp in comments")
|
||||||
|
|||||||
Reference in New Issue
Block a user