77from pyhdx import TorchFitResult
88from pyhdx .fitting import RatesFitResult
99from pyhdx .models import HDXMeasurement , HDXMeasurementSet
10- from pyhdx .support import multiindex_astype , multiindex_set_categories
10+ from pyhdx .support import multiindex_astype , multiindex_set_categories , hash_dataframe
1111
1212
1313class Source (param .Parameterized ):
@@ -23,7 +23,13 @@ def get(self):
2323
2424class TableSource (Source ):
2525
26- tables = param .Dict ({})
26+ tables = param .Dict (
27+ default = {},
28+ doc = "Dictionary of tables (pd.DataFrames)" )
29+
30+ hashes = param .Dict (
31+ default = {},
32+ doc = "Dictionary of table hashes" )
2733
2834 _type = 'table'
2935
@@ -33,6 +39,13 @@ def get(self):
3339 else :
3440 raise ValueError ("TableSource has multiple tables, use `get_table`" )
3541
42+ def add_table (self , table : str , df : pd .DataFrame ):
43+ table_hash = hash_dataframe (df )
44+ self .hashes [table ] = table_hash
45+ self .tables [table ] = df
46+
47+ #todo self.updated = True?
48+
3649 def get_table (self , table ):
3750 df = self .tables .get (table , None )
3851
@@ -193,7 +206,8 @@ def _add_table(self, df, table, categorical=True):
193206 if categorical :
194207 new .columns = multiindex_astype (new .columns , 0 , 'category' )
195208 new .columns = multiindex_set_categories (new .columns , 0 , categories , ordered = True )
196- self .tables [table ] = new
209+
210+ self .add_table (table , new )
197211
198212
199213class PDBSource (Source ):
@@ -202,6 +216,8 @@ class PDBSource(Source):
202216
203217 pdb_files = param .Dict ({}, doc = 'Dictionary with id: pdb_string pdb file entries' )
204218
219+ hashes = param .Dict ({})
220+
205221 max_entries = param .Number (
206222 1 ,
207223 doc = 'set maximum size for pdb files. set to none for infinite size. set to one for single pdb mode' )
@@ -213,11 +229,13 @@ def add_from_pdb(self, pdb_id):
213229 pdb_string = response .read ().decode ()
214230
215231 self .pdb_files [pdb_id ] = pdb_string
232+ self .hashes [pdb_id ] = hash (pdb_string )
216233 self .updated = True
217234
218235 def add_from_string (self , pdb_string , pdb_id ):
219236 self ._make_room ()
220237 self .pdb_files [pdb_id ] = pdb_string
238+ self .hashes [pdb_id ] = hash (pdb_string )
221239 self .updated = True
222240
223241 def _make_room (self ):
@@ -227,9 +245,10 @@ def _make_room(self):
227245 elif len (self .pdb_files ) == self .max_entries :
228246 key = next (iter (self .pdb_files ))
229247 del self .pdb_files [key ]
248+ del self .hashes [key ]
230249
231250 def get (self ):
232- """returns the first entry in the """
251+ """returns the first entry in the pdb source """
233252 return next (iter (self .pdb_files .values ()))
234253
235254 def get_pdb (self , pdb_id ):
0 commit comments