Skip to content

Normalize query added - #23

Open
MrEx3cut0r wants to merge 3 commits into
mpds-io:masterfrom
MrEx3cut0r:normalize-query-added
Open

MrEx3cut0r wants to merge 3 commits into
mpds-io:masterfrom
MrEx3cut0r:normalize-query-added

Conversation

@MrEx3cut0r

Copy link
Copy Markdown
Member

I added query normalize function to the MPDS Retrieve class.

@MrEx3cut0r

Copy link
Copy Markdown
Member Author

@blokhin after accepting this PR, normalize_query no more needed in mpds-api

@alinzh alinzh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I recommend merging master into this branch after PR #22 is merged, or rewriting the imports to relative ones now so that the PR can be accepted independently.

I would also handle the case where the user submits an empty list; script will break now. It's better to add a check for case: _normalize_query({"elements": []}) .
With this inputs format, '-'.join([]) yields an empty string, which will most likely trigger an API error.

Comment thread mpds_client/retrieve_MPDS.py Resolved
Comment thread mpds_client/test_retrieve_MPDS.py Resolved
Comment thread mpds_client/retrieve_MPDS.py Resolved
Comment thread mpds_client/retrieve_MPDS.py Resolved
@alinzh

alinzh commented May 29, 2026

Copy link
Copy Markdown
Contributor

Change _normalize_query to:

    def _normalize_query(self, query):
        out = dict(query)
        if 'elements' in out and isinstance(out['elements'], (list, tuple)):
            if out['elements']:
                out['elements'] = '-'.join(out['elements'])
            else:
                raise ValueError("'elements' list must not be empty")
        if 'classes' in out and isinstance(out['classes'], (list, tuple)):
            if out['classes']:
                out['classes'] = ','.join(out['classes'])
            else:
                raise ValueError("'classes' list must not be empty")
        return out 

to avoid the empty list problem.

@MrEx3cut0r

Copy link
Copy Markdown
Member Author

@alinzh is elements and classes lists are required in any request?

@MrEx3cut0r
MrEx3cut0r force-pushed the normalize-query-added branch from 488f400 to 1d9091d Compare May 30, 2026 07:31
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.

2 participants