bluer-objects 6.317.1__py3-none-any.whl → 6.325.1__py3-none-any.whl

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.

Potentially problematic release.


This version of bluer-objects might be problematic. Click here for more details.

bluer_objects/__init__.py CHANGED
@@ -4,7 +4,7 @@ ICON = "🌀"
4
4
 
5
5
  DESCRIPTION = f"{ICON} Object management in Bash."
6
6
 
7
- VERSION = "6.317.1"
7
+ VERSION = "6.325.1"
8
8
 
9
9
  REPO_NAME = "bluer-objects"
10
10
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Dict, List
1
+ from typing import Any, Dict, List, Union
2
2
  import yaml
3
3
  import numpy as np
4
4
  import json
@@ -30,9 +30,15 @@ def finish_saving(
30
30
  success: bool,
31
31
  message: str,
32
32
  log: bool = True,
33
+ exception: Union[Exception, None] = None,
33
34
  ) -> bool:
34
35
  if not success:
35
- crash_report(f"{message}: failed.")
36
+ crash_report(
37
+ "{}: failed: {}".format(
38
+ message,
39
+ exception,
40
+ )
41
+ )
36
42
  elif log:
37
43
  logger.info(message)
38
44
 
@@ -246,12 +252,14 @@ def save_yaml(
246
252
  if not prepare_for_saving(filename):
247
253
  return False
248
254
 
255
+ exception = None
249
256
  success = True
250
257
  try:
251
258
  with open(filename, "w") as f:
252
259
  yaml.dump(data, f)
253
- except:
260
+ except Exception as e:
254
261
  success = False
262
+ exception = e
255
263
 
256
264
  return finish_saving(
257
265
  success,
@@ -261,4 +269,5 @@ def save_yaml(
261
269
  filename,
262
270
  ),
263
271
  log,
272
+ exception,
264
273
  )
@@ -0,0 +1,76 @@
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+ from typing import List
4
+
5
+ from bluer_objects.graphics.signature import justify_text
6
+ from bluer_objects import file
7
+
8
+
9
+ def log_confusion_matrix(
10
+ confusion_matrix: np.ndarray,
11
+ filename: str,
12
+ header: List[str] = [],
13
+ footer: List[str] = [],
14
+ x_classes: List[str] = [],
15
+ y_classes: List[str] = [],
16
+ x_name: str = "prediction",
17
+ y_name: str = "label",
18
+ line_width: int = 80,
19
+ log: bool = True,
20
+ figsize: tuple = (10, 10),
21
+ ) -> bool:
22
+ fig, ax = plt.subplots(figsize=figsize)
23
+ cax = ax.imshow(
24
+ confusion_matrix,
25
+ interpolation="nearest",
26
+ cmap=plt.cm.Blues,
27
+ )
28
+ fig.colorbar(cax)
29
+ ax.set_title(
30
+ justify_text(
31
+ " | ".join(header),
32
+ line_width=line_width,
33
+ return_str=True,
34
+ )
35
+ )
36
+ ax.set_xlabel(
37
+ justify_text(
38
+ " | ".join([x_name] + footer),
39
+ line_width=line_width,
40
+ return_str=True,
41
+ )
42
+ )
43
+ ax.set_ylabel(y_name)
44
+
45
+ if not x_classes:
46
+ x_classes = [f"class #{index}" for index in range(confusion_matrix.shape[1])]
47
+ if not y_classes:
48
+ y_classes = [f"class #{index}" for index in range(confusion_matrix.shape[0])]
49
+
50
+ ax.set_xticks(np.arange(confusion_matrix.shape[1]))
51
+ ax.set_yticks(np.arange(confusion_matrix.shape[0]))
52
+ ax.set_xticklabels(
53
+ x_classes,
54
+ rotation=45,
55
+ ha="right",
56
+ )
57
+ ax.set_yticklabels(y_classes)
58
+
59
+ threshold = confusion_matrix.max() / 2.0
60
+ for i in range(confusion_matrix.shape[0]):
61
+ for j in range(confusion_matrix.shape[1]):
62
+ ax.text(
63
+ j,
64
+ i,
65
+ f"{100*confusion_matrix[i, j]:.1f}%",
66
+ ha="center",
67
+ va="center",
68
+ color="white" if confusion_matrix[i, j] > threshold else "black",
69
+ )
70
+
71
+ plt.tight_layout()
72
+
73
+ return file.save_fig(
74
+ filename,
75
+ log=log,
76
+ )
@@ -0,0 +1,18 @@
1
+ import numpy as np
2
+
3
+ from bluer_objects import objects
4
+ from bluer_objects.logger.confusion_matrix import log_confusion_matrix
5
+
6
+
7
+ def test_logger_confusion_matrix():
8
+ object_name = objects.unique_object("test_logger_confusion_matrix")
9
+
10
+ confusion_matrix = np.random.random((10, 8))
11
+
12
+ assert log_confusion_matrix(
13
+ confusion_matrix,
14
+ objects.path_of(
15
+ object_name=object_name,
16
+ filename="confusion_matrix.png",
17
+ ),
18
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bluer_objects
3
- Version: 6.317.1
3
+ Version: 6.325.1
4
4
  Summary: 🌀 Object management in Bash.
5
5
  Home-page: https://github.com/kamangir/bluer-objects
6
6
  Author: Arash Abadpour (Kamangir)
@@ -65,6 +65,6 @@ pip install bluer-objects
65
65
 
66
66
  [![pylint](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/bluer-objects/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/bluer-objects.svg)](https://pypi.org/project/bluer-objects/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/bluer-objects)](https://pypistats.org/packages/bluer-objects)
67
67
 
68
- built by 🌀 [`bluer README`](https://github.com/kamangir/bluer-objects/tree/main/bluer_objects/README), based on 🌀 [`bluer_objects-6.317.1`](https://github.com/kamangir/bluer-objects).
68
+ built by 🌀 [`bluer README`](https://github.com/kamangir/bluer-objects/tree/main/bluer_objects/README), based on 🌀 [`bluer_objects-6.325.1`](https://github.com/kamangir/bluer-objects).
69
69
 
70
70
  built by 🌀 [`blueness-3.118.1`](https://github.com/kamangir/blueness).
@@ -1,4 +1,4 @@
1
- bluer_objects/__init__.py,sha256=JkRIAGUXIONHpmIWt1EkQaI7NAmrG2fKp6UdYkev2oY,315
1
+ bluer_objects/__init__.py,sha256=Pi2iOBzjpZk_r580bAmAfa7JmsPQhMi-wqb2eJLn4AI,315
2
2
  bluer_objects/__main__.py,sha256=Yqfov833_hJuRne19WrGhT5DWAPtdffpoMxeSXS7EGw,359
3
3
  bluer_objects/config.env,sha256=ReX0OSH_dK2tdD4-zAlp-427BB57yw8uDTS6tLYN4K0,270
4
4
  bluer_objects/env.py,sha256=ecwldUVsamxAjOI0a6PmbZPcyhdUZgzJ-nhAPh0CJRo,2085
@@ -87,7 +87,7 @@ bluer_objects/file/__main__.py,sha256=katbvYg2ykEcs14ZY1kvCKaA6KB_vhlPCLPuJlMX_k
87
87
  bluer_objects/file/classes.py,sha256=TRgeRP2yxInPkBnywhuB4BsoBcBRA3UmQzX1dI43UxU,872
88
88
  bluer_objects/file/functions.py,sha256=YBJFaI5l-bY1LSz8S_hMhbCmym6cULZTF5fzP2W4Osk,6604
89
89
  bluer_objects/file/load.py,sha256=1zt5xC95HFr89G9lsi3gCJMSvC4Bt0vVeeUEf3NjpOQ,4281
90
- bluer_objects/file/save.py,sha256=eXl5pM8Q29Jq8skVkZkU6THoqyMd2FkfFIPgO0-NarM,5056
90
+ bluer_objects/file/save.py,sha256=IuSbK6GExzOhHqaVfAhoGRqtgCTaon3Fr1T7rSzyV3w,5277
91
91
  bluer_objects/graphics/__init__.py,sha256=Dd0kQqN7Ldvp1N9oyIirPZ6W3IdUtfPj2u21Bf4W_MI,213
92
92
  bluer_objects/graphics/__main__.py,sha256=5_acfal1MnfzhDrp_pfDbC7oy5uzf6vDiiG3lvgx4VU,2041
93
93
  bluer_objects/graphics/frame.py,sha256=WcSn-0oqDw48Akmn_bwcjDC9U_kKqRYRoGWYPoKyFvY,321
@@ -117,6 +117,7 @@ bluer_objects/host/__init__.py,sha256=Ko43SWnZNsGKuIPU_l0w17pYrxCgVHQx3_zEoUNaHZ
117
117
  bluer_objects/host/__main__.py,sha256=J0MO2sUzrI_t_X4VVYyM6n41ND0yhhSXOmZSkDAC4rg,1751
118
118
  bluer_objects/host/functions.py,sha256=ADups78hYZDAnC6FlIICQ48WkFd4sPnRMWA0D6X-FV4,1663
119
119
  bluer_objects/logger/__init__.py,sha256=2aGNbx-qBXU3IlX9BDqtrFfN25lO_uarEg22cE3-3dU,102
120
+ bluer_objects/logger/confusion_matrix.py,sha256=CCcuogDm7_w-0f87-AeK7ue2CMBRJHmoaO_Vqy-C_Ds,1991
120
121
  bluer_objects/logger/image.py,sha256=wHpE6jCqKGmcjXU61vCMKbBeir7DAxH6nKx5kb_1Vv0,2617
121
122
  bluer_objects/logger/matrix.py,sha256=cPKQIhd347MH_9LaB-Ym7Mix1pqampG9MIgkeh08KA4,5757
122
123
  bluer_objects/logger/stitch.py,sha256=qFWQAxNyfOn7k5celRYIUPqaI-ZqDWKQ5ud1VyaIwM4,2515
@@ -166,6 +167,7 @@ bluer_objects/tests/test_graphics_signature.py,sha256=CVV257E3A5KBwqEDpRXShN-ful
166
167
  bluer_objects/tests/test_graphics_text.py,sha256=_jLZVuAcQQYlKpATeQCBpPMa8UhKQ__bFYR1bedO5EE,314
167
168
  bluer_objects/tests/test_log_image_grid.py,sha256=qjSRMwY5jnJd9S3XZ3FDeoIsSJ9aFJ3yDhth1sV0A5g,737
168
169
  bluer_objects/tests/test_logger.py,sha256=DdkZqj8YOErKf6T-SWEPtU21LGfQf_O3GKrCn3H0Ujs,88
170
+ bluer_objects/tests/test_logger_confusion_matrix.py,sha256=KbkUg153n6xt3558LXE50URGXrhoRsSorF2lJcqMmaE,469
169
171
  bluer_objects/tests/test_logger_matrix.py,sha256=qedidEDGusMWQM04kgk3mt74yFm4iU3jIyjE4gRi_FQ,1703
170
172
  bluer_objects/tests/test_logger_stitch_images.py,sha256=GW_EPbByNbAhwCJ3LwVXjwe4sTx6jcE0SXVvM8kL_LY,929
171
173
  bluer_objects/tests/test_markdown.py,sha256=KtCWKIDs4U1M3qAGFMYhzVpdGiDV2VU8z7dCaU3s3Ec,217
@@ -186,8 +188,8 @@ bluer_objects/tests/test_web_is_accessible.py,sha256=2Y20NAEDMblg0MKnhnqcfw3XVKE
186
188
  bluer_objects/web/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
187
189
  bluer_objects/web/__main__.py,sha256=xf2Ob54FI8JEokfGhFmiyOBdD9nBactwqmZvsKsdioU,624
188
190
  bluer_objects/web/functions.py,sha256=KNufAFOc6N3BYf83lN2rUpKUdsnzb2anWyp9koFRVUo,172
189
- bluer_objects-6.317.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
190
- bluer_objects-6.317.1.dist-info/METADATA,sha256=pKpKV9JJSzH37QSct--MYf0XDUMQ4Ltq1RS4mfdW-Lk,3780
191
- bluer_objects-6.317.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
192
- bluer_objects-6.317.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
193
- bluer_objects-6.317.1.dist-info/RECORD,,
191
+ bluer_objects-6.325.1.dist-info/licenses/LICENSE,sha256=ogEPNDSH0_dhiv_lT3ifVIdgIzHAqNA_SemnxUfPBJk,7048
192
+ bluer_objects-6.325.1.dist-info/METADATA,sha256=satmgSwT0AVO9rSYBViAgJbo7RfFTSOCDlJZrK0bX4s,3780
193
+ bluer_objects-6.325.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
194
+ bluer_objects-6.325.1.dist-info/top_level.txt,sha256=RX2TpddbnRkurda3G_pAdyeTztP2IhhRPx949GlEvQo,14
195
+ bluer_objects-6.325.1.dist-info/RECORD,,