Skip to content

Commit

Permalink
Adding .dta (STATA) file conversion support
Browse files Browse the repository at this point in the history
  • Loading branch information
lcsrodriguez committed Jul 16, 2022
1 parent 8ce9277 commit b441369
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 9 additions & 4 deletions headat/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,23 @@
"extension": "mat",
"method": "custom"
},
"wav":{
"wav": {
"extension": "wav",
"method": "custom"
},
"edf":{
"edf": {
"extension": "edf",
"method": "custom"
},
"feather":{
"feather": {
"extension": "fea",
"method": "to_feather"
"method": "to_feather",
},
"stata": {
"extension": "dta",
"method": "to_stata",
}
}

EXPORT_FOLDERS = "out"
EXCEL_ROW_LIMIT = 1048576 - 2
14 changes: 14 additions & 0 deletions headat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,20 @@ def t_feather(self, **kwargs) -> bool:
except:
return False

def t_stata(self, **kwargs) -> bool:
"""
Function converting the record to a .dta file (STATA)
: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("stata")
cl_m = eval(f"df.{method}")
try:
cl_m(filename, **kwargs)
return True
except:
return False
# ----------------------------------------------------------------
# GENERIC METHODS

Expand Down
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
#a.t_edf()
a.t_csv()
a.t_feather()
"""
pd.DataFrame().to_records()
"""

0 comments on commit b441369

Please sign in to comment.