Repository: LMFDB/lmfdb

Issue:
Fix dimension table display for Bianchi modular forms
This did not survive migration to postgres.  For example, 
http://localhost:37777/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.4.1
displays blank data and it should display a lot.


Discussion:
If you display all http://beta.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.4.1?start=0&count=50&level_flag=all then it looks like something's wrong in the data (conversion to Postgres)?  
Examples of the problem

http://beta.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.4.1
http://beta.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.8.1
http://beta.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.3.1

There is data in  bmf_dims for these spaces but it does not appear to be getting parsed/processed directly.
From our conversation: could be an issue with strings vs. integers in the keys?
The fact that http://beta.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.4.1 looks so different from  http://beta.lmfdb.org/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.4.1?start=0&count=50&level_flag=all  is another clue.
If you want to see what I believe the tables **should** look like, the mongo db version is still available at prod.lmfdb.xyz, for example, you can compare the links I gave above with

http://prod.lmfdb.xyz/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.4.1
http://prod.lmfdb.xyz/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.8.1
http://prod.lmfdb.xyz/ModularForm/GL2/ImaginaryQuadratic/gl2dims/2.0.3.1


Resolving patch:
diff --git a/lmfdb/bianchi_modular_forms/bianchi_modular_form.py b/lmfdb/bianchi_modular_forms/bianchi_modular_form.py
--- a/lmfdb/bianchi_modular_forms/bianchi_modular_form.py
+++ b/lmfdb/bianchi_modular_forms/bianchi_modular_form.py
@@ -174,33 +174,31 @@ def bmf_field_dim_table(**args):
     bread = [('Bianchi Modular Forms', url_for(".index")), (
         pretty_field_label, ' ')]
     properties = []
+    query = {}
+    query['field_label'] = field_label
     if gl_or_sl=='gl2_dims':
         info['group'] = 'GL(2)'
         info['bgroup'] = '\GL(2,\mathcal{O}_K)'
     else:
         info['group'] = 'SL(2)'
         info['bgroup'] = '\SL(2,\mathcal{O}_K)'
+    if level_flag == 'all':
+        query[gl_or_sl] = {'$exists': True}
+    else:
+        # Only get records where the cuspdial/new dimension is positive for some weight
+        totaldim = gl_or_sl.replace('dims', level_flag) + '_totaldim'
+        query[totaldim] = {'$gt': 0}
     t = ' '.join(['Dimensions of Spaces of {} Bianchi Modular Forms over'.format(info['group']), pretty_field_label])
-    query = {}
-    query['field_label'] = field_label
-    query[gl_or_sl] = {'$exists': True}
-    data = db.bmf_dims.search(query, limit=count, offset=start, info=info)
+    data = list(db.bmf_dims.search(query, limit=count, offset=start, info=info))
     nres = info['number']
+    if not info['exact_count']:
+        info['number'] = nres = db.bmf_dims.count(query)
+        info['exact_count'] = True
     if nres > count or start != 0:
         info['report'] = 'Displaying items %s-%s of %s levels,' % (start + 1, min(nres, start + count), nres)
     else:
         info['report'] = 'Displaying all %s levels,' % nres
 
-    # convert data to a list and eliminate levels where all
-    # new/cuspidal dimensions are 0.  (This could be done at the
-    # search stage, but that requires adding new fields to each
-    # record.)
-    def filter(dat, flag):
-        dat1 = dat[gl_or_sl]
-        return any([int(dat1[w][flag])>0 for w in dat1])
-    flag = 'cuspidal_dim' if level_flag=='cusp' else 'new_dim'
-    data = [dat for dat in data if level_flag == 'all' or filter(dat, flag)]
-
     info['field'] = field_label
     info['field_pretty'] = pretty_field_label
     nf = WebNumberField(field_label)
diff --git a/scripts/bianchi_modular_forms/import_bianchi_dimensions.py b/scripts/bianchi_modular_forms/import_bianchi_dimensions.py
--- a/scripts/bianchi_modular_forms/import_bianchi_dimensions.py
+++ b/scripts/bianchi_modular_forms/import_bianchi_dimensions.py
@@ -19,6 +19,9 @@
    - 'sl2_dims':       (dict) each key is a weight (int), with value a
                          dict with keys 'cuspidal_dim', 'new_dim' (and possibly more)
 
+Note (April 2019): when this script is updated to Postgres, make sure to add the columns
+sl2_new_totaldim, sl2_cusp_totaldim, gl2_new_totaldim, and gl2_cusp_totaldim.  See
+PR #2926 for details.
 """
 from sage.all import polygen, QQ, ZZ, NumberField
 


Test patch: