Skip to content

Commit

Permalink
Adding final support for Parquet/Pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
lcsrodriguez committed Jul 16, 2022
1 parent dab3e2f commit d00e1af
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
6 changes: 3 additions & 3 deletions headat/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"method": "to_latex"
},
"parquet": {
"extension": "pqt",
"extension": "parquet",
"method": "to_parquet"
},
"pickle": {
"extension": "pkl",
"extension": "pickle",
"method": "to_pickle"
},
"sqlite": {
"sql": {
"extension": "db",
"method": "to_sql"
},
Expand Down
1 change: 1 addition & 0 deletions headat/lib/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .constants import *
import datetime
import os
import scipy.io
import warnings
# Export routine to LaTeX generate a FutureWarning which has to be silenced
warnings.simplefilter(action='ignore', category=FutureWarning)
Expand Down
40 changes: 40 additions & 0 deletions headat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,46 @@ def t_tex(self, **kwargs) -> bool:
except:
return False

def t_parquet(self, **kwargs) -> bool:
"""
Function converting the record to the Apache Parquet format
:rtype: bool
:return: Boolean set to True if conversion has been successfully performed
"""
# Gathering the details concerning the specified format
df, method, filename = self.get_conversion_details("parquet")
cl_m = eval(f"df.{method}")
try:
cl_m(filename, **kwargs)
return True
except:
return False

def t_pickle(self, **kwargs) -> bool:
"""
Function converting the record to the Pickle (standard serialization) format
:rtype: bool
:return: Boolean set to True if conversion has been successfully performed
"""
# Gathering the details concerning the specified format
df, method, filename = self.get_conversion_details("pickle")
cl_m = eval(f"df.{method}")
try:
cl_m(filename, **kwargs)
return True
except:
return False

def t_sql(self, **kwargs) -> bool:
"""
Function converting the record to a database format supported by SQLAlchemy
:rtype: bool
:return: Boolean set to True if conversion has been successfully performed
"""
# TODO
pass


# ----------------------------------------------------------------
# GENERIC METHODS

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
openpyxl
pyarrow
tabulate
fastparquet
fastparquet
SQLAlchemy
4 changes: 3 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
a.t_json()
a.t_xml()
a.t_md()
a.t_tex()
a.t_tex()
a.t_parquet()
a.t_pickle()

0 comments on commit d00e1af

Please sign in to comment.