-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Validate that float_format option is callable #12711
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
Conversation
Some of my travis builds are failing for reasons unclear to me. This is my first attempt at a pandas PR, so I'd love some help if it's available. Also, I'm having a hard time seeing where a test would go for this. I haven't been able to find where option validators are tested. |
can you add a test in |
http://pandas.pydata.org/pandas-docs/stable/contributing.html try:
fix anything if needed
I suspect you have a fairly old fork, which means its tags aren't updating. this is an annoying git/travis thing. |
float_format
option is callablef4f5676
to
6495011
Compare
Just an FYI, as I'm not sure what changes you are adding: every time you push, you start a new build on Travis, and right now you have three builds that haven't been run yet. It seems prudent perhaps to test locally before you push. Also, from a selfish standpoint, I am impatient and would like Travis to run the most recent build for my PR 😄 @jreback: Could you cancel the old builds for this PR? |
@gfyoung: Oy, I wasn't thinking about it triggering builds on the Pandas Travis. (I'm watching it on mine.) I can't have the tests cooking my work computer at the moment, so I was letting Travis handle it for me. |
@gfyoung That's just how things work. I don't see it as a problem. |
@gfyoung you of course have travis running on YOUR own branches, the pydata/pandas builder is just for final confirmation. |
In any case, I think I'm getting close to having this thing ready, @jreback |
https://travis-ci.org/tdhopper/pandas https://travis-ci.org/gfyoung/pandas (@gfyoung), not running on your branch for some reason |
@@ -124,6 +124,7 @@ Bug Fixes | |||
- Bug in numpy compatibility of ``np.round()`` on a ``Series`` (:issue:`12600`) | |||
- Bug in ``Series`` construction with ``Categorical`` and ``dtype='category'`` is specified (:issue:`12574`) | |||
- Bugs in concatenation with a coercable dtype was too aggressive. (:issue:`12411`, :issue:`12045`, :issue:`11594`, :issue:`10571`) | |||
- Bug in `float_format` option with option not being validated as callable. (:issue:`12706`, :issue:`12711`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double back-ticks on float_format
, only list the issue option, not the PR one (e.g. 12706)
@tdhopper yep that looks good. minor doc change. ping when green. |
@tdhopper : Ah, no worries. Just wanted to point that out for future reference. It also was driven partially be selfish motives as I didn't try hard to conceal. 😄 @jreback : Fair point. For future reference, would that be considered valid confirmation in case there is a traffic jam on the main |
@gfyoung no, but its simple better to ping me if you want me to look. But I would certainly fix up your personal branch on travis, it runs MUCH faster as there is NO contention, except your own builds. pydata builds are contending with LOTS of things. |
@@ -803,3 +803,4 @@ def inner(x): | |||
is_str = is_type_factory(str) | |||
is_unicode = is_type_factory(compat.text_type) | |||
is_text = is_instance_factory((str, bytes)) | |||
is_callable = callable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback: This doesn't work because callable
doesn't raise a ValueError. I could overcome this by:
def is_callable(obj):
"""
Parameters
----------
`obj` - the object to be checked
Returns
-------
validator - returns True if object is callable, and
raises ValueError otherwise.
"""
if not callable(obj):
raise ValueError("Value must be an callable")
return True
Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep that would work
355b16c
to
74c17fa
Compare
@jreback: Sadly My current solution (tested fine locally and now running in travis) is adding a This is tricker than I thought! |
74c17fa
to
a974d66
Compare
I think this will work.
|
@jreback: That would exclude callable objects. Maybe it's not a concern, but 😬 |
yeah I suppose. ok, then pls rebase as well. |
a974d66
to
76d0116
Compare
The `float_format` setting takes either None or a callable object that returns a formatted string given a float value. Currently, the setting isn't validated, so cryptic error messages are returned if, for example, a format non-callable format string is given (see \pandas-dev#12704). Add a standard validation method and use it to validate the `float_format` setting.
76d0116
to
086a824
Compare
Rebased and fixed a comment. I'm heading out for the weekend. Thanks for the help Jeff. |
@tdhopper thanks! I changed the approach to use |
Great solution! Much better that way. |
git diff upstream/master | flake8 --diff