cbrkit 0.18.0__tar.gz → 0.18.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {cbrkit-0.18.0 → cbrkit-0.18.2}/PKG-INFO +4 -3
  2. {cbrkit-0.18.0 → cbrkit-0.18.2}/README.md +2 -2
  3. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/loaders.py +21 -14
  4. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/retrieval.py +1 -1
  5. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/graphs/_model.py +46 -0
  6. {cbrkit-0.18.0 → cbrkit-0.18.2}/pyproject.toml +2 -2
  7. {cbrkit-0.18.0 → cbrkit-0.18.2}/LICENSE +0 -0
  8. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/__init__.py +0 -0
  9. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/__main__.py +0 -0
  10. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/adaptation.py +0 -0
  11. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/api.py +0 -0
  12. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/cli.py +0 -0
  13. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/eval/__init__.py +0 -0
  14. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/eval/_common.py +0 -0
  15. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/eval/_retrieval.py +0 -0
  16. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/helpers.py +0 -0
  17. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/py.typed +0 -0
  18. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/__init__.py +0 -0
  19. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/_aggregator.py +0 -0
  20. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/_attribute_value.py +0 -0
  21. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/collections.py +0 -0
  22. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/generic.py +0 -0
  23. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/graphs/__init__.py +0 -0
  24. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/graphs/_astar.py +0 -0
  25. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/numbers.py +0 -0
  26. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/strings/__init__.py +0 -0
  27. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/sim/strings/taxonomy.py +0 -0
  28. {cbrkit-0.18.0 → cbrkit-0.18.2}/cbrkit/typing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cbrkit
3
- Version: 0.18.0
3
+ Version: 0.18.2
4
4
  Summary: Customizable Case-Based Reasoning (CBR) toolkit for Python with a built-in API and CLI.
5
5
  Home-page: https://wi2trier.github.io/cbrkit/
6
6
  License: MIT
@@ -18,6 +18,7 @@ Classifier: Natural Language :: English
18
18
  Classifier: Operating System :: OS Independent
19
19
  Classifier: Programming Language :: Python :: 3
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
23
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
23
24
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
@@ -144,7 +145,7 @@ import pandas as pd
144
145
  import cbrkit
145
146
 
146
147
  df = pd.read_csv("path/to/cases.csv")
147
- casebase = cbrkit.loaders.dataframe(df)
148
+ casebase = cbrkit.loaders.pandas(df)
148
149
  ```
149
150
 
150
151
  When dealing with formats like JSON, the files can be loaded directly:
@@ -169,7 +170,7 @@ If you have a collection of queries, you can load them using the same loader fun
169
170
 
170
171
  ```python
171
172
  # for pandas
172
- queries = cbrkit.loaders.dataframe(pd.read_csv("path/to/queries.csv"))
173
+ queries = cbrkit.loaders.pandas(pd.read_csv("path/to/queries.csv"))
173
174
  # for json
174
175
  queries = cbrkit.loaders.json("path/to/queries.json")
175
176
  ```
@@ -76,7 +76,7 @@ import pandas as pd
76
76
  import cbrkit
77
77
 
78
78
  df = pd.read_csv("path/to/cases.csv")
79
- casebase = cbrkit.loaders.dataframe(df)
79
+ casebase = cbrkit.loaders.pandas(df)
80
80
  ```
81
81
 
82
82
  When dealing with formats like JSON, the files can be loaded directly:
@@ -101,7 +101,7 @@ If you have a collection of queries, you can load them using the same loader fun
101
101
 
102
102
  ```python
103
103
  # for pandas
104
- queries = cbrkit.loaders.dataframe(pd.read_csv("path/to/queries.csv"))
104
+ queries = cbrkit.loaders.pandas(pd.read_csv("path/to/queries.csv"))
105
105
  # for json
106
106
  queries = cbrkit.loaders.json("path/to/queries.json")
107
107
  ```
@@ -20,7 +20,6 @@ from cbrkit.typing import Casebase, FilePath
20
20
 
