Hướng dẫn python 3.9 fractions gcd - python 3,9 phân số gcd

Vấn đề39350

Được tạo vào ngày 2020-01-16 08:13 bởi Vstinner, lần cuối đã thay đổi 2022-04-11 14:59 bởi quản trị viên. Vấn đề giờ đã kết thúc.2020-01-16 08:13 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Kéo yêu cầuURLTrạng tháiLiên kếtChỉnh sửa
PR 18021hợp nhất Vstinner, 2020-01-16 08:17, 2020-01-16 08:17
PR 18309Đóng Mark.Dickinson, 2020-02-02 10:06, 2020-02-02 10:06
PR 18375hợp nhất Vstinner, 2020-01-16 08:17, 2020-02-06 12:42
PR 18309ĐóngMark.Dickinson, 2020-02-02 10:06*
PR 18375Tin nhắn [12]Mark.Dickinson, 2020-02-02 10:06*
PR 18375Tin nhắn [12] MSG360095 - [Xem]*Tác giả: Stinner Victor [Vstinner] *
bpo-22486 added math.gcd[] and deprecated fractions.gcd[] in Python 3.5: commit 48e47aaa28d6dfdae128142ffcbc4b0642422e90.

The function was deprecated during 4 cycles [3.5, 3.6, 3.7, 3.8]: I propose attached PR to remove it.
MSG360095 - [Xem]*Tác giả: Stinner Victor [Vstinner] *
bpo-22486 added math.gcd[] and deprecated fractions.gcd[] in Python 3.5: commit 48e47aaa28d6dfdae128142ffcbc4b0642422e90.

The function was deprecated during 4 cycles [3.5, 3.6, 3.7, 3.8]: I propose attached PR to remove it.
MSG360111 - [Xem]*
Ngày: 2020-01-16 10:02 MSG361103 - [Xem] MSG360095 - [Xem]*Tác giả: Stinner Victor [Vstinner] *
bpo-22486 added math.gcd[] and deprecated fractions.gcd[] in Python 3.5: commit 48e47aaa28d6dfdae128142ffcbc4b0642422e90.

The function was deprecated during 4 cycles [3.5, 3.6, 3.7, 3.8]: I propose attached PR to remove it.
MSG360111 - [Xem]*
Ngày: 2020-01-16 10:02 MSG361103 - [Xem]Mark.Dickinson, 2020-02-02 10:06*
PR 18375Tin nhắn [12]Mark.Dickinson, 2020-02-02 10:06*
PR 18375Tin nhắn [12]Mark.Dickinson, 2020-02-02 10:06*
PR 18375Tin nhắn [12]Mark.Dickinson, 2020-02-02 10:06*
PR 18375Tin nhắn [12]Mark.Dickinson, 2020-02-02 10:06*
PR 18375
Vstinner, 2020-02-06 12:42
Vstinner, 2020-02-06 12:42
Ngày: 2020-01-16 08:13
Ngày: 2020-01-16 08:13
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
Ngày: 2020-01-16 08:13
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
Vstinner, 2020-02-06 12:42
Vstinner, 2020-02-06 12:42
Vstinner, 2020-02-06 12:42
Vstinner, 2020-02-06 12:42
Vstinner, 2020-02-06 12:42
Tin nhắn [12] MSG360095 - [Xem]Tác giả: Stinner Victor [Vstinner] *Ngày: 2020-01-16 08:13
bpo-22486 added math.gcd[] and deprecated fractions.gcd[] in Python 3.5: commit 48e47aaa28d6dfdae128142ffcbc4b0642422e90.

The function was deprecated during 4 cycles [3.5, 3.6, 3.7, 3.8]: I propose attached PR to remove it.
MSG360111 - [Xem]Ngày: 2020-01-16 10:02
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
resolution: fixed
messages: + msg361613

Tác giả: Miro Hrončok [Hroncok] *

Ngày: 2020-01-31 12:52Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
messages: + msg361481
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
pull_requests: + pull_request17685
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]

Tác giả: Miro Hrončok [Hroncok] *

Ngày: 2020-01-31 12:52Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
messages: + msg361103
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
resolution: fixed
stage: patch review -> resolved
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
New changeset 4691a2f2a2b8174a6c958ce6976ed5f3354c9504 by Victor Stinner in branch 'master':
bpo-39350: Remove deprecated fractions.gcd[] [GH-18021]
//github.com/python/cpython/commit/4691a2f2a2b8174a6c958ce6976ed5f3354c9504
MSG361103 - [Xem]
stage: patch review
pull_requests: + pull_request17416
Tác giả: Miro Hrončok [Hroncok] *Ngày: 2020-01-31 12:52
I believe there is a regression here.

numpy fails to build with Python 3.9.0a3.

________________________ TestMatmul.test_matmul_object _________________________
self = 
    def test_matmul_object[self]:
        import fractions
    
        f = np.vectorize[fractions.Fraction]
        def random_ints[]:
            return np.random.randint[1, 1000, size=[10, 3, 3]]
>       M1 = f[random_ints[], random_ints[]]
f          = 
fractions  = 
random_ints = 
self       = 
numpy/core/tests/test_multiarray.py:6259: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
numpy/lib/function_base.py:2091: in __call__
    return self._vectorize_call[func=func, args=vargs]
numpy/lib/function_base.py:2161: in _vectorize_call
    ufunc, otypes = self._get_ufunc_and_otypes[func=func, args=args]
numpy/lib/function_base.py:2121: in _get_ufunc_and_otypes
    outputs = func[*inputs]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cls = , numerator = 483, denominator = 809
    def __new__[cls, numerator=0, denominator=None, *, _normalize=True]:
        """Constructs a Rational.
    
        Takes a string like '3/2' or '1.5', another Rational instance, a
        numerator/denominator pair, or a float.
    
        Examples
        --------
    
        >>> Fraction[10, -8]
        Fraction[-5, 4]
        >>> Fraction[Fraction[1, 7], 5]
        Fraction[1, 35]
        >>> Fraction[Fraction[1, 7], Fraction[2, 3]]
        Fraction[3, 14]
        >>> Fraction['314']
        Fraction[314, 1]
        >>> Fraction['-35/4']
        Fraction[-35, 4]
        >>> Fraction['3.1415'] # conversion from numeric string
        Fraction[6283, 2000]
        >>> Fraction['-47e-2'] # string may include a decimal exponent
        Fraction[-47, 100]
        >>> Fraction[1.47]  # direct construction from float [exact conversion]
        Fraction[6620291452234629, 4503599627370496]
        >>> Fraction[2.25]
        Fraction[9, 4]
        >>> Fraction[Decimal['1.47']]
        Fraction[147, 100]
    
        """
        self = super[Fraction, cls].__new__[cls]
    
        if denominator is None:
            if type[numerator] is int:
                self._numerator = numerator
                self._denominator = 1
                return self
    
            elif isinstance[numerator, numbers.Rational]:
                self._numerator = numerator.numerator
                self._denominator = numerator.denominator
                return self
    
            elif isinstance[numerator, [float, Decimal]]:
                # Exact conversion
                self._numerator, self._denominator = numerator.as_integer_ratio[]
                return self
    
            elif isinstance[numerator, str]:
                # Handle construction from strings.
                m = _RATIONAL_FORMAT.match[numerator]
                if m is None:
                    raise ValueError['Invalid literal for Fraction: %r' %
                                     numerator]
                numerator = int[m.group['num'] or '0']
                denom = m.group['denom']
                if denom:
                    denominator = int[denom]
                else:
                    denominator = 1
                    decimal = m.group['decimal']
                    if decimal:
                        scale = 10**len[decimal]
                        numerator = numerator * scale + int[decimal]
                        denominator *= scale
                    exp = m.group['exp']
                    if exp:
                        exp = int[exp]
                        if exp >= 0:
                            numerator *= 10**exp
                        else:
                            denominator *= 10**-exp
                if m.group['sign'] == '-':
                    numerator = -numerator
    
            else:
                raise TypeError["argument should be a string "
                                "or a Rational instance"]
    
        elif type[numerator] is int is type[denominator]:
            pass # *very* normal case
    
        elif [isinstance[numerator, numbers.Rational] and
            isinstance[denominator, numbers.Rational]]:
            numerator, denominator = [
                numerator.numerator * denominator.denominator,
                denominator.numerator * numerator.denominator
                ]
        else:
            raise TypeError["both arguments should be "
                            "Rational instances"]
    
        if denominator == 0:
            raise ZeroDivisionError['Fraction[%s, 0]' % numerator]
        if _normalize:
            if type[numerator] is int is type[denominator]:
                # *very* normal case
                g = math.gcd[numerator, denominator]
                if denominator < 0:
                    g = -g
            else:
>               g = _gcd[numerator, denominator]
E               NameError: name '_gcd' is not defined
__class__  = 
_normalize = True
cls        = 
denominator = 809
numerator  = 483
self       = 
/usr/lib64/python3.9/fractions.py:164: NameError


This removed _gcd, but it is still called in:

//github.com/python/cpython/blob/58a4054760bffbb20aff90290dd0f3554f7bea42/Lib/fractions.py#L164

Chủ Đề