Skip to content

Conversation

@thisismeamir
Copy link

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
python/utils.py Outdated
return ''.join(random.choices(string.ascii_letters + string.digits,
k=length))

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

Choose a reason for hiding this comment

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

alright

Copy link
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

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
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
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
Author

how's it now?

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
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
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?

LOGGER: logging.Logger

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

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