21
21
  __all__ = [
22
22
  "csv",
23
- "dataframe",
24
23
  "pandas",
25
24
  "file",
26
25
  "folder",
@@ -62,17 +61,20 @@ def python(import_name: str) -> Any:
62
61
  class pandas(Mapping[int, pd.Series]):
63
62
  df: pd.DataFrame
64
63
 
65
- def __getitem__(self, key: int) -> pd.Series:
66
- return self.df.iloc[key]
64
+ def __getitem__(self, key: int | str) -> pd.Series:
65
+ if isinstance(key, str):
66
+ return cast(pd.Series, self.df.loc[key])
67
+ elif isinstance(key, int):
68
+ return self.df.iloc[key]
69
+
70
+ raise TypeError(f"Invalid key type: {type(key)}")
67
71
 
68
72
  def __iter__(self) -> Iterator[int]:
69
- return iter(range(len(self.df)))
73
+ return iter(range(self.df.shape[0]))
70
74
 
71
75
  def __len__(self) -> int:
72
- return len(self.df)
73
-
76
+ return self.df.shape[0]
74
77
 
75
- dataframe = pandas
76
78
 
77
79
  # @dataclass(slots=True)
78
80
  # class dataframe(Mapping[int, tuple[Any, ...]]):
@@ -95,17 +97,22 @@ try:
95
97
  import polars as pl
96
98
 
97
99
  @dataclass(slots=True, frozen=True)
98
- class polars(Mapping[int, pl.DataFrame]):
100
+ class polars(Mapping[int, pl.Series]):
99
101
  df: pl.DataFrame
100
102
 
101
- def __getitem__(self, key: int) -> pl.DataFrame:
102
- return self.df.slice(key, 1)
103
+ def __getitem__(self, key: int | str) -> pl.Series:
104
+ if isinstance(key, str):
105
+ return self.df[key]
106
+ elif isinstance(key, int):
107
+ return pl.Series(self.df.row(key))
108
+
109
+ raise TypeError(f"Invalid key type: {type(key)}")
103
110
 
104
111
  def __iter__(self) -> Iterator[int]:
105
- return iter(range(len(self.df)))
112
+ return iter(range(self.df.shape[0]))
106
113
 
107
114
  def __len__(self) -> int:
108
- return len(self.df)
115
+ return self.df.shape[0]
109
116
 
110
117
  __all__ += ["polars"]
111
118
 
@@ -141,7 +148,7 @@ def csv(path: FilePath) -> dict[int, dict[str, str]]:
141
148
  def _csv_pandas(path: FilePath) -> dict[int, pd.Series]:
142
149
  df = pd.read_csv(path)
143
150
 
144
- return cast(dict[int, pd.Series], dataframe(df))
151
+ return cast(dict[int, pd.Series], pandas(df))
145
152
 
146
153
 
147
154
  def json(path: FilePath) -> dict[Any, Any]:
@@ -401,7 +408,7 @@ def validate(data: Casebase[Any, Any] | Any, validation_model: BaseModel):
401
408
  >>> validate(data, Car)
402
409
  >>> import pandas as pd
403
410
  >>> df = pd.read_csv("data/cars-1k.csv")
404
- >>> data = dataframe(df)
411
+ >>> data = pandas(df)
405
412
  >>> validate(data, Car)
406
413
  """
407
414
  assert data is not None
@@ -160,7 +160,7 @@ def apply[K, V, S: Float](
160
160
  >>> import cbrkit
161
161
  >>> import pandas as pd
162
162
  >>> df = pd.read_csv("./data/cars-1k.csv")
163
- >>> casebase = cbrkit.loaders.dataframe(df)
163
+ >>> casebase = cbrkit.loaders.pandas(df)
164
164
  >>> query = casebase[42]
165
165
  >>> retriever = cbrkit.retrieval.build(
166
166
  ... cbrkit.sim.attribute_value(
@@ -160,3 +160,49 @@ try:
160
160
 
161
161
  except ImportError:
162
162
  pass
163
+
164
+ try:
165
+ import networkx as nx
166
+
167
+ def to_networkx[N, E](g: Graph[Any, N, E, Any]) -> "nx.DiGraph":
168
+ ng = nx.DiGraph()
169
+ # Set graph attributes
170
+ ng.graph.update(g.data)
171
+
172
+ # Add nodes with their data
173
+ for node in g.nodes.values():
174
+ ng.add_node(node.key, data=node.data)
175
+
176
+ # Add edges with their data
177
+ for edge in g.edges.values():
178
+ ng.add_edge(edge.source.key, edge.target.key, key=edge.key, data=edge.data)
179
+
180
+ return ng
181
+
182
+ def from_networkx[N, E](g: "nx.DiGraph") -> Graph[Any, N, E, Any]:
183
+ # Create nodes
184
+ nodes = immutables.Map(
185
+ (node_id, Node(node_id, g.nodes[node_id].get("data")))
186
+ for node_id in g.nodes
187
+ )
188
+
189
+ # Create edges
190
+ edges = immutables.Map(
191
+ (
192
+ edge_data.get("key", idx),
193
+ Edge(
194
+ edge_data.get("key", idx),
195
+ nodes[source],
196
+ nodes[target],
197
+ edge_data.get("data"),
198
+ ),
199
+ )
200
+ for idx, (source, target, edge_data) in enumerate(g.edges(data=True))
201
+ )
202
+
203
+ return Graph(nodes, edges, dict(g.graph))
204
+
205
+ __all__ += ["to_networkx", "from_networkx"]
206
+
207
+ except ImportError:
208
+ pass
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cbrkit"
3
- version = "0.18.0"
3
+ version = "0.18.2"
4
4
  description = "Customizable Case-Based Reasoning (CBR) toolkit for Python with a built-in API and CLI."
5
5
  authors = ["Mirko Lenz <mirko@mirkolenz.com>"]
6
6
  license = "MIT"
@@ -79,7 +79,7 @@ xmltodict = ">=0.13, <1.0"
79
79
 
80
80
  [tool.poetry.group.dev.dependencies]
81
81
  pytest = "^8.0"
82
- pytest-cov = "^5.0"
82
+ pytest-cov = "^6.0"
83
83
 
84
84
  [tool.poetry.group.docs.dependencies]
85
85
  pdoc = "^15"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes