|
6 | 6 | from pathlib import Path, WindowsPath |
7 | 7 |
|
8 | 8 |
|
9 | | -class CustomJSONEncoder(json.JSONEncoder): |
| 9 | +class PyscanJSONEncoder(json.JSONEncoder): |
10 | 10 | """ |
11 | 11 | A custom JSON encoder subclass that extends json.JSONEncoder to handle additional Python data types |
12 | 12 | not supported by the default JSON encoder. This includes handling of custom objects, numpy data types, |
@@ -36,23 +36,22 @@ def default(self, obj, debug=False): |
36 | 36 | # keys_to_skip = {'logger', 'expt_thread', 'data_path', 'instrument', 'module_id_string', 'spec'} |
37 | 37 |
|
38 | 38 | if type(obj) is type: |
39 | | - return f"<class '{obj.__name__}'>" |
| 39 | + return obj.__name__ |
40 | 40 | elif isinstance(obj, (InstrumentDriver, ItemAttribute)): |
41 | 41 | if debug is True: |
42 | 42 | print(f"obj {obj} was instance of InstrumentDriver and or ItemAttribute.") |
43 | 43 | return obj.__dict__ |
44 | | - elif isinstance(obj, range): |
| 44 | + elif isinstance(obj, (range, tuple)): |
45 | 45 | if debug is True: |
46 | | - print(f"obj {obj} was instance of range.") |
| 46 | + print(f"obj {obj} was instance of {type(obj)}.") |
47 | 47 | return list(obj) |
48 | 48 | # Handle numpy integers |
49 | | - elif isinstance(obj, (np.integer, np.int_, np.intc, np.intp, np.int8, np.int16, np.int32, np.int64, |
50 | | - np.uint8, np.uint16, np.uint32, np.uint64)): |
| 49 | + elif isinstance(obj, np.integer): |
51 | 50 | if debug is True: |
52 | 51 | print(f"Object {obj} is a numpy integer, converting to int.") |
53 | 52 | return int(obj) |
54 | 53 | # Handle numpy floating values |
55 | | - elif isinstance(obj, (np.floating, np.float16, np.float32, np.float64)): |
| 54 | + elif isinstance(obj, np.floating): |
56 | 55 | if debug is True: |
57 | 56 | print(f"Object {obj} is a numpy floating value, converting to float.") |
58 | 57 | return float(obj) |
|
0 commit comments