Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rounding optional #166

Merged
merged 9 commits into from
Aug 18, 2021
Merged

Make rounding optional #166

merged 9 commits into from
Aug 18, 2021

Conversation

LKirst
Copy link
Contributor

@LKirst LKirst commented Aug 17, 2021

Make rounding of outputs optional by allowing the user to change the boolean attribute round_outputs of an instance of the textstatistics class.

Copy link
Member

@alxwrd alxwrd left a comment

Choose a reason for hiding this comment

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

hi @LKirst. Thank you for this! I'm happy to accept this as a work around for rounding. The build is currently failing though, see review comments.

textstat/textstat.py Outdated Show resolved Hide resolved
textstat/textstat.py Outdated Show resolved Hide resolved
@LKirst
Copy link
Contributor Author

LKirst commented Aug 18, 2021

Hi @alxwrd,

Thank you for your feedback. I've implemented the changes as requested.

@alxwrd
Copy link
Member

alxwrd commented Aug 18, 2021

Excellent, thank you!

I've just pushed a couple of tests as I was playing around with it. The usage of

import textstat

textstat.textstat.round_outputs = False

felt a bit awkward.

But, as we expose all the methods of a default textstat instance in the textstat module namespace,

>>> textstat.char_count.__self__ is textstat.textstat.char_count.__self__
True

I've changed the usage to set_rounding(rounding, points=None). Because this now a callable, it also gets exposed from the default instance.


So the usage for the default textstat instance is:

import textstat
textstat.set_rounding(False)

of course you could still create a separate instance:

import textstat
from textstat.textstat import textstatistics

my_textstat = textstatistics()
my_textstat.set_rounding(False)

my_not_rounded_index = my_textstat.spache_readability(long_test)

assert my_not_rounded_index == 5.2500456989247315

default_rounded_index = textstat.spache_readability(long_test)

assert default_rounded_index == 5.25

@alxwrd alxwrd merged commit c83d123 into textstat:master Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants