Skip to content

Tutorial: miscellaneous #914

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

Merged
merged 2 commits into from
Feb 25, 2021
Merged

Conversation

alixdamman
Copy link
Collaborator

slight changes or improvements here and there

@alixdamman alixdamman requested a review from gdementen February 17, 2021 14:54
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@alixdamman
Copy link
Collaborator Author

From the logs from Travis, I can see that the newer version of pandas has broken LArray...

Copy link
Contributor

@gdementen gdementen left a comment

Choose a reason for hiding this comment

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

  • tutorial: use print() everywhere: -1 on this. We can add a note about this/explain this at the start if this isn't the case already but users need to understand that rather sooner than later because most Python ressources on the net use that syntax.

  • tutorial: use string syntax to generate axes in the getting_started: +0

  • tutorial: removed the warning box about how to define Session objects…: +1

  • tutorial -> tutorial_presenting_larray_objects notebook:

    • use the string syntax to declare axes: +0 in general but a -1 for the "age axis with strings" change as is. I think it is a good idea to show the consequence of having a mixed axis (need to index with strings) but it should contain some kind of explanation that it is a special case when you have a mixed axis. Without an explanation , this is going to confuse more than anything IMO. Also, I wonder if this is the best place to introduce that.
    • removed other axis (it is unlikely that users will mix letters and numbers when generating labels with the syntax start..end): +0
    • do not use numpy randint() function to generate fake data (to avoid to confuse readers): +1
    • avoid to define anonymous axes when calling function to create arrays with predefined values (confusing): +1
    • removed example explaining how to create Session objects with Python 3.5- (versions 3.5 or less are too old): +1 but see inline comment.
  • tutorial -> tutorial_combine_arrays notebook:

    • removed subsection about extend() (redundant with append()/append()/insert()): strong -1 as this is really not the same operation. We should probably make it so (document that .append also works when the axis already exists + deprecate .extend #887) but it is not the case yet, and even if it was documented, keeping an example where the axis exist is a must IMO.
    • added example using argument after instead of before with the insert() method: +1

# create an anonymous Group object 'teens'
teens = age[10:20]
teens = age['10':'18']
Copy link
Contributor

Choose a reason for hiding this comment

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

Beurk! See general comment.

@@ -364,12 +369,6 @@ cells:
gender = Axis("gender=Male,Female")
time = Axis("time=2013..2017")

# create and populate a new session in one step
# Python <= 3.5
demography_session = Session([('gender', gender), ('time', time), ('population', zeros((gender, time))),
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this syntax is also useful when you have objects with names which are not valid Python identifiers (such as labels starting with a number). This probably needs to be mentioned somewhere, but probably not here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using a dictionary instead of a list of pairs would be clearer. Anyway, it is difficult and maybe not a good idea to show any pitfall or very specific cases in the tutorial. IMO, the tutorial is big enough right now to not add (very) specific cases (at least this one).

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed a dict is better for Python3.7+, my bad. My comment was only valid for 3.6, but since we are doing away with it too, you can indeed simply remove that. Concerning special/tricky cases I think a tutorial is meant precisely to show those which users are likely to stumble into and how to "work around" them. In this case, I don't know how likely it is. I have seen array labels starting with numbers quite a few time, but never in a session, so removing the block is fine I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Your comment above makes me think that I may add something about how to create a group mixing separated labels and a slice (using Group.union()). What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

A good idea (unless you plan to tackle #429 "soonish", in which case it would be better to tackle it first to show the nice syntax directly) but I don't know what's the best place to add that...

@alixdamman
Copy link
Collaborator Author

* tutorial: use print() everywhere: -1 on this. We can add a note about this/explain this at the start if this isn't the case already but users need to understand that rather sooner than later because most Python ressources on the net use that syntax.

OK. OK. I did that because 2 of our users send me an email to complain about the fact that lines like:

population.info

don't print anything when they run their scripts. They think that everything in the tutorial is transferable to their scripts as it is.
But you're right when you say "users need to understand that rather sooner than later because most Python ressources on the net use that syntax". I will reverse that commit and add a note somewhere.

* tutorial -> tutorial_presenting_larray_objects notebook:
  
  * use the string syntax to declare axes:  +0 in general but a **-1** for the "age axis with strings" change as is. I think it is a good idea to show the consequence of having a mixed axis (need to index with strings) **but** it should contain some kind of explanation that it is a special case when you have a mixed axis. Without an explanation , this is going to confuse more than anything IMO. Also, I wonder if this is the best place to introduce that.

OK

* tutorial -> tutorial_combine_arrays notebook:
  
  * removed subsection about extend() (redundant with append()/append()/insert()): strong **-1** as this is really not the same operation. We should probably make it so (#887) but it is not the case yet, and even if it was documented, keeping an example where the axis exist is a must IMO.

Hum. Well. What does really extend() is obscure to me and I can't find an example where extend() cannot be replaced by either insert() or append() or prepend(). To tell the truth, I never use it when I have to help someone.

@alixdamman
Copy link
Collaborator Author

Do you have an example in mind where the use of extend() cannot be replaced by either insert(), prepend() or append() ?

@@ -27,6 +27,17 @@ cells:
__version__


- markdown: |
<div class="alert alert-warning">
The tutorial is generated from Jupyter notebooks which works in "interactive" mode (like in the LArray Editor).
Copy link
Contributor

Choose a reason for hiding this comment

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

  • s/works/work
  • LArray Editor console?

- markdown: |
<div class="alert alert-warning">
The tutorial is generated from Jupyter notebooks which works in "interactive" mode (like in the LArray Editor).
In the "interactive" mode, there is no need to use the function print() to display the content of a variable.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/the "interactive"/interactive/
s/the function print()/the print() function
also add a mention of expressions?

The tutorial is generated from Jupyter notebooks which works in "interactive" mode (like in the LArray Editor).
In the "interactive" mode, there is no need to use the function print() to display the content of a variable.
Simply writing its name is enough.
The function print() is only need if the content of more than one variable has to be displayed.<br><br>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would remove this sentence (as it is not entirely true), you can display a tuple in the console:

>>> a = 1; b = 2
>>> a, b
(1, 2)

Simply writing its name is enough.
The function print() is only need if the content of more than one variable has to be displayed.<br><br>
In a Python script (file with .py extension), you always need to use the print() function to display the content of
a variable or the value returned by a function.
Copy link
Contributor

Choose a reason for hiding this comment

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

add a mention of expressions?

@gdementen
Copy link
Contributor

OK. OK. I did that because 2 of our users send me an email to complain about the fact that lines like:

population.info

don't print anything when they run their scripts. They think that everything in the tutorial is transferable to their scripts as it is.

I know, I already had that question too.

@gdementen
Copy link
Contributor

gdementen commented Feb 19, 2021

Concerning the print() function, I think it would help if you mentioned

  1. an explicit example. Something like: "For example, we did not need to use a print() function to display the content of the __version__ variable above".
  2. explicit explanation that when copy pasting code from the tutorial in a script file, you need to add those print() calls.

@gdementen
Copy link
Contributor

Do you have an example in mind where the use of extend() cannot be replaced by either insert(), prepend() or append() ?

Probably not something user-friendly, because .append does work in that case (by accident -- this is the whole point of #887) but that's not the point here. The point is that those two methods were meant to do (and are documented as doing) different things and even if we can do both "things" using the same method, we should show both in the tutorial. So either you leave it as is (using .extend) or you tackle #887 first/at the same time and change that .extend call to .append.

@gdementen
Copy link
Contributor

PS: the difference between larray.append and .extend was meant to be exactly the same as the difference between list.append and .extend



- code: |
# mixing a slices and individual labels leads to the creation of a tuple of groups
Copy link
Contributor

Choose a reason for hiding this comment

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

s/a slices/slices/
s/a tuple of/several distinct/ ?

- markdown: |
<div class="alert alert-warning">

**Warning:** Mixing slices and individual labels inside the `[ ]` will generate a **tuple of groups** instead of unique group.<br>If you want to create a unique group using both slices and individual labels, you need to use the `.union()` method (see below).
Copy link
Contributor

Choose a reason for hiding this comment

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

s/a tuple of/several distinct/ ?
s/of unique/of a single/
s/a unique/a single/

</div>


- code: |
s = "There is no need to use the print() function to display the content of the variable 's'."
Copy link
Contributor

Choose a reason for hiding this comment

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

couldn't having the message within the variable be confusing?



- code: |
"There is no need to use the print() function " + "to display the returned value of an " + "expression"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use something simpler?

>>> 1 + 2
3

- markdown: |
<div class="alert alert-warning">

**Warning:** Mixing slices and individual labels inside the `[ ]` will generate a **tuple of groups** instead of unique group.<br>If you want to create a unique group using both slices and individual labels, you need to use the `.union()` method (see below).
Copy link
Contributor

Choose a reason for hiding this comment

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

s/a tuple of/several distinct/ ?
s/of unique/of a single/
s/a unique/a single/



- code: |
# leading to unexpected results
Copy link
Contributor

Choose a reason for hiding this comment

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

to potentially unexpected?



- code: |
# the union() method allows to mix slices and individual labels to create a unique group
Copy link
Contributor

Choose a reason for hiding this comment

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

single

@gdementen
Copy link
Contributor

LGTM, it's merging season 😉

@gdementen
Copy link
Contributor

btw the "the" you added were not typos. I think it's correct too but it's superfluous. In general, "the" is used less in English than "le" in French.

- use string syntax to generate axes
- removed the warning box about how to define Session objects before Python 3.6 (Python version previous to 3.6 are too old now)
- removed other axis (it is unlikely that users will mix letters and numbers when generating labels with the syntax start..end)
- do not use numpy randint() function to generate fake data (to avoid to confuse readers)
- avoid to define anonymous axes when calling function to create arrays with predefined values (confusing)
- removed example explaining how to create Session objects with Python 3.5- (versions 3.5 or less are too old)
- added example using argument after instead of before with the insert() method
- added a warning box to explain why we don't use the print() function to display the content of a variable in the tutorial
- added warning and examples about how LArray infer type of labels
- added explanation about how to create a unique group using slices and individual labels together
@alixdamman alixdamman merged commit 0f02f12 into larray-project:master Feb 25, 2021
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