Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread Kapil Bansal
I do something similar to what math.isclose() provides. Can anyone please
review this PR:-
https://github.com/django/django/pull/14162

On Mon, Mar 22, 2021, 4:53 PM James Bennett  wrote:

> There are ways to check "close enough" equality for floats. There's
> even the math.isclose() function which is arbitrarily tune-able:
>
> https://docs.python.org/3/library/math.html#math.isclose
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django developers  (Contributions to Django itself)" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-developers/oVWKJUXTb1o/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAL13Cg9kom4X57gaUp%2Bq8%3DqdEF_33hTEZ9AMi8bucXjaKXsX8Q%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAM_E0q6CZHooYBkojJA7ZjB-pMaC4cAAN9S9K5w1OqyQ50SBrg%40mail.gmail.com.


Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread James Bennett
There are ways to check "close enough" equality for floats. There's
even the math.isclose() function which is arbitrarily tune-able:

https://docs.python.org/3/library/math.html#math.isclose

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAL13Cg9kom4X57gaUp%2Bq8%3DqdEF_33hTEZ9AMi8bucXjaKXsX8Q%40mail.gmail.com.


Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread Jacob Rief
The problem with modulo on floats is, that due to rounding errors it often 
created weird results,
for instance in Python-3.8 this happens: 3.5 % 0.1 = 0.09981
This btw. also applies to the builtin divmod and math.fmod functions.
Therefore I proposed to do it via classic division and check if it's near 
enough to an integer value.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/ce5717e1-db00-4c76-b98b-908a5202470bn%40googlegroups.com.


Re: Fellow Reports - March 2021

2021-03-22 Thread Mariusz Felisiak
Week ending March 21, 2021 

*Triaged: *
   https://code.djangoproject.com/ticket/32547 - 
assertHTMLEqual()/assertHTMLNotEqual() allow invalid HTML. (accepted) 
   https://code.djangoproject.com/ticket/32549 - Add `Q.empty()` to check 
for nested empty Q objects like `Q(Q())` (wontfix) 
   https://code.djangoproject.com/ticket/32548 - Support passing 
conditional expressions to Q(). (accepted) 
   https://code.djangoproject.com/ticket/32550 - Translation Error 
(invalid) 
   https://code.djangoproject.com/ticket/32545 - Admin foreign key raw 
inputs are too small when referring to a UUID field (accepted) 
   https://code.djangoproject.com/ticket/32546 - Meta.ordering fields must 
not be included in GROUP BY clause (accepted) 
   https://code.djangoproject.com/ticket/32551 - Need a direct reference of 
MEDIA_URL and MEDIA_ROOT in file uploads (invalid) 
   https://code.djangoproject.com/ticket/32553 - Allow 
UserAttributeSimilarityValidator to validate against fields of related 
models (wontfix) 
   https://code.djangoproject.com/ticket/32555 - DecimalField Rounding 
inconsistency (PostgreSQL) (duplicate) 
   https://code.djangoproject.com/ticket/24522 - Add --random option to 
test command to run test cases in random order (accepted) 
   https://code.djangoproject.com/ticket/32556 - assertHTMLEqual gives a 
confusing error message with empty attributes (accepted) 
   https://code.djangoproject.com/ticket/32560 - Make --pdb cooperate with 
--buffer (accepted) 
   https://code.djangoproject.com/ticket/32564 - admin/base.html : Add 
block "end_of_body" for JS includes (wontfix) 
   https://code.djangoproject.com/ticket/32563 - Cannot override database 
used with RelatedManager (invalid) 
   https://code.djangoproject.com/ticket/32570 - Documentation example for 
AppConfig is overloaded (accepted) 
   https://code.djangoproject.com/ticket/32571 - CsrfViewMiddleware assumes 
referer header can be parsed (accepted) 
   https://code.djangoproject.com/ticket/32557 - Fail tests when unraisable 
exceptions occur (accepted) 
   https://code.djangoproject.com/ticket/32558 - Fail tests when unhandled 
thread exceptions occur (accepted) 
   https://code.djangoproject.com/ticket/32574 - Add support for Proj 8.x. 
(accepted) 
   https://code.djangoproject.com/ticket/32575 - Add support for SpatiaLite 
