Skip to content

fix(safaa): handle non-list iterables in _ensure_list_of_strings#48

Open
Valyrian-Code wants to merge 1 commit into
fossology:mainfrom
Valyrian-Code:fix/ensure-list-of-strings
Open

fix(safaa): handle non-list iterables in _ensure_list_of_strings#48
Valyrian-Code wants to merge 1 commit into
fossology:mainfrom
Valyrian-Code:fix/ensure-list-of-strings

Conversation

@Valyrian-Code

@Valyrian-Code Valyrian-Code commented May 23, 2026

Copy link
Copy Markdown

Description

_ensure_list_of_strings was documented to accept any iterable but only worked for list and pandas.Series. Tuples, generators, sets, and other iterables raised:

AttributeError: '<type>' object has no attribute 'to_list'

because to_list() is a pandas-specific method.

This PR replaces data.to_list() with list(data), allowing all standard iterables to be handled consistently without changing behavior for existing callers.

Changes

The new tests cover lists, tuples, generators, pandas Series, numpy arrays, mixed types, empty inputs, and regression cases for the original bug.

How to test

poetry install
poetry run pytest tests/test_safaa.py -v

All tests pass.

Regression check

Previously failing inputs now work correctly:

from safaa.Safaa import SafaaAgent

agent = SafaaAgent()

agent.predict(("Copyright 2024 Foo",))
agent.predict(x for x in ["Copyright 2024 Foo"])

This closes #47.

_ensure_list_of_strings called data.to_list() when the input was not a
list. to_list is a pandas Series method, so tuples, generators, sets and
other iterables raised AttributeError despite the docstring stating the
parameter accepts an "iterable".

Replace with list(data), which works uniformly for lists, tuples,
generators, pandas Series, numpy arrays, and any other iterable.

Also introduce a pytest-based test suite (the repo previously had none),
add pytest to the dev dependencies, and cover the regression path along
with baseline tests for predict() and declutter() so future refactors
have a safety net.

Signed-off-by: RAJVEER42 <irajveer.bishnoi2310@gmail.com>
@Valyrian-Code

Valyrian-Code commented May 23, 2026

Copy link
Copy Markdown
Author

Hi @GMishx & @Kaushl2208

Hi! I opened a small PR with bug fixes and regression tests. I’d appreciate a review whenever you have time thanks for maintaining the project!

GIF

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_ensure_list_of_strings raises AttributeError for tuples, generators, and other non-list iterables

2 participants