You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix statistics.py after the Decimal.as_integer_ratio() changeΒ #70162
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/stevendaprano'closed_at=<Date2016-05-06.12:02:09.068>created_at=<Date2015-12-29.12:49:31.259>labels= ['type-bug', 'library', 'release-blocker']
title='Fix statistics.py after the Decimal.as_integer_ratio() change'updated_at=<Date2016-05-06.12:02:09.066>user='https://github.com/skrah'
I haven't tested that "type(x) is float or type(x) is Decimal" is faster than alternatives ("type(x) in (float, Decimal)", or "isinstance(x, (float, Decimal))", or "hasattr(x, 'as_integer_ratio')") and believe you have tested this.
skrah commented on Dec 29, 2015
skrahmannequin
MannequinAuthor
More actions
No, I haven't done any benchmarks. In a quick test type(x) == float
does not seem any faster than isinstance(x, float), so perhaps we
could reduce the try/except complexity.
skrah commented on Dec 29, 2015
skrahmannequin
MannequinAuthor
More actions
The clear winner for float and Decimal is hasattr(x, 'as_integer_ratio').
The other types are a bit disadvantaged if the lookup fails, but they
go through additional try/excepts anyway.
I believe the current code is well-weighed compromise that optimize different cases ranged for their frequency of occurrence (floats, ints, decimals, fractions, subclasses of int, float, etc and independed numeric types). And new addition unlikely will change the balance too much, but we have to be aware. If Steven have no something to add, the patch LGTM.
skrah commented on Apr 3, 2016
skrahmannequin
MannequinAuthor
More actions
Ping. Just a reminder that it would be nice to get this into 3.6-alpha-1. :)
Activity
skrah commentedon Dec 29, 2015
Here's a fix for the fallout from bpo-25928. I've set it to
release blocker to make sure we don't forget.
serhiy-storchaka commentedon Dec 29, 2015
LGTM.
I haven't tested that "type(x) is float or type(x) is Decimal" is faster than alternatives ("type(x) in (float, Decimal)", or "isinstance(x, (float, Decimal))", or "hasattr(x, 'as_integer_ratio')") and believe you have tested this.
skrah commentedon Dec 29, 2015
No, I haven't done any benchmarks. In a quick test type(x) == float
does not seem any faster than isinstance(x, float), so perhaps we
could reduce the try/except complexity.
skrah commentedon Dec 29, 2015
The clear winner for float and Decimal is hasattr(x, 'as_integer_ratio').
The other types are a bit disadvantaged if the lookup fails, but they
go through additional try/excepts anyway.
serhiy-storchaka commentedon Dec 29, 2015
I believe the current code is well-weighed compromise that optimize different cases ranged for their frequency of occurrence (floats, ints, decimals, fractions, subclasses of int, float, etc and independed numeric types). And new addition unlikely will change the balance too much, but we have to be aware. If Steven have no something to add, the patch LGTM.
skrah commentedon Apr 3, 2016
Ping. Just a reminder that it would be nice to get this into 3.6-alpha-1. :)
berkerpeksag commentedon May 6, 2016
statistics_as_integer_ratio.diff has been committed in 7b2fafd78c1d.