Skip to content
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

sage.misc.prandom misses several functions added in Python 3 #34973

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

Sandstorm831
Copy link
Contributor

This is my pull request originally created on trac, which I thought pushing on github.
Fixes #32439

@Sandstorm831
Copy link
Contributor Author

Hello everyone, I have created this pull request in view of changes committed by me in the open issue #32439, Please review this pull request and tell if there are changes that needs to be done on my side.

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2023

Codecov Report

Base: 88.58% // Head: 88.59% // Increases project coverage by +0.01% 🎉

Coverage data is based on head (948c4c6) compared to base (c017a6a).
Patch coverage: 83.33% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #34973      +/-   ##
===========================================
+ Coverage    88.58%   88.59%   +0.01%     
===========================================
  Files         2140     2140              
  Lines       397273   397279       +6     
===========================================
+ Hits        351933   351988      +55     
+ Misses       45340    45291      -49     
Impacted Files Coverage Δ
src/sage/misc/prandom.py 97.67% <83.33%> (-2.33%) ⬇️
src/sage/categories/super_modules_with_basis.py 96.29% <0.00%> (-3.71%) ⬇️
...rc/sage/categories/super_lie_conformal_algebras.py 95.00% <0.00%> (-1.67%) ⬇️
src/sage/schemes/elliptic_curves/hom_velusqrt.py 94.88% <0.00%> (-0.79%) ⬇️
src/sage/sets/integer_range.py 91.41% <0.00%> (-0.51%) ⬇️
...ge/schemes/elliptic_curves/weierstrass_morphism.py 93.01% <0.00%> (-0.44%) ⬇️
src/sage/rings/polynomial/ore_polynomial_ring.py 89.40% <0.00%> (-0.43%) ⬇️
src/sage/rings/padics/local_generic.py 90.43% <0.00%> (-0.39%) ⬇️
src/sage/schemes/elliptic_curves/ell_generic.py 93.37% <0.00%> (-0.28%) ⬇️
src/sage/rings/polynomial/polynomial_ring.py 93.90% <0.00%> (-0.13%) ⬇️
... and 20 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Sandstorm831
Copy link
Contributor Author

@kwankyu Sir, can you review this pull request, or tell someone to for the review.

@kwankyu kwankyu requested a review from videlec February 9, 2023 11:25
@Sandstorm831
Copy link
Contributor Author

@videlec @kwankyu sir can anyone tell what needs to be done ahead in this PR.

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 16, 2023

@Sandstorm831
Copy link
Contributor Author

Don't I have to add more functions or add class, as in that case I would add that code first and make my code clean.

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 16, 2023

Yes, that's why I set it to "needs work".

There's no need for a PR to fix everything in an issue at the same time; but those parts that you do fix need to pass their tests. I recommend that you expand the PR description to say more precisely what this PR does.

One difficulty here is to achieve compatibility with different versions. Some of the functions mentioned in #32439 are only added in Python 3.9 (or later?), but Sage still supports Python >= 3.8.

@Sandstorm831
Copy link
Contributor Author

I think, I would correct my code first to make sure tests passing. And then describe my PRs purpose as completing the whole issue

@Sandstorm831
Copy link
Contributor Author

@mkoeppe sir, I was trying to fix failing tests, I recognized that none of them was caught in my machine, and all tests are working fine. Can you tell me how should I proceed ?

@mkoeppe
Copy link
Contributor

mkoeppe commented Feb 24, 2023

As I said:

One difficulty here is to achieve compatibility with different versions. Some of the functions mentioned in #32439 are only added in Python 3.9 (or later?), but Sage still supports Python >= 3.8.

So you may want to test using Python 3.8 on your machine.

@Sandstorm831
Copy link
Contributor Author

Sandstorm831 commented Feb 25, 2023

@mkoeppe, indeed the failing tests are due to fact that those features appeared in python 3.9 and not in python 3.8.
So should I write those features from scratch ?

@Sandstorm831
Copy link
Contributor Author

@mkoeppe , can you tell me what should I do further ?

@tobiasdiez tobiasdiez mentioned this pull request Mar 31, 2023
5 tasks
@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 12, 2023

can you tell me what should I do further ?

To move this PR forward, you can just cut out these functions that were only added in Python 3.9.

In a follow-up PR, to be merged when we drop Python 3.8, these additional functions can then be added.

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 23, 2023
    
<!-- Please provide a concise, informative and self-explanatory title.
-->
<!-- Don't put issue numbers in the title. Put it in the Description
below. -->
<!-- For example, instead of "Fixes sagemath#12345", use "Add a new method to
multiply two integers" -->

### 📚 Description

In preparation for important package upgrades, we remove support for
Python v3.8. (Almost) all occurrences of "Python 3.8" are removed from
the codebase. There are still some comments left that essentially say
that in newer versions things can be simplified, but I didn't touch
those and leave them for follow-up PRs.

