Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/activity_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def infer_extension(file: str | PathLike[str]) -> str:
ext = p.suffix
if ext.lower() == ".gz":
ext = Path(p.stem).suffix
if not ext:
ext = ".gz"
return normalize_extension(ext)


Expand Down
1 change: 1 addition & 0 deletions src/activity_parser/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def index_by_time(records: pd.DataFrame, column: str) -> pd.DataFrame:
if column not in records.columns:
if not records.empty:
return records.rename_axis(column)
records = records.copy()
records[column] = pd.NaT

records = records.set_index(column)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def test_infer_extension():
assert infer_extension("dir/sub/ride.GPX.GZ") == "gpx"


def test_infer_extension_bare_gz_rejected():
with pytest.raises(ValueError, match="Ambiguous"):
infer_extension("ride.gz")


def test_select_and_reorder_cols_selects_and_orders():
df = pd.DataFrame({"b": [1], "a": [2], "ignored": [3]})
out = select_and_reorder_cols(df, ["a", "b", "missing"], include_all_columns=False)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def test_index_by_time_missing_column_yields_empty_datetime_index():
assert isinstance(out.index, pd.DatetimeIndex)


def test_index_by_time_missing_column_and_empty_does_not_mutate_input():
df = pd.DataFrame({"value": []})
index_by_time(df, "time")
assert "time" not in df.columns


def test_index_by_time_missing_column_with_rows_keeps_them():
df = pd.DataFrame({"value": [1, 2, 3]})
out = index_by_time(df, "time")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Keeps README.md's tables in sync with output.py."""
"""Keeps README.md's tables in sync with parser.py."""

import re
from dataclasses import fields
Expand Down