Skip to content

Commit

Permalink
Added optional indexes to tables
Browse files Browse the repository at this point in the history
  • Loading branch information
PointlessUser committed Aug 10, 2023
1 parent aad44e9 commit 1e022d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mecsimcalc v0.1.4 documentation
# Mecsimcalc v0.1.5 documentation

This library is designed to provide a set of functions for handling and converting various types of data, such as base64 encoded data, Pandas DataFrames, and Pillow images.

Expand Down Expand Up @@ -311,6 +311,7 @@ Create a DataFrame from given rows and column headers
| -------------------- | ------------------- | ------------------------------------------------------------------------------- |
| **`column_headers`** | **List[str]** | List of column headers |
| **`rows`** | **List[List[str]]** | List of rows to be converted into a DataFrame. Each column is a list of strings |
| **`index`** | **bool** (optional) | Whether to use the first column as the DataFrame's index. (Defaults to True) |

#### Returns:

Expand Down Expand Up @@ -346,10 +347,11 @@ Creates an HTML table from given rows and column headers

#### Arguments:

| Argument | Type | Description |
| -------------------- | ------------------- | --------------------------------------------------------------------------- |
| **`column_headers`** | **List[str]** | List of column headers |
| **`rows`** | **List[List[str]]** | List of rows to be converted into a table. Each column is a list of strings |
| Argument | Type | Description |
| -------------------- | ------------------- | ---------------------------------------------------------------------------- |
| **`column_headers`** | **List[str]** | List of column headers |
| **`rows`** | **List[List[str]]** | List of rows to be converted into a table. Each column is a list of strings |
| **`index`** | **bool** (optional) | Whether to use the first column as the DataFrame's index. (Defaults to True) |

#### Returns:

Expand Down
14 changes: 10 additions & 4 deletions mecsimcalc/table_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def table_to_dataframe(
column_headers: List[str], rows: List[List[str]]
column_headers: List[str], rows: List[List[str]], index: bool = True
) -> pd.DataFrame:
"""
>>> table_to_dataframe(column_headers: List[str], rows: List[List[str]]) -> pd.DataFrame
Expand All @@ -16,6 +16,8 @@ def table_to_dataframe(
List of column headers.
rows : List[List[str]]
List of rows to be converted into a DataFrame. Each row is a list of strings.
index : bool
Whether to use the first column as the DataFrame's index. (Defaults to True)
# Raises
Expand All @@ -41,10 +43,12 @@ def table_to_dataframe(
if len(row) != len(column_headers):
raise ValueError("Each row must have the same length as the column headers")

return pd.DataFrame(rows, columns=column_headers)
return pd.DataFrame(rows, columns=column_headers, index=index)


def print_table(column_headers: List[str], rows: List[List[str]]) -> str:
def print_table(
column_headers: List[str], rows: List[List[str]], index: bool = True
) -> str:
"""
>>> print_table(column_headers: List[str], rows: List[List[str]]) -> str
Expand All @@ -56,6 +60,8 @@ def print_table(column_headers: List[str], rows: List[List[str]]) -> str:
The header for each column.
rows : List[List[str]]
A list of rows (each row is a list of strings).
index : bool
Whether to use the first column as the DataFrame's index. (Defaults to True)
# Returns
Expand All @@ -72,4 +78,4 @@ def print_table(column_headers: List[str], rows: List[List[str]]) -> str:
"""

df = table_to_dataframe(column_headers, rows)
return df.to_html(index=True, border=1, escape=True)
return df.to_html(index=index, border=1, escape=True)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read()

VERSION = "0.1.4"
VERSION = "0.1.5"
DESCRIPTION = "Useful functions for MecSimCalc.com"

# Setting up
Expand Down

0 comments on commit 1e022d5

Please sign in to comment.