This will help with:
-  PRs that require Python 3.9 or above, such as
sagemath#34973 and
sagemath#35188.
- Upgrades of Python packages that have dropped support for Python 3.8
because they follow NEP 29 and have already released a new major version
that drops support according to the NEP 29 schedule.
  - NetworkX 3.2 (expected 2023-??; version 3.1 was released 2023-04,
see sagemath#35671)
  - sagemath#34816
  - sagemath#35703
  - See also sagemath#32074.

Test run: https://github.com/tobiasdiez/sage/actions/runs/4586981626

<!-- Describe your changes here in detail. -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x
]`. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#35404
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik, Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 27, 2023
    
<!-- Please provide a concise, informative and self-explanatory title.
-->
<!-- Don't put issue numbers in the title. Put it in the Description
below. -->
<!-- For example, instead of "Fixes sagemath#12345", use "Add a new method to
multiply two integers" -->

### 📚 Description

In preparation for important package upgrades, we remove support for
Python v3.8. (Almost) all occurrences of "Python 3.8" are removed from
the codebase. There are still some comments left that essentially say
that in newer versions things can be simplified, but I didn't touch
those and leave them for follow-up PRs.

This will help with:
-  PRs that require Python 3.9 or above, such as
sagemath#34973 and
sagemath#35188.
- Upgrades of Python packages that have dropped support for Python 3.8
because they follow NEP 29 and have already released a new major version
that drops support according to the NEP 29 schedule.
  - NetworkX 3.2 (expected 2023-??; version 3.1 was released 2023-04,
see sagemath#35671)
  - sagemath#34816
  - sagemath#35703
  - See also sagemath#32074.

Test run: https://github.com/tobiasdiez/sage/actions/runs/4586981626

<!-- Describe your changes here in detail. -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x
]`. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#35404
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik, Matthias Köppe
src/sage/misc/prandom.py Outdated Show resolved Hide resolved
src/sage/misc/prandom.py Outdated Show resolved Hide resolved
src/sage/misc/prandom.py Outdated Show resolved Hide resolved
src/sage/misc/prandom.py Outdated Show resolved Hide resolved
src/sage/misc/prandom.py Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Nov 2, 2023

Documentation preview for this PR (built with commit 4d368e5; changes) is ready! 🎉

@mkoeppe
Copy link
Contributor

mkoeppe commented Nov 3, 2023

**********************************************************************
File "src/sage/misc/prandom.py", line 418, in sage.misc.prandom.choices
Failed example:
    choices(data, k=5) #random
Exception raised:
    Traceback (most recent call last):
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.prandom.choices[1]>", line 1, in <module>
        choices(data, k=Integer(5)) #random
      File "/home/runner/work/sage/sage/src/sage/misc/prandom.py", line 423, in choices
        return _pyrand().choices(population, weights=weights, cum_weights=cum_weights, k=k)
    AttributeError: 'Random' object has no attribute 'choices'
**********************************************************************
File "src/sage/misc/prandom.py", line 420, in sage.misc.prandom.choices
Failed example:
    choices((2,3,4), cum_weights=(0.2, 0.7, 1.0), k=10) #random
Exception raised:
    Traceback (most recent call last):
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.prandom.choices[2]>", line 1, in <module>
        choices((Integer(2),Integer(3),Integer(4)), cum_weights=(RealNumber('0.2'), RealNumber('0.7'), RealNumber('1.0')), k=Integer(10)) #random
      File "/home/runner/work/sage/sage/src/sage/misc/prandom.py", line 423, in choices
        return _pyrand().choices(population, weights=weights, cum_weights=cum_weights, k=k)
    AttributeError: 'Random' object has no attribute 'choices'
**********************************************************************
File "src/sage/misc/prandom.py", line 432, in sage.misc.prandom.randbytes
Failed example:
    randbytes(10) #random
Exception raised:
    Traceback (most recent call last):
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.prandom.randbytes[0]>", line 1, in <module>
        randbytes(Integer(10)) #random
      File "/home/runner/work/sage/sage/src/sage/misc/prandom.py", line 435, in randbytes
        return _pyrand().randbytes(n)
    AttributeError: 'Random' object has no attribute 'randbytes'
**********************************************************************
File "src/sage/misc/prandom.py", line 447, in sage.misc.prandom.triangular
Failed example:
     sample = [triangular(1.0, 5.0, 2.0) for i in range(1, 5)]; sample #random
Exception raised:
    Traceback (most recent call last):
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1142, in compile_and_execute
        compiled = compiler(example)
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 676, in compiler
        code = compile(example.source, filename, "single",
      File "<doctest sage.misc.prandom.triangular[0]>", line 1
        sample = [triangular(RealNumber('1.0'), RealNumber('5.0'), RealNumber('2.0')) for i in range(Integer(1), Integer(5))]; sample #random
    IndentationError: unexpected indent
**********************************************************************
File "src/sage/misc/prandom.py", line 449, in sage.misc.prandom.triangular
Failed example:
    all(s >= 1.0 for s in sample) #random
Exception raised:
    Traceback (most recent call last):
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 709, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/runner/work/sage/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.misc.prandom.triangular[1]>", line 1, in <module>
        all(s >= RealNumber('1.0') for s in sample) #random
    TypeError: 'function' object is not iterable
**********************************************************************

https://github.com/sagemath/sage/actions/runs/6738996646/job/18319650965?pr=34973#step:11:7599

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sage.misc.prandom misses several functions added in Python 3
4 participants