zhmiscellany 6.2.8__py3-none-any.whl → 6.2.9__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 +33 -2
- {zhmiscellany-6.2.8.dist-info → zhmiscellany-6.2.9.dist-info}/METADATA +1 -1
- {zhmiscellany-6.2.8.dist-info → zhmiscellany-6.2.9.dist-info}/RECORD +5 -5
- {zhmiscellany-6.2.8.dist-info → zhmiscellany-6.2.9.dist-info}/WHEEL +0 -0
- {zhmiscellany-6.2.8.dist-info → zhmiscellany-6.2.9.dist-info}/top_level.txt +0 -0
zhmiscellany/fileio.py
CHANGED
|
@@ -238,7 +238,37 @@ def cache(function, *args, **kwargs):
|
|
|
238
238
|
return inspect.getsource(obj)
|
|
239
239
|
except (OSError, TypeError):
|
|
240
240
|
return str(obj) # Fallback for lambdas/partials
|
|
241
|
-
|
|
241
|
+
|
|
242
|
+
# PANDAS DATAFRAMES: Convert to stable dictionary format
|
|
243
|
+
if hasattr(obj, '__class__') and obj.__class__.__name__ == 'DataFrame':
|
|
244
|
+
try:
|
|
245
|
+
import pandas as pd
|
|
246
|
+
if isinstance(obj, pd.DataFrame):
|
|
247
|
+
# Convert to dict with records orientation for stability
|
|
248
|
+
# Include dtypes to ensure type information is preserved
|
|
249
|
+
return {
|
|
250
|
+
'data': obj.to_dict(orient='split'),
|
|
251
|
+
'dtypes': {col: str(dtype) for col, dtype in obj.dtypes.items()},
|
|
252
|
+
'index_name': obj.index.name,
|
|
253
|
+
'columns': list(obj.columns)
|
|
254
|
+
}
|
|
255
|
+
except ImportError:
|
|
256
|
+
pass
|
|
257
|
+
|
|
258
|
+
# PANDAS SERIES: Similar handling
|
|
259
|
+
if hasattr(obj, '__class__') and obj.__class__.__name__ == 'Series':
|
|
260
|
+
try:
|
|
261
|
+
import pandas as pd
|
|
262
|
+
if isinstance(obj, pd.Series):
|
|
263
|
+
return {
|
|
264
|
+
'data': obj.to_dict(),
|
|
265
|
+
'dtype': str(obj.dtype),
|
|
266
|
+
'name': obj.name,
|
|
267
|
+
'index': list(obj.index)
|
|
268
|
+
}
|
|
269
|
+
except ImportError:
|
|
270
|
+
pass
|
|
271
|
+
|
|
242
272
|
# SETS: Must be sorted to ensure determinism!
|
|
243
273
|
# JSON doesn't support sets, so we turn them into sorted lists.
|
|
244
274
|
if isinstance(obj, set):
|
|
@@ -255,9 +285,10 @@ def cache(function, *args, **kwargs):
|
|
|
255
285
|
# CUSTOM OBJECTS: Try to return their __dict__ or string rep
|
|
256
286
|
if hasattr(obj, '__dict__'):
|
|
257
287
|
return obj.__dict__
|
|
258
|
-
|
|
288
|
+
|
|
259
289
|
# Fallback: String representation (risky if str() format changes)
|
|
260
290
|
return str(obj)
|
|
291
|
+
|
|
261
292
|
json_bytes = orjson.dumps(
|
|
262
293
|
data,
|
|
263
294
|
default=default_converter,
|
|
@@ -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
|
|
11
|
+
zhmiscellany/fileio.py,sha256=-W1A_sEymfaqxhiEY-y6h_owBlAyVWNm4PSFn7LVoBI,21991
|
|
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=S0Rb6ndTC6N23-kz4hLEeRNgAaWjcMAtt8QNDE8x4v4,11350
|
|
22
22
|
zhmiscellany/rust.py,sha256=cHkSpdtq7QQW3yzBEAYL9lZxLW0h4wal2tsxIOnyTrA,494
|
|
23
23
|
zhmiscellany/string.py,sha256=A4ilBWSYlrJ0AJ0axvepSSjYCYwYk5X-vRrHNphi_ow,4809
|
|
24
|
-
zhmiscellany-6.2.
|
|
25
|
-
zhmiscellany-6.2.
|
|
26
|
-
zhmiscellany-6.2.
|
|
27
|
-
zhmiscellany-6.2.
|
|
24
|
+
zhmiscellany-6.2.9.dist-info/METADATA,sha256=92jIwQqgCsL9ZfTi7pPeFNrFYPAIYpjb_K6lNJ6ZlEM,43872
|
|
25
|
+
zhmiscellany-6.2.9.dist-info/WHEEL,sha256=hPN0AlP2dZM_3ZJZWP4WooepkmU9wzjGgCLCeFjkHLA,92
|
|
26
|
+
zhmiscellany-6.2.9.dist-info/top_level.txt,sha256=ioDtsrevCI52rTxZntMPljRIBsZs73tD0hI00HektiE,13
|
|
27
|
+
zhmiscellany-6.2.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|