zhmiscellany 6.3.3__py3-none-any.whl → 6.3.6__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.
zhmiscellany/fileio.py CHANGED
@@ -218,7 +218,7 @@ def chdir_to_script_dir():
218
218
  os.chdir(os.path.dirname(get_script_path()))
219
219
 
220
220
 
221
- def cache(function, *args, compressed=False, **kwargs):
221
+ def cache(function, *args, _cache_compressed=False, **kwargs):
222
222
  """
223
223
  Caches the result of a function call to disk.
224
224
  """
@@ -239,6 +239,16 @@ def cache(function, *args, compressed=False, **kwargs):
239
239
  except (OSError, TypeError):
240
240
  return str(obj) # Fallback for lambdas/partials
241
241
 
242
+ # DICT-LIKE OBJECTS WITH NON-STRING KEYS (e.g., bidict, defaultdict, etc.)
243
+ # Convert keys to strings to make them JSON-serializable
244
+ if isinstance(obj, dict):
245
+ try:
246
+ # Check if any key is not a string
247
+ if any(not isinstance(k, str) for k in obj.keys()):
248
+ return {str(k): v for k, v in obj.items()}
249
+ except (TypeError, AttributeError):
250
+ pass
251
+
242
252
  # PANDAS DATAFRAMES: Convert to stable dictionary format
243
253
  if hasattr(obj, '__class__') and obj.__class__.__name__ == 'DataFrame':
244
254
  try:
@@ -300,7 +310,7 @@ def cache(function, *args, compressed=False, **kwargs):
300
310
  'function': function,
301
311
  'args': args,
302
312
  'kwargs': kwargs,
303
- 'compressed': compressed
313
+ 'compressed': _cache_compressed
304
314
  }
305
315
 
306
316
  seed_hash = get_hash_orjson(seed)
@@ -308,11 +318,11 @@ def cache(function, *args, compressed=False, **kwargs):
308
318
  cache_file = f'{cache_folder}/cache_{function.__name__}_{seed_hash}.pkl'
309
319
 
310
320
  if os.path.exists(cache_file):
311
- return load_object_from_file(cache_file, compressed=compressed)
321
+ return load_object_from_file(cache_file, compressed=_cache_compressed)
312
322
  else:
313
323
  result = function(*args, **kwargs)
314
324
  zhmiscellany.fileio.create_folder(cache_folder)
315
- save_object_to_file(result, cache_file, compressed=compressed)
325
+ save_object_to_file(result, cache_file, compressed=_cache_compressed)
316
326
  return result
317
327
 
318
328
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zhmiscellany
3
- Version: 6.3.3
3
+ Version: 6.3.6
4
4
  Summary: A collection of useful/interesting python libraries made by zh.
5
5
  Home-page: https://discord.gg/ThBBAuueVJ
6
6
  Author: zh
@@ -8,7 +8,7 @@ zhmiscellany/_resource_files_lookup.py,sha256=hsgPW0dngokgqWrAVAv5rUo-eobzJPjvWH
8
8
  zhmiscellany/cpp.py,sha256=XEUEoIKCDCdY5VgwNWE5oXrGjtsmGdz_MnaVwQmi2dk,179
9
9
  zhmiscellany/dict.py,sha256=dNu3G9qiJeLgE7JY3QD31GJU7EfLsYPqxf8AOhBsYag,81
10
10
  zhmiscellany/discord.py,sha256=yKoigWI3tONfYSoMEynGGEWW1VsXSRdkg8vPbIKwBNI,20312
11
- zhmiscellany/fileio.py,sha256=KTMmUlvEoFcRCyVIC1ghTJ7OD6H4VfuLbs08EWZX0es,22151
11
+ zhmiscellany/fileio.py,sha256=7eMIrLBX69KLdxNbFur8hG16iZkg570LzOGizU2h2s4,22676
12
12
  zhmiscellany/gui.py,sha256=OVwuZ_kWHJlgKPeYR7fAAyomNmU-OnxOgXZelVNPm1w,10409
13
13
  zhmiscellany/image.py,sha256=6Hz5sfym_o7FHokGUKeXRsjl89VY_ZMSLnvuSam1icI,8265
14
14
  zhmiscellany/list.py,sha256=BnbYG-lpHmi0C4v8jLfaeXqQdc3opmNgkvY6yz4pasg,1475
@@ -21,7 +21,7 @@ zhmiscellany/pipes.py,sha256=RlHxsW_M_R6UJUIDgYVS_zfqUwO8kXG8j-0YG5qByjo,4637
21
21
  zhmiscellany/processing.py,sha256=ZhNAJ5OfCUHuaXj0z6XZ94ZGSK86-EdCyqW-9ILayLg,11524
22
22
  zhmiscellany/rust.py,sha256=cHkSpdtq7QQW3yzBEAYL9lZxLW0h4wal2tsxIOnyTrA,494
23
23
  zhmiscellany/string.py,sha256=A4ilBWSYlrJ0AJ0axvepSSjYCYwYk5X-vRrHNphi_ow,4809
24
- zhmiscellany-6.3.3.dist-info/METADATA,sha256=C0N-dl_MfRXvHlgCnry-2vK4L7B74pb0p-TLON1iABM,43872
25
- zhmiscellany-6.3.3.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
26
- zhmiscellany-6.3.3.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
27
- zhmiscellany-6.3.3.dist-info/RECORD,,
24
+ zhmiscellany-6.3.6.dist-info/METADATA,sha256=HjIrPNfZ5x7q3srMfDGlcC8_Jkl5WWLPLdO-wkRS798,43872
25
+ zhmiscellany-6.3.6.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
26
+ zhmiscellany-6.3.6.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
27
+ zhmiscellany-6.3.6.dist-info/RECORD,,