Skip to content

Commit

Permalink
0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Jan 3, 2024
1 parent b0f38bd commit 9060533
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

.. .. image:: https://readthedocs.org/projects/tt4human/badge/?version=latest
.. image:: https://readthedocs.org/projects/tt4human/badge/?version=latest
:target: https://tt4human.readthedocs.io/en/latest/
:alt: Documentation Status

.. image:: https://github.com/MacHu-GWU/tt4human-project/workflows/CI/badge.svg
:target: https://github.com/MacHu-GWU/tt4human-project/actions?query=workflow:CI

.. .. image:: https://codecov.io/gh/MacHu-GWU/tt4human-project/branch/main/graph/badge.svg
.. image:: https://codecov.io/gh/MacHu-GWU/tt4human-project/branch/main/graph/badge.svg
:target: https://codecov.io/gh/MacHu-GWU/tt4human-project

.. image:: https://img.shields.io/pypi/v/tt4human.svg
Expand All @@ -26,10 +26,10 @@

------

.. .. image:: https://img.shields.io/badge/Link-Document-blue.svg
.. image:: https://img.shields.io/badge/Link-Document-blue.svg
:target: https://tt4human.readthedocs.io/en/latest/

.. .. image:: https://img.shields.io/badge/Link-API-blue.svg
.. image:: https://img.shields.io/badge/Link-API-blue.svg
:target: https://tt4human.readthedocs.io/en/latest/py-modindex.html

.. image:: https://img.shields.io/badge/Link-Install-blue.svg
Expand Down
2 changes: 1 addition & 1 deletion docs/source/01-Quick-Start/do_you_go_out.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

"""
this module is generated by https://pypi.org/project/tt4human = 0.2.2
this module is generated by https://pypi.org/project/tt4human = 0.3.1
"""

from pathlib import Path
Expand Down
4 changes: 2 additions & 2 deletions docs/source/01-Quick-Start/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"from tt4human.api import TruthTable\n",
"\n",
"# create Truth Table\n",
"tt = TruthTable(\n",
"tt = TruthTable.new(\n",
" headers=[\"weather\", \"get_up\", \"go_out\"],\n",
" rows=[\n",
" (\"is_sunny\", \"before_10\", True),\n",
Expand Down Expand Up @@ -292,7 +292,7 @@
"# -*- coding: utf-8 -*-\n",
"\n",
"\"\"\"\n",
"this module is generated by https://pypi.org/project/tt4human = 0.2.2\n",
"this module is generated by https://pypi.org/project/tt4human = 0.3.1\n",
"\"\"\"\n",
"\n",
"from pathlib import Path\n",
Expand Down
13 changes: 13 additions & 0 deletions release-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ x.y.z (Backlog)
**Miscellaneous**


0.3.1 (2024-01-02)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Features and Improvements**

- Add the following api:
- ``tt4human.api.TruthTable.new(...)``
- ``tt4human.api.TruthTable.from_pandas_df(...)``

**Minor Improvements**

- Add document website.


0.2.2 (2023-12-17)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**Minor Improvements**
Expand Down
2 changes: 1 addition & 1 deletion tt4human/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.2"
__version__ = "0.3.1"

if __name__ == "__main__": # pragma: no cover
print(__version__)
32 changes: 25 additions & 7 deletions tt4human/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ def lookup(self) -> T.Dict[str, bool]:

return lookup

@classmethod
def new(
cls,
headers: T.List[str],
rows: T.List[list],
):
"""
Create a new truth table.
:param headers: the last column is the "target", others are "conditions".
:param rows: list of "cases", for each row, the last item is the "target",
others are "conditions".
"""
new_rows = list()
for row in rows:
new_row = list(row[:-1])
new_row.append(to_bool(str(row[-1])))
new_rows.append(new_row)
return cls(headers, new_rows)

@classmethod
def from_csv(
cls,
Expand All @@ -166,19 +186,17 @@ def from_csv(
reader = csv.reader(f, delimiter=sep)
headers = next(reader)
for row in reader:
row[-1] = to_bool(row[-1])
rows.append(row)

return cls(headers=headers, rows=rows)
return cls.new(headers=headers, rows=rows)

@classmethod
def from_pandas_df(cls, df: "pd.DataFrame"): # pragma: no cover
"""
Create a truth table from a pandas DataFrame.
"""
headers = list(df.columns)
rows = df.values.tolist()
for row in rows:
row[-1] = to_bool(str(row[-1]))

return cls(headers=headers, rows=rows)
return cls.new(headers=headers, rows=rows)

def evaluate(self, case: T.Dict[str, str]) -> bool:
"""
Expand Down

0 comments on commit 9060533

Please sign in to comment.