Skip to content

Commit

Permalink
Trac #31054: 2 internet doctests failing in findstat.py
Browse files Browse the repository at this point in the history
On Ubuntu 18.04 with `9.3.beta4, Release Date: 2020-12-14` the command
{{{
sage -t --optional=sage,internet src/sage/databases/findstat.py
}}}

gives

{{{
sage -t --warn-long 72.7 --random-seed=0 src/sage/databases/findstat.py
**********************************************************************
File "src/sage/databases/findstat.py", line 118, in
sage.databases.findstat
Failed example:
    r = findstat(Permutations, lambda pi: pi.saliances()[0], depth=2); r
# optional -- internet
Expected:
    0: St000476oMp00099oMp00127 (quality [100, 100])
    1: St001497oMp00119oMp00127 with offset 1 (quality [100, 100])
    2: St000147oMp00027oMp00127 (quality [96, 100])
    3: St000054oMp00064oMp00062 with offset 1 (quality [88, 100])
    4: St000740oMp00062 with offset 1 (quality [87, 100])
    ...
Got:
     0: St000740oMp00066 with offset 1 (quality [100, 100])
     1: St000476oMp00099oMp00127 (quality [100, 100])
     2: St001497oMp00119oMp00127 with offset 1 (quality [100, 100])
     3: St000147oMp00027oMp00127 (quality [96, 100])
     4: St000054oMp00066oMp00149 with offset 1 (quality [89, 100])
     5: St000141oMp00025oMp00127 (quality [87, 100])
     6: St001291oMp00127 with offset 1 (quality [87, 86])
     7: St000051oMp00061oMp00069 (quality [87, 86])
     8: St000316oMp00025oMp00127 (quality [87, 86])
     9: St000653oMp00129oMp00127 (quality [87, 86])
    10: St001184oMp00127oMp00064 with offset 1 (quality [87, 86])
    11: St001227oMp00028oMp00127 (quality [87, 86])
    12: St001480oMp00032oMp00127 (quality [87, 86])
    13: St000066oMp00063oMp00149 with offset 1 (quality [54, 86])
    14: St000840oMp00146oMp00127 (quality [18, 86])
    15: St000199oMp00063 with offset 1 (quality [15, 71])
    16: St000193oMp00004oMp00063 with offset 1 (quality [15, 71])
    17: St000200oMp00063oMp00062 with offset 1 (quality [15, 71])
**********************************************************************
File "src/sage/databases/findstat.py", line 129, in
sage.databases.findstat
Failed example:
    r[4].info()
# optional -- internet
Expected:
    after adding 1 to every value
    and applying
        Mp00062: Lehmer-code to major-code bijection: Permutations ->
Permutations
    to the objects (see `.compound_map()` for details)
    <BLANKLINE>
    your input matches
        St000740: The last entry of a permutation.
    <BLANKLINE>
    among the values you sent, 87 percent are actually in the database,
    among the distinct values you sent, 100 percent are actually in the
database
Got:
    after adding 1 to every value
    and applying
        Mp00149: Lehmer code rotation: Permutations -> Permutations
        Mp00066: inverse: Permutations -> Permutations
    to the objects (see `.compound_map()` for details)
    <BLANKLINE>
    your input matches
        St000054: The first entry of the permutation.
    <BLANKLINE>
    among the values you sent, 89 percent are actually in the database,
    among the distinct values you sent, 100 percent are actually in the
database
**********************************************************************
1 item had failures:
   2 of  16 in sage.databases.findstat
    [392 tests, 2 failures, 42.52 s]
----------------------------------------------------------------------
sage -t --warn-long 72.7 --random-seed=0 src/sage/databases/findstat.py
# 2 doctests failed
----------------------------------------------------------------------
}}}

URL: https://trac.sagemath.org/31054
Reported by: slabbe
Ticket author(s): Martin Rubey
Reviewer(s): Sébastien Labbé
  • Loading branch information
