Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of wfdb.io.annotation.field2bytes function #406

Merged
merged 4 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@ def test_to_dataframe(self):
self.assertEqual(record.sig_name, list(df.columns))
self.assertEqual(len(df), record.sig_len)
self.assertEqual(df.index[0], pd.Timedelta(0))
self.assertEqual(df.index[-1], pd.Timedelta(seconds=1 / record.fs * (record.sig_len - 1)))
self.assertEqual(
df.index[-1],
pd.Timedelta(seconds=1 / record.fs * (record.sig_len - 1)),
)
assert np.array_equal(record.p_signal, df.values)

def test_header_with_non_utf8(self):
Expand Down
1 change: 0 additions & 1 deletion wfdb/io/_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2505,4 +2505,3 @@ def _infer_sig_len(
sig_len = int(data_size / (BYTES_PER_SAMPLE[fmt] * tsamps_per_frame))

return sig_len

9 changes: 5 additions & 4 deletions wfdb/io/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,10 +1627,7 @@ def field2bytes(field, value, custom_labels=None):
# samp and sym bytes come together
if field == "samptype":
# Numerical value encoding annotation symbol
typecode = label_table.loc[
label_table["symbol"] == value[1], "label_store"
].values[0]

typecode = typecodes[value[1]]
# sample difference
sd = value[0]

Expand Down Expand Up @@ -3208,3 +3205,7 @@ def __str__(self):
)
ann_label_table.set_index(ann_label_table["label_store"].values, inplace=True)
ann_label_table = ann_label_table[["label_store", "symbol", "description"]]
typecodes = {
ann_label_table.iloc[i]["symbol"]: ann_label_table.iloc[i]["label_store"]
for i in range(len(ann_label_table))
}
6 changes: 1 addition & 5 deletions wfdb/io/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,7 @@ def to_dataframe(self) -> pd.DataFrame:
else:
raise ValueError("No signal in record.")

return pd.DataFrame(
data=data,
index=index,
columns=self.sig_name
)
return pd.DataFrame(data=data, index=index, columns=self.sig_name)


class MultiRecord(BaseRecord, _header.MultiHeaderMixin):
Expand Down