Skip to content

Commit

Permalink
Add docstring example
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Nov 13, 2024
1 parent 7a6476c commit 1fdebad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion audbackend/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,30 @@ def checksum(file: str) -> str:
or pyarrow_ is not installed,
its MD5 sum is calculated instead.
.. _pyarrow: https://arrow.apache.org/docs/python/index.html
Args:
file: file path with extension
Returns:
MD5 checksum of file
.. _pyarrow: https://arrow.apache.org/docs/python/index.html
Examples:
>>> checksum("src.txt")
'd41d8cd98f00b204e9800998ecf8427e'
>>> import audformat
>>> import pandas as pd
>>> import pyarrow as pa
>>> import pyarrow.parquet as pq
>>> df = pd.DataFrame([0, 1], columns=["a"])
>>> hash = audformat.utils.hash(df, strict=True)
>>> hash
'9021a9b6e1e696ba9de4fe29346319b2'
>>> table = pa.Table.from_pandas(df)
>>> table = table.replace_schema_metadata({"hash": hash})
>>> pq.write_table(table, "file.parquet", compression="snappy")
>>> checksum("file.parquet")
'9021a9b6e1e696ba9de4fe29346319b2'
"""
ext = audeer.file_extension(file)
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyarrow
audformat
pytest<8.1.0 # required by doctestplus
pytest-cov
pytest-doctestplus

0 comments on commit 1fdebad

Please sign in to comment.