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/
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.dfdict module
- class banana.data.dfdict.DFdict(*args, **kwargs)[source]
Bases:
dictCollects 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)
- property q2s
banana.data.sql module
- exception banana.data.sql.HashError(descr, objs=None)[source]
Bases:
RetrieveError- objects = 'hashes'
- exception banana.data.sql.UIDError(descr, objs=None)[source]
Bases:
RetrieveError- objects = 'pids'
- banana.data.sql.insertmany(session, table, df)[source]
Insert all records into the DB.
- Parameters:
session (sqlalchemy.orm.session.Session) – database
table (sqlalchemy.schema.Table) – target table
df (pandas.DataFrame) – dataframe all records
- banana.data.sql.insertnew(session, table, df)[source]
Insert all records that do not exist yet (determined by hash).
- Parameters:
session (sqlalchemy.orm.session.Session) – database
table (sqlalchemy.schema.Table) – target table
df (pandas.DataFrame) – dataframe all records
- banana.data.sql.remove(session, table_object, uids)[source]
Remove given rows from chosen table.
- Parameters:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object
- banana.data.sql.select_all(session, table_object)[source]
Collect all records.
- Parameters:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object
- Returns:
list of records
- Return type:
- 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:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object
hash_partial (str) – hash identifier
- Returns:
record
- Return type:
- 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:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object
hash_partial (str) – hash identifier
- Returns:
record
- Return type:
- banana.data.sql.select_by_uid(session, table_object, uid)[source]
Find a record by its uid (unique identifier).
- Parameters:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object
hash_partial (str) – hash identifier
- Returns:
record
- Return type:
- banana.data.sql.serialize(data)[source]
Eventually turn some elements into their binary representation.
- banana.data.sql.truncate(session, table_object)[source]
Empty table.
- Parameters:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object
- banana.data.sql.update_atime(session, table_object, uids)[source]
Update rows access time to now.
- Parameters:
session (sqlalchemy.orm.session.Session) – DB ORM session
table_object (sqlalchemy.schema.Table) – table object