Skip to content

Commit

Permalink
fix: docstrings after ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Mar 20, 2023
1 parent dfa91ad commit 1563e57
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/timeseriesflattener/feature_spec_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class TextPredictorSpec(PredictorSpec):
interval_days (Union[int, float]):
How far to look in the given direction (ahead for outcomes,
behind for predictors)
resolve_multiple_fn (Union[str, Callable]):
resolve_multiple_fn (Union[Callable, str]):
A function used for resolving multiple values within the
interval_days, i.e. how to combine texts within the lookbehind window.
Defaults to: 'concatenate'. Other possible options are 'latest' and
Expand Down Expand Up @@ -597,7 +597,7 @@ class Doc:
default=None,
description="""Optional kwargs passed onto the embedding_fn.""",
)
resolve_multiple_fn: Union[str, Callable] = Field(
resolve_multiple_fn: Union[Callable, str] = Field(
default="concatenate",
description="""A function used for resolving multiple values within the
interval_days, i.e. how to combine texts within the lookbehind window.
Expand Down Expand Up @@ -746,7 +746,7 @@ class Doc:
output df.""",
)

resolve_multiple_fn: List[Union[str, Callable]] = Field(
resolve_multiple_fn: List[Union[Callable, str]] = Field(
description="""Name of resolve multiple fn, resolved from
resolve_multiple_functions.py""",
)
Expand Down Expand Up @@ -871,7 +871,7 @@ class PredictorGroupSpec(_MinGroupSpec):
output_col_name_override (Optional[str]):
Override for the column name to use as values in the
output df.
resolve_multiple_fn (List[Union[str, Callable]]):
resolve_multiple_fn (List[Union[Callable, str]]):
Name of resolve multiple fn, resolved from
resolve_multiple_functions.py
fallback (List[Union[Callable, str]]):
Expand Down Expand Up @@ -924,7 +924,7 @@ class OutcomeGroupSpec(_MinGroupSpec):
output_col_name_override (Optional[str]):
Override for the column name to use as values in the
output df.
resolve_multiple_fn (List[Union[str, Callable]]):
resolve_multiple_fn (List[Union[Callable, str]]):
Name of resolve multiple fn, resolved from
resolve_multiple_functions.py
fallback (List[Union[Callable, str]]):
Expand Down
41 changes: 35 additions & 6 deletions tests/test_timeseriesflattener/test_feature_spec_objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Test that feature spec objects work as intended."""

import difflib
from typing import List

import numpy as np
import pandas as pd
import pytest
Expand Down Expand Up @@ -142,6 +145,17 @@ def test_resolve_multiple_fn_to_str():
assert "maximum" in pred_spec_batch[0].get_col_str()


def get_lines_with_diff(text1: str, text2: str) -> List[str]:
"""Find all lines in text1 which are different from text2."""
# Remove whitespace and periods
text_1 = text1.replace(" ", "").replace(".", "")
text_2 = text2.replace(" ", "").replace(".", "")

lines1 = text_1.splitlines()
lines2 = text_2.splitlines()
return [line for line in lines1 if line not in lines2]


@pytest.mark.parametrize(
"spec",
[
Expand All @@ -159,13 +173,26 @@ def test_feature_spec_docstrings(spec: BaseModel):
current_docstring = spec.__doc__
generated_docstring = generate_docstring_from_attributes(cls=spec)
# strip docstrings of newlines and whitespace to allow room for formatting
current_docstring_no_whitespace = current_docstring.replace(" ", "").replace(
"\n",
"",
current_docstring_no_whitespace = (
current_docstring.replace(" ", "")
.replace(
"\n",
"",
)
.replace(".", "")
)
generated_docstring_no_whitespace = (
generated_docstring.replace(" ", "")
.replace(
"\n",
"",
)
.replace(".", "")
)
generated_docstring_no_whitespace = generated_docstring.replace(" ", "").replace(
"\n",
"",

lines_with_diff = get_lines_with_diff(
text1=current_docstring,
text2=generated_docstring,
)

if current_docstring_no_whitespace != generated_docstring_no_whitespace:
Expand All @@ -185,6 +212,8 @@ def test_feature_spec_docstrings(spec: BaseModel):
Got: \n\n{current_docstring}.
Expected: \n\n{generated_docstring}
Differences are in lines: \n\n{lines_with_diff}
""",
)

Expand Down

0 comments on commit 1563e57

Please sign in to comment.