logic_utils
logic_utils
used to store multiple functions that are used in many different files.
ticks_to_datetime(ticks)
pandas_datatype_to_tabular_datatype(df)
Takes dataframe columns and gets respective tabular column datatype.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas DataFrame |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
Dict
|
dictionary with results. |
Example
Source code in pytabular/logic_utils.py
pd_dataframe_to_m_expression(df)
This will take a pandas dataframe and convert to an m expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas DataFrame |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Currently only returning string values in your tabular model. |
Example
converts toSource code in pytabular/logic_utils.py
remove_folder_and_contents(folder_location)
Internal used in tabular_editor.py and best_practice_analyzer.py.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_location |
str
|
Folder path to remove directory and contents. |
required |
Source code in pytabular/logic_utils.py
remove_file(file_path)
remove_suffix(input_string, suffix)
Adding for <3.9 compatiblity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_string |
str
|
input string to remove suffix from. |
required |
suffix |
str
|
suffix to be removed. |
required |
Source code in pytabular/logic_utils.py
get_sub_list(lst, n)
get_value_to_df(query, index)
Gets the values from the AdomdDataReader to convert to python df.
Lots of room for improvement on this one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
AdomdDataReader
|
The AdomdDataReader .Net object. |
required |
index |
int
|
Index of the value to perform the logic on. |
required |
Source code in pytabular/logic_utils.py
dataframe_to_dict(df)
Convert to Dataframe to dictionary and alter columns names with it.
Will convert the underscores (_) to spaces, and all strings are converted to Title Case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Original table that needs to be converted to a list with dicts. |
required |
Returns:
Type | Description |
---|---|
List[dict]
|
list of dictionaries. |
Source code in pytabular/logic_utils.py
dict_to_markdown_table(list_of_dicts, columns_to_include=None)
Generate a Markdown table based on a list of dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_of_dicts |
list
|
List of Dictionaries that need to be converted to a markdown table. |
required |
columns_to_include |
list
|
Default = None, and all colums are included. If a list is supplied, those columns will be included. |
None
|
Returns:
Type | Description |
---|---|
str
|
String that will represent a table in Markdown. |