Skip to content

Commit

Permalink
client: get table by tid or md5
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jan 23, 2021
1 parent 57c0c4e commit 9280311
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions mpcontribs-client/mpcontribs/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,27 @@ def get_contribution(self, cid):
fields.remove("notebook")
return Dict(self.contributions.get_entry(pk=cid, _fields=fields).result())

def get_table(self, tid):
"""Convenience function to get full Pandas DataFrame for a table."""
def get_table(self, tid_or_md5):
"""Convenience function to get full Pandas DataFrame for a table.
Args:
tid_or_md5 (str): ObjectId or MD5 hash digest for table
Returns:
pd.DataFrame: pandas DataFrame containing table data
"""
str_len = len(tid_or_md5)
if str_len not in {24, 32}:
raise ValueError(f"'{tid_or_md5}' is not a valid table id or md5 hash digest!")

if str_len == 32:
tables = self.tables.get_entries(md5=tid_or_md5, _fields=["id"]).result()
if not tables:
raise ValueError(f"table for md5 '{tid_or_md5}' not found!")
tid = tables["data"][0]["id"]
else:
tid = tid_or_md5

table = {"data": []}
page, pages = 1, None

Expand Down

0 comments on commit 9280311

Please sign in to comment.