Skip to content

Commit 2e5ae9e

Browse files
committed
Migrated modulo string formats to f-strings
1 parent c3afb9a commit 2e5ae9e

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/eyelinkio/edf/read.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class EDF(dict):
7272

7373
def __init__(self, fname):
7474
if not has_edfapi:
75-
raise OSError("Could not load EDF api: %s" % why_not)
75+
raise OSError(f"Could not load EDF api: {why_not}")
7676
info, discrete, times, samples = _read_raw_edf(fname)
7777
self.info = info
7878
self.info["filename"] = Path(fname).name
@@ -132,16 +132,15 @@ def __enter__(self):
132132
self.fid = edf_open_file(self.fname, 2, 1, 1, ct.byref(error_code))
133133
if self.fid is None or error_code.value != 0:
134134
raise OSError(
135-
'Could not open file "%s": (%s, %s)'
136-
% (self.fname, self.fid, error_code.value)
135+
f"Could not open file {self.fname}: ({self.fid}, {error_code.value})"
137136
)
138137
return self.fid
139138

140139
def __exit__(self, type_, value, traceback):
141140
if self.fid is not None:
142141
result = edf_close_file(self.fid)
143142
if result != 0:
144-
raise OSError('File "%s" could not be closed' % self.fname)
143+
raise OSError(f"File {self.fname} could not be closed")
145144

146145

147146
_ets2pp = dict(
@@ -158,7 +157,7 @@ def __exit__(self, type_, value, traceback):
158157
def _read_raw_edf(fname):
159158
"""Read data from raw EDF file into pyeparse format."""
160159
if not op.isfile(fname):
161-
raise OSError('File "%s" does not exist' % fname)
160+
raise OSError(f"File {fname} does not exist")
162161

163162
#
164163
# First pass: get the number of each type of sample
@@ -173,7 +172,7 @@ def _read_raw_edf(fname):
173172
while etype != event_constants.get("NO_PENDING_ITEMS"):
174173
etype = edf_get_next_data(edf)
175174
if etype not in event_constants:
176-
raise RuntimeError("unknown type %s" % event_constants[etype])
175+
raise RuntimeError(f"unknown type {event_constants[etype]}")
177176
ets = event_constants[etype]
178177
if ets in _ets2pp:
179178
n_samps[_ets2pp[ets]] += 1
@@ -194,13 +193,13 @@ def _read_raw_edf(fname):
194193
)
195194
# XXX: pyeparse represented messages as byte strings.
196195
# XXX: Maybe we should use regular python strings?
197-
dtype = [("stime", np.float64), ("msg", "|S%s" % _MAX_MSG_LEN)]
196+
dtype = [("stime", np.float64), ("msg", f"|S{_MAX_MSG_LEN}")]
198197
res["discrete"]["messages"] = np.empty((n_samps["messages"]), dtype=dtype)
199198
res["eye_idx"] = None # in case we get input/button before START
200199
while etype != event_constants.get("NO_PENDING_ITEMS"):
201200
etype = edf_get_next_data(edf)
202201
if etype not in event_constants:
203-
raise RuntimeError("unknown type %s" % event_constants[etype])
202+
raise RuntimeError(f"unknown type {event_constants[etype]}")
204203
ets = event_constants[etype]
205204
_element_handlers[ets](edf, res)
206205
_element_handlers["VERSION"](res)
@@ -521,7 +520,7 @@ def _handle_message(edf, res):
521520
msg = msg.decode("UTF-8")
522521
msg = "".join([i if ord(i) < 128 else "" for i in msg])
523522
if len(msg) > _MAX_MSG_LEN:
524-
warnings.warn("Message truncated to %s characters:\n%s" % (_MAX_MSG_LEN, msg))
523+
warnings.warn(f"Message truncated to {_MAX_MSG_LEN} characters:\n{msg}")
525524
off = res["offsets"]["messages"]
526525
res["discrete"]["messages"]["stime"][off] = e.sttime
527526
res["discrete"]["messages"]["msg"][off] = msg[:_MAX_MSG_LEN]
@@ -543,7 +542,7 @@ def _handle_end(edf, res, name):
543542
elif name == "inputs":
544543
f = ["sttime", "input"]
545544
else:
546-
raise KeyError("Unknown name %s" % name)
545+
raise KeyError(f"Unknown name {name}")
547546
res["edf_fields"][name] = f
548547
our_names = [_el2pp[field] for field in f]
549548
dtype = [(ff, np.float64) for ff in our_names]

0 commit comments

Comments
 (0)