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

Clarification of 1.0 v 1. #760

Merged
merged 4 commits into from Dec 3, 2019
Merged

Clarification of 1.0 v 1. #760

merged 4 commits into from Dec 3, 2019

Conversation

@coolernato
Copy link
Contributor

coolernato commented Nov 25, 2019

The previous explanation implies that Python will always print 1.0 as "1." when there's nothing after the decimal point. However, this is specific to numpy. For example, the statement "print(1.0)" will print "1.0" and not "1.". I changed the description to refer to a numpy array instead of Python in general. I also clarified the space saved was on the screen (rather than in memory, for example).

The previous explanation implies that Python will always print 1.0 as "1." when there's nothing after the decimal point. However, this is specific to numpy. For example, the statement "print(1.0)" will print "1.0" and not "1.". I also clarified the space saved was on the screen (rather than in memory for example).
To save space,
Python displays numbers as `1.` instead of `1.0`
To save space on the screen
when printing a numpy array, numbers will be displayed as `1.` instead of `1.0`
when there's nothing interesting after the decimal point.

This comment has been minimized.

Copy link
@ldko

ldko Nov 25, 2019

Contributor

@coolernato I think the points you are clarifying are worthwhile ones to make. Thanks for proposing the change. A few things I am thinking:

  1. We should capitalize "NumPy" here (based on other usage in the episode).
  2. I wonder about using the word "printing" , since in this case we aren't using print.
  3. Not sure about using the tense of "will be".

What do you think of the wording:

To save space on the screen when displaying a NumPy array, numbers are shown as `1.` instead of `1.0` when there's nothing interesting after the decimal point.

This comment has been minimized.

Copy link
@coolernato

coolernato Nov 27, 2019

Author Contributor

@ldko Yes, I agree with your points and think your re-phrasing makes sense. I will update the request to use that phrasing.

@maxim-belkin

This comment has been minimized.

Copy link
Contributor

maxim-belkin commented Nov 27, 2019

Thanks for spotting the problem, Chris, and improving Chris' suggestion, Lauren!

Yes, we need to reword this part of the episode. How strongly do you both feel about these two pieces?

To save space on the screen when displaying a NumPy array

when there's nothing interesting after the decimal point.

Can we remove them? They both justify / explain the middle part (numbers are shown as 1. instead of 1.0) but I'm not positive they're necessary.

  1. "there's nothing interesting after the decimal point" is a bit vague
  2. the actual reason we see 1. instead of 1.0 (or something else) is the floatmode setting which we can control with numpy.set_printoptions(): by default, NumPy displays elements of an array using the number of fractional digits necessary to uniquely represent this specific element (numpy.get_printoptions()['floatmode'] returns maxprec -- see help page for numpy.set_printoptions).

What if we say something like this?

Note, that when displaying NumPy arrays, Python does not show us trailing zeros, so 1.0 becomes 1.

Do we nee to know the "reasons" why NumPy does what it does when displaying arrays?

@coolernato

This comment has been minimized.

Copy link
Contributor Author

coolernato commented Nov 28, 2019

@maxim-belkin I agree the "there's nothing interesting after the decimal point" is a bit vague. Your rewording regarding trailing zeroes is much clearer.

Regarding your second point, I would say this is the mechanism by which the format is controlled. I agree that going into detail about this mechanism would be too much. However, the reason it is by default set to "1." instead of "1.0" is to save space on the display. I think that there's value to pointing this out - otherwise learners will likely wonder why this behaviour (which many learners would not expect) occurs.

I would propose the following (or some reworded variant):

"Note, that to save space when displaying NumPy arrays, Python does not show us trailing zeros, so 1.0 becomes 1."

If you feel strongly that the explanation is unnecessary I would be happy to leave it out, as either version corrects the initial problem I identified.

@slel

This comment has been minimized.

Copy link
Contributor

slel commented Nov 28, 2019

How about something like this.

Note the 1. for 1.0: NumPy arrays skip trailing zeros
to save space, but keep the decimal point to tell apart
arrays of integers from arrays of floating-point numbers.

@coolernato

This comment has been minimized.

Copy link
Contributor Author

coolernato commented Nov 29, 2019

@slel The point that the period remains to differentiate it from an int is valid. I worry though that it might be going into too much detail?

If this were to be mentioned, it might be best splitting it into two sentences:

'Note, that to save space when displaying NumPy arrays, Python does not show us trailing zeros, so "1.0" becomes "1.". The period remains after the "1" to show the number is a float and not an int.'

This is my first pull request (on The Carpentries or elsewhere). When there are a multitude of valid options (as I believe we have here), who is it that makes the final decision of how to resolve an issue?

@slel

This comment has been minimized.

Copy link
Contributor

slel commented Nov 29, 2019

You are right, no need to mention ints here. I'm fine with any phrasing.
You and the lesson maintainers should settle on something snappy.

@ldko

This comment has been minimized.

Copy link
Contributor

ldko commented Dec 2, 2019

I agree with both @maxim-belkin and @coolernato that the wording "nothing interesting after the decimal point" is worth replacing and with @coolernato that it is useful to give some reasoning of why there is nothing shown after the decimal point. If you give no explanation at all, you are stating only what is already shown by the output, so why state it at all?

"Note, that to save space when displaying NumPy arrays, Python does not show us trailing zeros, so 1.0 becomes 1."

sounds good to me, but I would either remove the word "that" or move the comma from before "that" to after "that".

@coolernato, regarding your question about who makes the final decision, I believe that, ideally, two of the maintainers agree on a resolution with the submitter, and we will merge the changes. I think we are close here!

@coolernato

This comment has been minimized.

Copy link
Contributor Author

coolernato commented Dec 3, 2019

@ldko A fine point regarding that comma. I've changed the phrasing to 'Note that, to save space when displaying NumPy arrays, Python does not show us trailing zeros, so "1.0" becomes "1.".' I think that's a simple, accurate and to the point explanation of the behaviour.

@ldko
ldko approved these changes Dec 3, 2019
Copy link
Contributor

ldko left a comment

This looks good to me 👍

@maxim-belkin

This comment has been minimized.

Copy link
Contributor

maxim-belkin commented Dec 3, 2019

I'd suggest using back-ticks instead of quotation marks to avoid any confusion.
Otherwise -- 👍

@coolernato

This comment has been minimized.

Copy link
Contributor Author

coolernato commented Dec 3, 2019

Fair point. Updated.

@maxim-belkin

This comment has been minimized.

Copy link
Contributor

maxim-belkin commented Dec 3, 2019

Thank you!

@ldko ldko merged commit c8c3767 into swcarpentry:gh-pages Dec 3, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.