Skip to content

Commit bf60907

Browse files
committed
should be compatible with py37 now
1 parent bef67c5 commit bf60907

File tree

4 files changed

+185
-103
lines changed

4 files changed

+185
-103
lines changed

docs/Showcase.ipynb

Lines changed: 170 additions & 93 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"description": "Fuzzy Logic for Python 3",
1313
"license": "MIT",
1414
"url": "https://github.com/amogorkon/fuzzylogic",
15-
"version": "1.1.0",
15+
"version": "1.2.0",
1616
"author": "Anselm Kiefner",
1717
"author_email": "fuzzylogic-pypi@anselm.kiefner.de",
1818
"python_requires": ">=3.8",

src/fuzzylogic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = (1,0,1)
1+
__version__ = (1, 2, 0)

src/fuzzylogic/classes.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def __getitem__(self, key):
422422

423423
def __call__(self, args: "dict[Domain, float]", method="cog"):
424424
"""Calculate the infered value based on different methods.
425-
Default is center of gravity.
425+
Default is center of gravity (cog).
426426
"""
427427
assert len(args) == max(
428428
len(c) for c in self.conditions.keys()
@@ -433,11 +433,13 @@ def __call__(self, args: "dict[Domain, float]", method="cog"):
433433
len({C.domain for C in self.conditions.values()}) == 1
434434
), "For CoG, all conditions must have the same target domain."
435435
actual_values = {f: f(args[f.domain]) for S in self.conditions.keys() for f in S}
436-
weights = [
437-
(v, x)
438-
for K, v in self.conditions.items()
439-
if (x := min(actual_values[k] for k in K if k in actual_values)) > 0
440-
]
436+
437+
weights = []
438+
for K, v in self.conditions.items():
439+
x = min(actual_values[k] for k in K if k in actual_values)
440+
if x > 0:
441+
weights.append((v, x))
442+
441443
if not weights:
442444
return None
443445
target_domain = list(self.conditions.values())[0].domain
@@ -447,7 +449,7 @@ def __call__(self, args: "dict[Domain, float]", method="cog"):
447449
) * index + target_domain._low
448450

449451

450-
def rule_from_table(table: str, references:dict):
452+
def rule_from_table(table: str, references: dict):
451453
"""Turn a (2D) string table into a Rule of fuzzy sets.
452454
453455
ATTENTION: This will eval() all strings in the table.
@@ -466,10 +468,13 @@ def rule_from_table(table: str, references:dict):
466468
df = pd.read_table(io.StringIO(table))
467469
D = {}
468470
for x, y in product(range(len(df.index)), range(len(df.columns))):
469-
D[(eval(df.index[x].strip(), references), eval(df.columns[y].strip(), references))] = eval(df.iloc[x, y], references)
471+
D[(eval(df.index[x].strip(), references), eval(df.columns[y].strip(), references))] = eval(
472+
df.iloc[x, y], references
473+
)
470474
return Rule(D)
471475

472476

473477
if __name__ == "__main__":
474478
import doctest
479+
475480
doctest.testmod()

0 commit comments

Comments
 (0)