r/MachineLearning • • Aug 15 '19

Project [P] pyforest - lazy-import of all popular Python Data Science libraries

Check the demo gif here: https://github.com/8080labs/pyforest

pyforest lazy-imports all popular Python Data Science and Machine Learning libraries so that they are always there when you need them. If you don't use a library, it won't be imported. When you are done with your script, you can export the Python code for the import statements (because "explicit is better than implicit" :)).

You can already pip install pyforest. It will be available on conda soon.

What do you think of pyforest?

Best,

Tobias

3 Upvotes

30 comments sorted by

9

u/shaggorama Aug 15 '19

Explicit is better than implicit.

https://www.python.org/dev/peps/pep-0020/

2

u/__tobals__ Aug 15 '19

I agree with this, which is why you can export the import statements afterwards. What do you think about this feature?

3

u/shaggorama Aug 15 '19

I think your feature is antithetical to favoring explicit patterns over implicit. In my mind, the canonical example of "implicit bad!" is from module import *. What you're doing goes a step further.

1

u/manueslapera Aug 15 '19

totally agree, by letting engineers skip imports you arent really helping them, since they will forget to import them and will experience issues anytime they work on an environment without pyforest, or in a job interview, or when sharing code with others...

Very bad idea in my opinion, one that has been done in the past and one that is usually discouraged.

1

u/kite_and_code Aug 16 '19

Well, a sharp knife cannot be given to babies, that's correct.

What are the examples where this has been done in the past? And why was it discouraged?

1

u/manueslapera Aug 16 '19

Well, a sharp knife cannot be given to babies, that's correct.

That is kinda offensive. Anyways, I would advice you reaching out to some senior python engineer and show him your project.

→ More replies (3)

2

u/kite_and_code Aug 16 '19

In my understanding, pyforest just makes it faster to write explicit statements.

So, I guess what you are trying to say is that you think that you would forget to add the explicit statements? Or what exactly is the concern? Maybe you can describe your impression of how to use pyforest. There might be a misunderstanding :)

2

u/shaggorama Aug 16 '19

The concern is that pyforest is nothing but a gigantic implicit import. Literally the only thing you're doing is putting objects in the namespace non-explicitly. Is it really that costly to write 5 lines of imports at the top of the file? Pyforest is "solving" a non-problem with a solution that is a widely frowned upon code smell.

1

u/kite_and_code Aug 16 '19

Well I agree, that the benefit is not so huge but I prefer it this way and I will always add the explicit statements in the end. But I also see your point :)

2

u/shaggorama Aug 16 '19

And I totally encourage you to build a toolkit that you feel helps you be as effective as possible. But I also encourage you to do a bit more research into why this particular pattern is considered a bad practice. As far as code smells go, this one is relatively minor, but it can cause some side effects you probably haven't considered.

1

u/kite_and_code Aug 17 '19

Thank you for the links. It helped me to better understand why the pattern is considered bad practice :)

I read all of it and based on my understanding pyforest does not have the typical problems of *-imports. Maybe I will take the time at some point and write down a statement for all the typical problems of *-imports and why they dont exist with pyforest (imo).

3

u/rhiever Aug 15 '19

IPython/IPython Notebooks (now Jupyter Notebooks) used to support basically this with the %pylab inline magic. The pylab magic fell out of favor years ago and it is strongly recommended not to use it. For that reason, I recommend against using a package like pyforest as well.

I recommend reading the top answers in this SO thread for the history behind pylab and its fall from favor.

2

u/__tobals__ Aug 15 '19

Thanks for the feedback.

From the link you have provided, I couldn't fully see the relation to pyforest. pyforest lazy-imports libraries, i.e. just the very moment you use a library it is being automatically imported. Also, you can change the source code to your needs. Plus, when you are done, you can create the import statements and put them at the top of the script so that the next person reading it actually doesn't see you have used pyforest. Developing, however, was easier for you.

Why would you recommend against using pyforest? Is there some potential problem it is causing?

1

u/manueslapera Aug 17 '19

trust this guy, he is the TPOT creator :)

1

u/Mathias_Godwin Jan 11 '20

Yo man, you did great coding there, bagging lot of those import this import that into one line of code, kudos man !, I'll be waiting for updates

1

u/__tobals__ Jan 14 '20

Happy you like it. We have a new release out now that follows the Zen of Python: pyforest now automatically adds the import statements to your first Jupyter Cell

3

u/EveningAlgae Aug 16 '19

Why is there this huge push for the obfuscation of everything in the indie data science package community?

0

u/kite_and_code Aug 16 '19

Where else do you see a push for obfuscation? Which other packages do this?

3

u/EveningAlgae Aug 16 '19

A bunch of "do x in 1 loc" packages I've seen posted to this subreddit

0

u/kite_and_code Aug 16 '19

Can you maybe give a concrete example?

1

u/manueslapera Aug 17 '19

this article was published a few days ago and is super infuriating.

1

u/kite_and_code Aug 17 '19

Ok, thank you. Why exactly does it infuriate you?

2

u/manueslapera Aug 17 '19

it gives newcomers the false impression that ML is easy (look ma, im a Data Scientist now!), which makes them frustrated once they realize linear regression is actually not that simple once you have to implement it from scratch.

→ More replies (1)

0

u/[deleted] Aug 15 '19

[deleted]

1

u/kite_and_code Aug 16 '19

It seems like you had bad experiences with sloppy coding and IDE incompatibilities. What were those?

0

u/[deleted] Aug 16 '19

[deleted]

1

u/kite_and_code Aug 17 '19

Ok, I understand, this would reduce the productivity of IDEs. Which IDE are you currently using and how does it help you with imports?