5.x. (accepted) 
   https://code.djangoproject.com/ticket/32576 - Correct documentation for 
dumpdata --exclude (accepted) 
   https://code.djangoproject.com/ticket/18096 - Overiding delete 
permissions in the Admin (fixed) 

*Reviewed/committed: *
   https://github.com/django/django/pull/14120 - Fixed #32540 -- Optimized 
DiscoverRunner.build_suite() by calling find_top_level() only if 
is_discoverable() is true. 
   https://github.com/django/django/pull/14114 - Refs #32508 -- Raised 
ValueError instead of using "assert" in lazy(). 
   https://github.com/django/django/pull/14129 - Fixed #32536 -- Added 
links to BaseDetailView/BaseListView.get() methods in CBV docs. 
   https://github.com/django/django/pull/14122 - Fixed #32546 -- Avoided 
Meta.ordering columns in GROUP BY clauses. 
   https://github.com/django/django/pull/14132 - Refs #32508 -- Raised 
ImproperlyConfigured instead of using "assert" in SessionStorage. 
   https://github.com/django/django/pull/14119 - Refs #24121 -- Added 
__repr__() to Origin and Template. 
   https://github.com/django/django/pull/14139 - Fixed #32560 -- Fixed test 
runner with --pdb and --buffer on fail/error. 
   https://github.com/django/django/pull/14126 - Fixed #32548 -- Fixed 
crash when combining Q() objects with boolean expressions. 
   https://github.com/django/django/pull/14143 - Fixed #32547 -- Corrected 
notes about validation in HTML assertions docs. 
   https://github.com/django/django/pull/12580 - Fixed #31370 -- Added 
support for parallel tests with --buffer. 
   https://github.com/django/django/pull/14144 - Fixed #32556 -- Fixed 
assertHTMLEqual() to handle empty string as boolean attributes value. 
   https://github.com/django/django/pull/13829 - Fixed #16010 -- Added 
Origin header checking to CSRF middleware. 
   https://github.com/django/django/pull/14135 - Refs #32508 -- Raised 
Type/ValueError instead of using "assert" in django.core. 
   https://github.com/django/django/pull/14151 - Fixed #32571 -- Made 
CsrfViewMiddleware handle invalid URLs in Referer header. 
   https://github.com/django/django/pull/14152 - Fixed #32570 -- Removed 
unnecessary default_auto_field in app config example. 
   https://github.com/django/django/pull/14148 - Fixed #32556 -- Fixed 
handling empty string as non-boolean attributes value by assertHTMLEqual(). 

*Reviewed: *
   https://github.com/django/django/pull/14031 - Fixed #32466 -- Corrected 
autocomplete to_field resolution for complex cases. 

*Authored: *
   https://github.com/django/django/pull/14133 - Fixed #32353 -- Confirmed 
support for PROJ 7.X. 
   https://github.com/django/django/pull/14145 - Corrected signatures in 
"Advan

Re: Proposal to add attribute 'step' to FloatField and DecimalField

2021-03-22 Thread 'Adam Johnson' via Django developers (Contributions to Django itself)
Use the modulo operator

In [1]: 4.5 % 1.5
Out[1]: 0.0

https://en.wikipedia.org/wiki/Modulo_operation
https://docs.python.org/3/reference/expressions.html?highlight=modulo#binary-arithmetic-operations

On Sun, 21 Mar 2021 at 23:47, Jacob Rief  wrote:

> Say, you have a value and step, both are floats, then if value / step is
> can be represented
> integer, the validation is fulfilled. Otherwise if the result has to be
> rounded to become an integer,
> a ValidationError shall be raised.
> Be aware of rounding errors.
>
> On Sunday, March 21, 2021 at 9:53:43 PM UTC+1 kapilbansal...@gmail.com
> wrote:
>
>> Hi everyone,
>> I am working on this and I have a question.
>> How to write validation check for this?
>> Due to python floating point issues, I am not able to validate whether
>> field value is of given step_size or not
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/11953496-ad4c-49cd-857d-e8723692197bn%40googlegroups.com
> 
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM0DLU2Pbr%3D9HCwT0fGq5qtCeyP4rEyqrCSasFCqaTQkLA%40mail.gmail.com.