Release Manager committed Jan 2, 2021
2 parents 1293960 + 88d7a84 commit b297248
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions src/sage/databases/findstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,43 @@
advertise yet another way to pass values to FindStat::
sage: r = findstat(Permutations, lambda pi: pi.saliances()[0], depth=2); r # optional -- internet
0: St000476oMp00099oMp00127 (quality [100, 100])
1: St001497oMp00119oMp00127 with offset 1 (quality [100, 100])
2: St000147oMp00027oMp00127 (quality [96, 100])
3: St000054oMp00064oMp00062 with offset 1 (quality [88, 100])
4: St000740oMp00062 with offset 1 (quality [87, 100])
0: St000740oMp00066 with offset 1 (quality [100, 100])
...
7: St000051oMp00061oMp00069 (quality [87, 86])
...
Note that some of the matches are up to a global offset, which is
then given. For example, we have::
Note that some of the matches are up to a global offset. For
example, we have::
sage: r[4].info() # optional -- internet
sage: r[0].info() # optional -- internet
after adding 1 to every value
and applying
Mp00062: Lehmer-code to major-code bijection: Permutations -> Permutations
Mp00066: inverse: Permutations -> Permutations
to the objects (see `.compound_map()` for details)
<BLANKLINE>
your input matches
St000740: The last entry of a permutation.
<BLANKLINE>
among the values you sent, 87 percent are actually in the database,
among the values you sent, 100 percent are actually in the database,
among the distinct values you sent, 100 percent are actually in the database
Let us pick another particular result::
sage: s = next(s for s in r if s.statistic().id() == 51); s # optional -- internet
St000051oMp00061oMp00069 (quality [87, 86])
sage: s.info() # optional -- internet
after applying
Mp00069: complement: Permutations -> Permutations
Mp00061: to increasing tree: Permutations -> Binary trees
to the objects (see `.compound_map()` for details)
<BLANKLINE>
your input matches
St000051: The size of the left subtree of a binary tree.
<BLANKLINE>
among the values you sent, 87 percent are actually in the database,
among the distinct values you sent, 86 percent are actually in the database
To obtain the value of the statistic sent to FindStat on a given
object, apply the maps in the list in the given order to this object,
and evaluate the statistic on the result. For example, let us check
Expand Down Expand Up @@ -2426,6 +2436,8 @@ def _element_constructor_(self, id):
id = id.id_str()
if not isinstance(id, str):
raise TypeError("the value '%s' is not a valid FindStat statistic identifier, nor a FindStat statistic query" % id)
else:
id = id.strip()
if FINDSTAT_MAP_SEPARATOR in id:
return FindStatCompoundStatistic(id)
if not re.match(FINDSTAT_STATISTIC_REGEXP, id) or int(id[2:]) <= 0:
Expand Down Expand Up @@ -2712,21 +2724,22 @@ def __init__(self, id, domain=None, check=True):
id = FINDSTAT_STATISTIC_PADDED_IDENTIFIER % id
elif isinstance(id, FindStatCombinatorialStatistic):
id = id.id_str()
self._id = id
if domain is not None:
self._domain = FindStatCollection(domain)
else:
self._domain = None
composition = id.partition("o")
composition = id.partition(FINDSTAT_MAP_SEPARATOR)
self._statistic = FindStatStatistic(composition[0])
if composition[2]:
self._maps = FindStatCompoundMap(composition[2], domain=self._domain)
self._id = self._statistic.id_str() + FINDSTAT_MAP_SEPARATOR + self._maps.id_str()
if self._domain is None:
self._domain = self._maps.domain()
else:
if self._domain is None:
self._domain = self._statistic.domain()
self._maps = FindStatCompoundMap("", domain=self._domain, codomain=self._domain)
self._id = self._statistic.id_str()
if (check
and self._maps.codomain() != self._statistic.domain()):
raise ValueError("the statistic %s cannot be composed with the map %s" % (self._statistic, self._maps))
Expand Down Expand Up @@ -2933,12 +2946,22 @@ def info(self):
<BLANKLINE>
among the values you sent, 17 percent are actually in the database,
among the distinct values you sent, 83 percent are actually in the database
sage: r = FindStatMatchingStatistic("St000042", 1, [17, 83]) # optional -- internet
sage: r.info() # optional -- internet
after adding 1 to every value
<BLANKLINE>
your input matches
St000042: The number of crossings of a perfect matching.
<BLANKLINE>
among the values you sent, 17 percent are actually in the database,
among the distinct values you sent, 83 percent are actually in the database
"""
if self.offset() < 0:
print("after subtracting %s from every value" % (-self.offset()))
if self.offset() > 0:
print("after adding %s to every value" % self.offset())
if self.compound_map():
if len(self.compound_map()):
if self.offset():
print("and applying")
else:
Expand Down Expand Up @@ -3297,6 +3320,8 @@ def _element_constructor_(self, id):
id = id.id_str()
if not isinstance(id, str):
raise TypeError("the value %s is neither an integer nor a string" % id)
else:
id = id.strip()
if FINDSTAT_MAP_SEPARATOR in id:
return FindStatCompoundMap(id)
if not re.match(FINDSTAT_MAP_REGEXP, id) or id == FINDSTAT_MAP_PADDED_IDENTIFIER % 0:
Expand Down Expand Up @@ -3548,8 +3573,7 @@ def __init__(self, id, domain=None, codomain=None, check=True):
self._domain = FindStatCollection(domain)
self._codomain = self._domain
else:
self._id = id
self._maps = [FindStatMap(m) for m in id.split("o")][::-1]
self._maps = [FindStatMap(m) for m in id.split(FINDSTAT_MAP_SEPARATOR)][::-1]
if (check
and not all(self._maps[i].codomain() == self._maps[i+1].domain()
for i in range(len(self._maps)-1))):
Expand All @@ -3562,6 +3586,7 @@ def __init__(self, id, domain=None, codomain=None, check=True):
self._codomain = self._maps[-1].codomain()
else:
self._codomain = FindStatCollection(codomain)
self._id = FINDSTAT_MAP_SEPARATOR.join(m.id_str() for m in reversed(self._maps))

Element.__init__(self, FindStatMaps()) # this is not completely correct, but it works

Expand Down

0 comments on commit b297248

Please sign in to comment.