banana.data package

Module to collect utilites to help with the data generation:

banana.data.cartesian_product(inp)[source]

Compute the cartesion product of a dictionary.

Thank you: https://stackoverflow.com/questions/5228158/

Parameters:

inp (dict) – dictionary listing all posibilities

Returns:

power set of all possibilities, preserving the keys

Return type:

list(dict)

Submodules

banana.data.db module

Actually using String it’s pointless, since SQLite has only one text type and it is TEXT, and the maximum length is coherently ignored by SQLite. Nevertheless the information is stored in the DB, even if the DBMS won’t use it, so we can keep declaring a size for fields where it matters.

Same considerations apply to datetime, with the further gain that SQLite it’s storing as he wish but able to use some dedicated functions.

class banana.data.db.Cache(**kwargs)[source]

Bases: CalcResult, Base

atime
ctime
external
hash
mtime
o_hash
pdf
result
t_hash
uid
class banana.data.db.CalcResult[source]

Bases: object

external = Column(None, Text(), table=None)
o_hash = Column(None, String(length=64), table=None)
pdf = Column(None, Text(), table=None)
t_hash = Column(None, String(length=64), table=None)
class banana.data.db.Log(**kwargs)[source]

Bases: CalcResult, Base

atime
ctime
external
hash
log
mtime
o_hash
pdf
t_hash
uid
class banana.data.db.MyBase[source]

Bases: object

atime = Column(None, DateTime(), table=None, onupdate=ColumnDefault(<function MyBase.<lambda>>))
ctime = Column(None, DateTime(), table=None, default=ColumnDefault(<function MyBase.<lambda>>))
hash = Column(None, String(length=64), table=None)
mtime = Column(None, DateTime(), table=None, onupdate=ColumnDefault(<function MyBase.<lambda>>))
uid = Column(None, Integer(), table=None, primary_key=True, nullable=False)
class banana.data.db.Theory(**kwargs)[source]

Bases: Base

CKM
Comments
DAMP
EScaleVar
FNS
GF
HQ
IB
IC
ID
MP
MW
MZ
MaxNfAs
MaxNfPdf
ModEv
NfFF
PTO
Q0
QED
Qedref
Qmb
Qmc
Qmt
Qref
SIN2TW
SxOrd
SxRes
TMC
XIF
XIR
alphaqed
alphas
atime
ctime
fact_to_ren_scale_ratio
global_nx
hash
kDISbThr
kDIScThr
kDIStThr
kbThr
kcThr
ktThr
mb
mc
mt
mtime
nfref
uid
banana.data.db.create_db(base_cls, engine)[source]
banana.data.db.engine(path='', dialect='sqlite', driver=None, username=None, password=None, host=None, port=None)[source]

banana.data.dfdict module

class banana.data.dfdict.DFdict(*args, **kwargs)[source]

Bases: dict

Collects dataframes in a dictionary printing them along side.

fancy(file=None)[source]

Print on stdout… with style!

Parameters:

file (IO[str]) – File to write to, None for stdout (passed down to rich)

classmethod from_document(d)[source]

Load dataframes from a previous dictionary dump

Parameters:

d (dict) – raw dictionary, containing a dump of a DFdict object

Returns:

the loaded DFdict

Return type:

DFdict

merge(other)[source]
print(*msgs, sep=' ', end='\n', position=None)[source]

Add new messages to the representation

Parameters:
  • msgs (str) – messages

  • sep (str) – separator

  • end (str) – end-of-line marker

q2_slice(q2)[source]
property q2s
to_document()[source]

Convert dataframes back to a true dictionary

Returns:

d – raw dictionary

Return type:

dict

banana.data.sql module

exception banana.data.sql.HashError(descr, objs=None)[source]

Bases: RetrieveError

objects = 'hashes'
exception banana.data.sql.RetrieveError(descr, objs=None)[source]

Bases: KeyError

objects = None
exception banana.data.sql.UIDError(descr, objs=None)[source]

Bases: RetrieveError

objects = 'pids'
banana.data.sql.add_hash(record)[source]

Add a hash value as last element to the record.

Parameters:

record (tuple) – data

Returns:

hashed_record – data + hash

Return type:

tuple

banana.data.sql.deserialize(data)[source]

Undo the binary representation.

Parameters:

data (list) – raw data

Returns:

obj – composed object

Return type:

dict

banana.data.sql.insertmany(session, table, df)[source]

Insert all records into the DB.

Parameters:
banana.data.sql.insertnew(session, table, df)[source]

Insert all records that do not exist yet (determined by hash).

Parameters:
banana.data.sql.prepare_records(base, updates)[source]

Generate all records from the base.

Parameters:
  • base (dict) – base record

  • updates (list(dict)) – update directives

Returns:

  • documents (list(dict)) – list of all dictionaries

  • df (pandas.DataFrame) – all records ready for insertion

banana.data.sql.remove(session, table_object, uids)[source]

Remove given rows from chosen table.

Parameters:
banana.data.sql.select_all(session, table_object)[source]

Collect all records.

Parameters:
Returns:

list of records

Return type:

list(dict)

banana.data.sql.select_by_hash(session, table_object, hash_partial)[source]

Find a record by its partial hash.

The hash provided is considered to be the first len(hash_partial) carachters of a full hash in the table.

Parameters:
Returns:

record

Return type:

dict

banana.data.sql.select_by_position(session, table_object, pos)[source]

Find a record by its position.

Negative values are supported, and used as positions from the end (exact same logic of python list).

Note

This is more expensive than using select_uid(), since the whole table is retrieved, and only after a single member is selected.

Parameters:
Returns:

record

Return type:

dict

banana.data.sql.select_by_uid(session, table_object, uid)[source]

Find a record by its uid (unique identifier).

Parameters:
Returns:

record

Return type:

dict

banana.data.sql.serialize(data)[source]

Eventually turn some elements into their binary representation.

Parameters:

data (dict) – raw data

Returns:

ndata – improved data

Return type:

list

banana.data.sql.truncate(session, table_object)[source]

Empty table.

Parameters:
banana.data.sql.update_atime(session, table_object, uids)[source]

Update rows access time to now.

Parameters:

banana.data.theories module

banana.data.theories.load(session, updates)[source]

Load theories.

Parameters:
Returns:

list of all dictionaries

Return type:

list(dict)