Skip to content

Fix tqdm_pandas(tqdm_notebook) by delaying instanciation in tqdm_pandas#192

Merged
casperdcl merged 6 commits intomasterfrom
pandas_notebook_fix
Jul 24, 2016
Merged

Fix tqdm_pandas(tqdm_notebook) by delaying instanciation in tqdm_pandas#192
casperdcl merged 6 commits intomasterfrom
pandas_notebook_fix

Conversation

@lrq3000
Copy link
Copy Markdown
Member

@lrq3000 lrq3000 commented Jul 3, 2016

This fixes #182 but this breaks retrocompatibility since tqdm_pandas does not accept a bar instance anymore (tqdm_pandas(tqdm(leave=True))) but a bar class (tqdm_pandas(tqdm, leave=True)).

/EDIT: fixed backwards compatibility.

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 3, 2016

Coverage Status

Coverage decreased (-0.2%) to 81.25% when pulling ee6abc9 on pandas_notebook_fix into bb53160 on master.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 3, 2016

Current coverage is 79.92% (diff: 15.15%)

Merging #192 into master will decrease coverage by 1.47%

@@             master       #192   diff @@
==========================================
  Files             8          8          
  Lines           527        538    +11   
  Methods           0          0          
  Messages          0          0          
  Branches         99        101     +2   
==========================================
+ Hits            429        430     +1   
- Misses           98        108    +10   
  Partials          0          0          

Powered by Codecov. Last update 1b4d483...7f6c45c

@casperdcl
Copy link
Copy Markdown
Member

Hmm I'd asked about doing it this way instead when creating this feature but since there didn't seem to be a clear advantage back then we stuck witht the current version... this PR is not backwards compatible, but could be fixed.

@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 5, 2016

Yes indeed I thought about it afterwards, we can simply detect whether the
supplied bar argument is a class or an object, and then act accordingly,
this will be backward compatible then :)
Le 5 Jul. 2016 09:07, "Casper da Costa-Luis" [email protected] a
écrit :

Hmm I'd asked about doing it this way instead when creating this feature
but since there didn't seem to be a clear advantage back then we stuck
witht the current version... this PR is not backwards compatible, but could
be fixed.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#192 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ABES3m2JKDZPoAs2WpKLN6npbuD0zWZXks5qSgKxgaJpZM4JD81F
.

@lrq3000 lrq3000 force-pushed the pandas_notebook_fix branch from c6b2252 to 2e74274 Compare July 6, 2016 02:05
@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 6, 2016

I added a deprecation message using tqdm.write(), because I didn't like the warnings module for our purpose since it suppresses warnings by default now as discussed here.

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 6, 2016

Coverage Status

Coverage decreased (-0.8%) to 80.639% when pulling 2e74274 on pandas_notebook_fix into bb53160 on master.

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 6, 2016

Coverage Status

Coverage decreased (-0.8%) to 80.639% when pulling 2e74274 on pandas_notebook_fix into bb53160 on master.

@casperdcl casperdcl force-pushed the pandas_notebook_fix branch from 2e74274 to 787f3b2 Compare July 18, 2016 20:47
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 18, 2016

Coverage Status

Coverage decreased (-0.8%) to 80.639% when pulling 787f3b2 on pandas_notebook_fix into ce2eace on master.

@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 18, 2016

Wow that's great @casperdcl , thank's a lot!

Just out of curiosity, why did you make tqdm_pandas a classmethod? What is the advantage in this case?

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 18, 2016

Coverage Status

Coverage decreased (-3.6%) to 77.758% when pulling f020419 on pandas_notebook_fix into ce2eace on master.

@casperdcl
Copy link
Copy Markdown
Member

because the way you'd re-written it in this PR was function(Class, ...) which is precisely what class methods are for! The nice thing about this is all sub classes automatically inherit the class method, with the correct child class passed as the first argument when invoked.

combined with the fact that an instance is created within the inner function, this means .pandas() only needs to be called once in a program (more precisely, once every time you want to use a different tqdm-like class to handle progress_apply). as in:

tqdm.pandas()
... # any number of `progress_apply` calls will go to terminal
tqdm_gui.pandas()
... # now use gui instead

@casperdcl
Copy link
Copy Markdown
Member

re: python warning confusions, much sad such is. was vaguely aware of this; surely there's a better solution. We could always class TqdmDeprecationWarning(SomethingAppropriate)?

@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 20, 2016

@casperdcl Great about the classmethod, talk about the low entry high ceiling of python, I still often learn new stuff XD

I thought about doing a class for the warning, but how would you raise it? If you raise it as an exception, then the old way of using tqdm_pandas will need to be specifically caught by users, so it breaks retrocompatibility. I do not know of any other way to raise a non-blocking warning in Python than just printing...

@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 20, 2016

But yeah it would be nice to have a standardized way of raising deprecation warnings, because I guess we will get more and more as time goes.

@CrazyPython
Copy link
Copy Markdown
Contributor

CrazyPython commented Jul 21, 2016

@lrq3000 There is! Here's a doc link! ;)

It's just warnings.DeprecationWarning. Learned some new stuff - again!

You can raise warnings using warnings.warn(). Does not crash program.

@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 21, 2016

@CrazyPython Yes but the warning module doesn't emit any output to sys.stderr by default now as reported here except if you modify the filters at the module level, which is considered a bad practice. I tried it with Python 2.7 just to make sure and indeed I had no output, but maybe I used it wrong or maybe the behavior was reverted in Python 3.5 (because it clearly contradicts the documentation you referenced).

@lrq3000
Copy link
Copy Markdown
Member Author

lrq3000 commented Jul 21, 2016

Ok so maybe we can add something like that in ._utils.py:

class TqdmDeprecationWarning(object):
    @staticmethod
    def warn(message, file=sys.stderr):
        file.write('DeprecationWarning: %s' % message)

Then to use:

from ._utils import TqdmDeprecationWarning

TqdmDeprecationWarning.warn('parameter xxx should not be used, prefer xxx')

What do you think about it guys?

@casperdcl casperdcl force-pushed the pandas_notebook_fix branch from f020419 to 7f6c45c Compare July 23, 2016 15:27
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 23, 2016

Coverage Status

Coverage decreased (-1.5%) to 79.926% when pulling 7f6c45c on pandas_notebook_fix into 1b4d483 on master.

@casperdcl casperdcl force-pushed the pandas_notebook_fix branch from 17e0bba to a4974c7 Compare July 24, 2016 13:52
@casperdcl casperdcl force-pushed the pandas_notebook_fix branch 3 times, most recently from 85013f2 to 9fa8cc5 Compare July 24, 2016 14:04
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 24, 2016

Coverage Status

Coverage increased (+12.5%) to 93.886% when pulling 9fa8cc5 on pandas_notebook_fix into 1b4d483 on master.

@casperdcl casperdcl force-pushed the pandas_notebook_fix branch from 9fa8cc5 to 7f6c45c Compare July 24, 2016 14:36
@casperdcl casperdcl merged commit 7f6c45c into master Jul 24, 2016
@casperdcl casperdcl deleted the pandas_notebook_fix branch July 24, 2016 15:30
@casperdcl casperdcl mentioned this pull request Jul 24, 2016
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.

Could the pandas progress bar be used for series objects?

5 participants