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

SloaneEncyclopedia.find and some other SloaneEncyclopedia.* are broken #34655

Open
dimpase opened this issue Oct 13, 2022 · 1 comment
Open

Comments

@dimpase
Copy link
Member

dimpase commented Oct 13, 2022

As described in https://groups.google.com/d/msgid/sage-support/67ce17aa-056b-49c1-95ad-e5cb75e25ba9n%40googlegroups.com

> SloaneEncyclopedia.find([1,2,3,4,5], 1)

TypeError                     Traceback (most recent call last)
/tmp/ipykernel_447/420583060.py in <cell line: 1>()
----> 1 SloaneEncyclopedia.find([Integer(1),Integer(2),Integer(3),Integer(4),Integer(5)], Integer(1))
~/mambaforge/envs/sage/lib/python3.10/site-packages/sage/databases/sloane.py in find(self, seq, maxresults)
    166         a subsequence.
    167         """
--> 168         self.load()
    169
    170         answer, nanswer = [], 0
~/mambaforge/envs/sage/lib/python3.10/site-packages/sage/databases/sloane.py in load(self)
    275             if len(L) == 0:
    276                 continue
--> 277             m = entry.search(L)
    278             if m:
    279                 seqnum = int(m.group('num'))

TypeError: cannot use a string pattern on a bytes-like object

CC: @PeterLuschny

Component: packages: optional

Issue created by migration from https://trac.sagemath.org/ticket/34655

@dimpase dimpase added this to the sage-9.8 milestone Oct 13, 2022
@sheerluck
Copy link
Contributor

comment:1
--- a/sage/databases/sloane.py
+++ b/sage/databases/sloane.py
@@ -274,7 +274,7 @@
         for L in file_seq:
             if len(L) == 0:
                 continue
-            m = entry.search(L)
+            m = entry.search(L.decode("utf-8"))
             if m:
                 seqnum = int(m.group('num'))
                 msg = m.group('body').strip()
@@ -287,10 +287,13 @@
             for L in file_names:
                 if not L:
                     continue
-                m = entry.search(L)
+                m = entry.search(L.decode("utf-8"))
                 if m:
                     seqnum = int(m.group('num'))
-                    self.__data__[seqnum][3] = m.group('body').strip()
+                    if seqnum in self.__data__:
+                        self.__data__[seqnum][3] = m.group('body').strip()
+                    else:
+                        self.__data__[seqnum] = [seqnum, None, 'unknown', m.group('body').strip()]
             file_names.close()
             self.__loaded_names__ = True
         except KeyError:

@mkoeppe mkoeppe removed this from the sage-9.8 milestone Jan 29, 2023
vbraun pushed a commit to vbraun/sage that referenced this issue Nov 26, 2024
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

motivated by
sagemath#38764 (comment)

fixes
sagemath#38764 (comment)

example:
```sage
      sage: SloaneEncyclopedia[60843]    # optional - sloane_database
      [1, 6, 21, 107, 47176870]

      sage: SloaneEncyclopedia[60843]    # optional - !sloane_database
      Traceback (most recent call last):
      ...
      OSError: The Sloane Encyclopedia database must be installed. Use
e.g.
      'SloaneEncyclopedia.install()' to download and install it.
```
along the way, we

- define `sloane_database` feature (I wonder why it was missing)
- fix `SloaneEncyclopedia` with the code by @sheerluck: https://github.c
om/sheerluck)sagemath#34655 (comment)
1418189098
- fix the problem of `solve()` for rubiks cube of silently choosing the
gap algorithm even when an algorithm is explicitly specified.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38810
Reported by: Kwankyu Lee
Reviewer(s):
vbraun pushed a commit to vbraun/sage that referenced this issue Nov 28, 2024
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

motivated by
sagemath#38764 (comment)

fixes
sagemath#38764 (comment)

example:
```sage
      sage: SloaneEncyclopedia[60843]    # optional - sloane_database
      [1, 6, 21, 107, 47176870]

      sage: SloaneEncyclopedia[60843]    # optional - !sloane_database
      Traceback (most recent call last):
      ...
      OSError: The Sloane Encyclopedia database must be installed. Use
e.g.
      'SloaneEncyclopedia.install()' to download and install it.
```
along the way, we

- define `sloane_database` feature (I wonder why it was missing)
- fix `SloaneEncyclopedia` with the code by @sheerluck: https://github.c
om/sheerluck)sagemath#34655 (comment)
1418189098
- fix the problem of `solve()` for rubiks cube of silently choosing the
gap algorithm even when an algorithm is explicitly specified.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

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

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38810
Reported by: Kwankyu Lee
Reviewer(s):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants