Skip to content

Commit

Permalink
Fix filters in TrainingDataDirectory.list (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
yias authored Oct 10, 2024
1 parent 166351b commit d8cf556
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/ansys/simai/core/api/training_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import json
from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional
from urllib.parse import urlencode

Expand All @@ -38,7 +39,9 @@ def get_training_data(self, id: str) -> Dict[str, Any]:

def iter_training_data(self, filters: Optional["RawFilters"]) -> Iterable[Dict[str, Any]]:
next_page = "training_data"
query = urlencode([("filter[]", f) for f in (filters or [])])
query = urlencode(
[("filter[]", json.dumps(f, separators=(",", ":"))) for f in (filters or [])]
)
if query:
next_page += f"?{query}"
while next_page:
Expand Down
16 changes: 14 additions & 2 deletions tests/test_training_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@ def test_training_data_list_with_filters(simai_client):
responses.matchers.query_string_matcher(
urlencode(
[
("filter[]", {"field": "name", "operator": "EQ", "value": "thingo"}),
("filter[]", {"field": "size", "operator": "LT", "value": 10000}),
(
"filter[]",
json.dumps(
{"field": "name", "operator": "EQ", "value": "thingo"},
separators=(",", ":"),
),
),
(
"filter[]",
json.dumps(
{"field": "size", "operator": "LT", "value": 10000},
separators=(",", ":"),
),
),
]
)
)
Expand Down

0 comments on commit d8cf556

Please sign in to comment.