Skip to content

[fix]:461 fixed with a utility function that checks for booealn inter…#493

Open
thisismeamir wants to merge 7 commits into
HEP-FCC:masterfrom
thisismeamir:master
Open

[fix]:461 fixed with a utility function that checks for booealn inter…#493
thisismeamir wants to merge 7 commits into
HEP-FCC:masterfrom
thisismeamir:master

Conversation

@thisismeamir
Copy link
Copy Markdown

The #461 opened the possibility that the user might un-intentionally enter string values instead of boolean for some inputs, resulting in an always True case.

I've added a utility function after the discussion with @kjvbrt about it and fixed the related histogram logarithmic scale bug with it as well.

…pretation fo string and integer content. Raises error to the user otherwise
Comment thread python/utils.py Outdated
return ''.join(random.choices(string.ascii_letters + string.digits,
k=length))

def boolean_of(input, context: str) -> bool :
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.

can you also make the function not sensitive to case? For example, "nO" or "trUe" should work as well.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

alright

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was thinking to make the users go to a typesafe region over time that's why I raised the error

Comment thread python/utils.py Outdated
elif input in booleanDictionary["trueStatements"]:
return True
else
raise Exception(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.")
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.

Can you instead of exception issue a warning? using the LOGGER?

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.

Should be LOGGER.warning()

@thisismeamir
Copy link
Copy Markdown
Author

how's it now?

Comment thread python/utils.py Outdated
elif statement.lower() in booleanDictionary["trueStatements"]:
return True
else:
LOGGER.warning(f"In ${context} you provided ${input} which cannot be considered a boolean in our source-code please use: False : ${booleanDictionary["falseStatements"]} and True: ${booleanDictionary["trueStatements"]}.")
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.

You need to escape the double quotes ". or use single quotes '.

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.

Nice, can you remove in our source-code from the warning message?

Comment thread python/utils.pyi
LOGGER: logging.Logger

def generate_graph(dframe, args, suffix: str | None = None) -> None: ...
def boolean_of(): ...
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.

The types do no match

@thisismeamir
Copy link
Copy Markdown
Author

To get on board again. I have a function boolean_of in the utils. Isn't that what we wanted? To have a function that enables boolean evaluation of strings generally?

And I've also used it in do_plots as well.

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