Skip to content

Conversation

@triper1022
Copy link

Hi~

I found we often make multiple imports in one line like below
from keras.layers import LSTM, Dropout, Dense.

Therefore, I rewrote the func., def _assign_imports_to_globals() to make this work.
If you are free, please check it out.

@FlorianWetschoreck
Copy link
Collaborator

Hey, thank you for your PR!

Please describe the use case a little bit more in detail.
E.g. do you add the "from keras.layers import LSTM, Dropout, Dense" to your personal pyforest imports?
What is the behavior of pyforest before your PR and after?
Also, we would need some tests for the PR.

@triper1022
Copy link
Author

triper1022 commented Jun 22, 2021

Hi~ Thanks for your reply.

E.g. do you add the "from keras.layers import LSTM, Dropout, Dense" to your personal pyforest imports?
Yes, I did. I knew that in original project,
the normal accepted formats are "import matplotlib.pyplot as plt" or
"from sklearn.ensemble import GradientBoostingRegressor"

However,
I know that we often would like to make the lines shorter,
we usually write imports in one line with comma
if they are in the same module.
We don't write
"from keras.layers import LSTM",
"from keras.layers import Dropout",
"from keras.layers import Dense" repeatedly.
The similar situation also happens when using Python built-in modules.
E.g., "import sys, os, re"

My PR is to split the string,
"from keras.layers import LSTM, Dropout, Dense",
and create 3 LazyImport instances as the original project,
LSTM = LazyImport("from keras.layers import LSTM"),
Dropout = LazyImport("from keras.layers import Dropout"),
Dense = LazyImport("from keras.layers import Dense"),
but users still can add their common use imports
in ~/.pyforest/user_imports.py,
like "from keras.layers import LSTM, Dropout, Dense" in one line.

Besides, I created 2 small personal features in my forked repo.
If you have interest, welcome to glance at them.
I wrote short description in readme file.

I think this project is useful for
the users who often change their workplaces
in different local machines, cloud IDEs, or projects.
Thank you very much!

@FlorianWetschoreck
Copy link
Collaborator

Thank you for your reply. Please also describe the behavior/spec of pyforest before and after your PR.

@tkrabel
Copy link
Collaborator

tkrabel commented Jun 23, 2021

Hi @triper1022,

So you mentioned that your PR allows writing import statements like from keras.layers import LSTM, Dropout, Dense to your personal pyforest imports.

Now, I'm wondering: If you open a fresh Notebook (with no imports written yet) and start using keras.layers.Dropout for example (but not LSTM or Dense), what import statement will be added to the top of the Notebook?

Will it be

  • from keras.layers import LSTM, Dropout, Dense
  • from keras.layers import Dropout
  • something else?

Can you describe any other behavioural changes of pyforest coming with your PR?


if "," not in import_statement:
process(import_statement)
else:
Copy link
Author

@triper1022 triper1022 Jun 24, 2021

Choose a reason for hiding this comment

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

Thanks for reply!

My PR doesn't affect any original behaviors.

At first,
PR uses new line 70. to judge whether the import statement includes multiple imports.

if "," not in import_statement,
"from keras.layers import LSTM" still behaves as original code
of original line 63, which is similar with new line 63~68.

if "," is in import_statement,
like "from keras.layers import LSTM, Dropout, Dense",
it will become
"from keras.layers import LSTM"
"from keras.layers import Dropout"
"from keras.layers import Dense" with new line 73~78.

Then, the following behaviors are still the same as the original line 63, 65, 66.

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.

3 participants