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

Redefining of functions across notebooks in the repository #98

Closed
oindrillac opened this issue Jan 21, 2021 · 7 comments · Fixed by #101
Closed

Redefining of functions across notebooks in the repository #98

oindrillac opened this issue Jan 21, 2021 · 7 comments · Fixed by #101

Comments

@oindrillac
Copy link
Member

Is your feature request related to a problem? Please describe.

There are a few functions that are re-defined across multiple notebooks eg: calc_flakiness_score(), decode_run_length etc. Having duplicate functions over different notebooks which are a part of the same project could increase the maintainability of code.

Describe the solution you'd like
As a software engineer creating notebooks for the project, I want to refactor the code to reduce duplication of modules so that the code is more easily maintainable. This can be achieved by importing the required modules across notebooks.

The ipynb package can be used for importing jupyter notebooks and modules therein like regular .py files.

@MichaelClifford
Copy link
Member

@oindrillac 👍

@oindrillac
Copy link
Member Author

The ipynb package does not seem to be a good fit for our use-case as the notebook import throws an error because of the inline %matlplotlib inline statement - ipython/ipynb#41.

  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)

  File "<unknown>", line 28
    %matplotlib inline
    ^
SyntaxError: invalid syntax

Are there any packages which can be used to import functions from other notebooks within a project?

@chauhankaranraj
Copy link
Member

Are there any packages which can be used to import functions from other notebooks within a project?

Hmm I'm not sure. Is there a strong reason for defining functions inside jupyter notebooks instead of .py files inside src directory?

@oindrillac
Copy link
Member Author

Are there any packages which can be used to import functions from other notebooks within a project?

Hmm I'm not sure. Is there a strong reason for defining functions inside jupyter notebooks instead of .py files inside src directory?

@chauhankaranraj You mean strip out all functions from within a notebook and move them to a script?
One reason that I can think of, is that the parent notebook which would contain the function definitions and which we also want to serve as tutorials/blogs become incomplete.
But otherwise, I do not see harm in moving out these frequently used modules out of a notebook into a script which all notebooks can leverage.

@chauhankaranraj
Copy link
Member

Are there any packages which can be used to import functions from other notebooks within a project?

Hmm I'm not sure. Is there a strong reason for defining functions inside jupyter notebooks instead of .py files inside src directory?

@chauhankaranraj You mean strip out all functions from within a notebook and move them to a script?
One reason that I can think of, is that the parent notebook which would contain the function definitions and which we also want to serve as tutorials/blogs become incomplete.

That's true. I'm not sure what the best practice for this should be. Maybe we could define it twice - once in the parent notebook where we explain the reasoning for that func, and then again in a helpers.py module?

Perhaps some of the python experts on the team could give pointers? @aicoe-aiops/team-aiops 😃

@MichaelClifford
Copy link
Member

Do we need %matplotlib inline? I think I put it in there out of habit. But I just tried it on MOC-JH and it didn't seem to make a difference without it. See image.

image

Maybe we just remove the % statements.

@oindrillac
Copy link
Member Author

Cool! that should be an easy fix then 👍

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 a pull request may close this issue.

3 participants