Skip to content

Commit

Permalink
Typo in NotImplementedError, corresponding tests
Browse files Browse the repository at this point in the history
* Added missing period in NotImplementedError in read_df/write_df,
  updated corresponding unit tests. Also use path suffix directly
  instead of given extension.
* Added missing test for write_df with provided extension raising
  NotImplementedError.
  • Loading branch information
TimothyWillard committed Jul 1, 2024
1 parent 18d9498 commit 0e8241d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions flepimop/gempyor_pkg/src/gempyor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def write_df(
elif path.suffix == ".parquet":
return df.to_parquet(path, index=False, engine="pyarrow")
raise NotImplementedError(
f"Invalid extension {extension}. Must be 'csv' or 'parquet'"
f"Invalid extension {path.suffix[1:]}. Must be 'csv' or 'parquet'."
)


Expand Down Expand Up @@ -95,7 +95,7 @@ def read_df(
elif path.suffix == ".parquet":
return pd.read_parquet(path, engine="pyarrow")
raise NotImplementedError(
f"Invalid extension {extension}. Must be 'csv' or 'parquet'"
f"Invalid extension {path.suffix[1:]}. Must be 'csv' or 'parquet'."
)


Expand Down
4 changes: 2 additions & 2 deletions flepimop/gempyor_pkg/tests/utils/test_read_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def test_raises_not_implemented_error(self) -> None:
"""
with pytest.raises(
expected_exception=NotImplementedError,
match="Invalid extension txt. Must be 'csv' or 'parquet'",
match="Invalid extension txt. Must be 'csv' or 'parquet'.",
) as _:
with NamedTemporaryFile(suffix=".txt") as temp_file:
read_df(fname=temp_file.name)
with pytest.raises(
expected_exception=NotImplementedError,
match="Invalid extension txt. Must be 'csv' or 'parquet'",
match="Invalid extension txt. Must be 'csv' or 'parquet'.",
) as _:
with NamedTemporaryFile(suffix=".txt") as temp_file:
fname = temp_file.name[:-4]
Expand Down
9 changes: 8 additions & 1 deletion flepimop/gempyor_pkg/tests/utils/test_write_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ def test_raises_not_implemented_error(self) -> None:
"""
with pytest.raises(
expected_exception=NotImplementedError,
match="Invalid extension txt. Must be 'csv' or 'parquet'",
match="Invalid extension txt. Must be 'csv' or 'parquet'.",
) as _:
with NamedTemporaryFile(suffix=".txt") as temp_file:
write_df(fname=temp_file.name, df=self.sample_df)
with pytest.raises(
expected_exception=NotImplementedError,
match="Invalid extension txt. Must be 'csv' or 'parquet'.",
) as _:
with NamedTemporaryFile(suffix=".txt") as temp_file:
fname = temp_file.name[:-4]
write_df(fname=fname, df=self.sample_df, extension="txt")

@pytest.mark.parametrize(
"fname_transformer,extension",
Expand Down

0 comments on commit 0e8241d

Please sign in to comment.