-
Notifications
You must be signed in to change notification settings - Fork 3
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
Better readability for numbers in output #89
Conversation
Codecov Report
@@ Coverage Diff @@
## main #89 +/- ##
==========================================
+ Coverage 91.85% 93.76% +1.91%
==========================================
Files 17 18 +1
Lines 1878 1894 +16
==========================================
+ Hits 1725 1776 +51
+ Misses 153 118 -35
|
Not really really ready for review, but I'd like to hear some thoughts. req.add_numeric_mean_constraint(..., accurate_numbers = True) or maybe an argument for the |
As you can see in my usage of the two functions, I'm also not really sure what's the best way from a dev experience POV. |
I'm not sure I find it totally necessary to to communicate to the end user what kind of rounding has taken place, as long as the rounding works in the interest of the prototypical user. Potentially one could add a short phrase to assertion texts indicating what kind of rounding has taken place, though I'm not sure about how bloated the texts might become then.
If you truly want to make this parametrizable, the
I'm not really sure I know what you mean. Your exemplary use in |
Nice! I think you're right about all the things you have said. What do you think about percentages instead of floats? |
Ignoring the messy code above: We could also color-code the output for better readability without having a trade-off on the user's precision. very nice idea from @jonashaag |
Great idea with the colorization! Just be cautious of cases where the place it's being printed on doesn't support that and then you end up (eventually) with garbage in the string. |
Yep, routing that output into a file gives you not-so-well formatted string. |
We can of course hack around like this import sys
if sys.stdout.isatty():
print(console.colorize("red", "This text is red."))
else:
print("This text is red.") but that may not be worth the hurdle, too.. |
It's not a hack actually, you might want to have a look at how other libraries identify color-readiness, I expect similar code |
What do you think about the following implementation? This works using When piping output to a file, it strips all formatting, s.t. something like the first example does not happen. It also works in f-strings, which are used in our |
I still really like the idea of the coloring, yet it doesn't seem to work perfectly for my local machine just yet. When I use the given functionality in an assertion string, I obtain the following: The default pytest coloring and the coloring introduced in this PR outdo each other. :/ @YYassin19 would you be open to making this PR about rounding and tackling the coloring in a follow-up PR? That might allow it to separate concerns and facilitate progress. |
I thought the idea was that this was the alternative to rounding. By adding colors, we can still show full complexity while making it very easy to read. |
:( |
I see - sorry about the misunderstanding.
Sadly I don't know. |
Hmm, I have no clue so far. |
Okay, I did some digging, and it turns out that the coloring of the section is currently hard-coded in pytest. The output seems fine on most UIs I have checked (e.g. PyCharm, VSCode, GitHub Output) but breaks for low contrast environments. |
6821d41
to
c1095c9
Compare
![]() TL;DR:
|
Awesome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Should we add colorma
to environment.yaml
and pyproject.toml
?
Yes, I'll do that! Should we also start re-writing some (all?) of the assertion messages to use this or have these few test cases, refine the feature further and refactor the others from time to time? |
9d69a30
to
c4b2102
Compare
Both are fine with me. In the latter case we should probably just make sure to create some shared overview of what has already been done and what remains to be done. |
I've created an issue to maybe track this task for the next time, hope that's a good middle way! |
Thanks! I'm not sure I understand 100%. What do you think about creating a concrete list of constraints with a binary indicator expressing completion? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Just to be sure: has anyone tested this change with the html reports yet?
src/datajudge/constraints/nrows.py
Outdated
@@ -58,9 +61,10 @@ def compare(self, n_rows_factual: int, n_rows_target: int) -> Tuple[bool, str]: | |||
class NRowsEquality(NRows): | |||
def compare(self, n_rows_factual: int, n_rows_target: int) -> Tuple[bool, str]: | |||
result = n_rows_factual == n_rows_target | |||
n1, n2 = diff_color(n_rows_factual, n_rows_target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would either suggest
n_rows_factual_fmt, n_rows_target_fmt = diff_color(n_rows_factual, n_rows_target)
'as before' or
factual_fmt, target_fmt = diff_color(n_rows_factual, n_rows_target)
as in other places in this PR.
src/datajudge/constraints/nrows.py
Outdated
@@ -145,10 +153,13 @@ def compare(self, n_rows_factual: int, n_rows_target: int) -> Tuple[bool, str]: | |||
if n_rows_factual < n_rows_target: | |||
return False, "Row loss." | |||
relative_gain = (n_rows_factual - n_rows_target) / n_rows_target | |||
relative_gain_fmt, min_gain_fmt = diff_color( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relative_gain_fmt, min_gain_fmt = diff_color( | |
relative_gain_fmt, min_relative_gain_fmt = diff_color( |
@YYYasin19 it should be possible to ask pytest if the html report option is active and if so, then the coloring should be deactivated. |
Alternatively, what do you think about a global option |
Do I understand correctly that this wouldn't allow for coloring if people don't use |
What do you guys think about if we support Colored Tags in the Failure message like |
That's certainly a better solution. If you can pull it it'd be great! |
Nice idea! |
I am in favor (of atleast trying it out) iff we have other use cases as well. Having more readable output is important, but does not only depend on better formatting for "long" numbers, only. |
Yes, exactly. We can even do proper HTML Colouring using this approach |
I implemented my concept in 567d6cd |
@0xbe7a looks good! |
@YYYasin19 How do we move with this PR after #170? Turn it into an example use in one constraint? |
I'll rebase, refactor some code and then add some examples to the more popular constraints we use! |
06c05f6
to
c9c2398
Compare
I think the PR's mostly ready. It has some examples of the usage (that we can further extend), it has some tests.. |
Thank you @YYYasin19 and @0xbe7a for this undertaking! |
Closes #88
Adds a method for cutting decimal numbers at their first differing place (cf. issue for a better explanation of the problem).
I also added a method that rounds numbers to their order of magnitude so the difference in large numbers can be seen more easily. Otherwise, you sometimes have an output like
12389239823 rows instead of 12259385943
.I just realized that the current method would round both to 120,000,... but an even better solution would be to round them to their first differing order of magnitude as well, i.e.
12,300,000,000 rows instead of 12,200,000,000
.I'll have to integrate them more though and add tests 👍