Skip to content

Commit

Permalink
Merge branch 'logstodf_raise_on_no_fields'
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdabbas committed Aug 18, 2024
2 parents 34b6d83 + aebdd8d commit e315db8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion advertools/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,11 @@ def logs_to_df(
raise ValueError(
"Please provide an `output_file` with a `.parquet` " "extension."
)

if not LOG_DATE_FORMATS.get(log_format) and fields is None:
raise ValueError(
"Please supply a value for the `fields` parameter when you provide a custom"
"log format."
)
regex = LOG_FORMATS.get(log_format) or log_format
date_fmt = date_format or LOG_DATE_FORMATS.get(log_format)
columns = fields or LOG_FIELDS[log_format]
Expand Down
14 changes: 13 additions & 1 deletion tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,16 @@ def test_logstodf_parses_raises_wrong_date_fmt():
date_format="%B %, M:%S %z",
)
result = pd.read_parquet(path / "delete_output.parquet")
assert not ("datetime" in result["datetime"].dtype.name)
assert "datetime" not in result["datetime"].dtype.name


def test_logstodf_raises_on_no_fields():
"""Raise an exception if user proivides custom log format without fields."""
with pytest.raises(ValueError):
logs_to_df(
log_file="some_file.txt",
output_file="output_file.parquet",
errors_file="errors.txt",
log_format="custom_regex",
fields=None,
)

0 comments on commit e315db8

Please sign in to comment.