ml-dash 0.5.2__tar.gz → 0.5.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ml-dash
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: ML experiment tracking and data storage
5
5
  Keywords: machine-learning,experiment-tracking,mlops,data-storage
6
6
  Author: Ge Yang, Tom Tao
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ml-dash"
3
- version = "0.5.2"
3
+ version = "0.5.3"
4
4
  description = "ML experiment tracking and data storage"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.9"
@@ -263,11 +263,12 @@ class FileBuilder:
263
263
  if self._experiment._write_protected:
264
264
  raise RuntimeError("Experiment is write-protected and cannot be modified.")
265
265
 
266
- # Create temporary file
267
- temp_fd, temp_path = tempfile.mkstemp(suffix='.json', text=True)
266
+ # Create temporary file with desired filename
267
+ temp_dir = tempfile.mkdtemp()
268
+ temp_path = os.path.join(temp_dir, file_name)
268
269
  try:
269
270
  # Write JSON content to temp file
270
- with os.fdopen(temp_fd, 'w') as f:
271
+ with open(temp_path, 'w') as f:
271
272
  json.dump(content, f, indent=2)
272
273
 
273
274
  # Save using existing save() method
@@ -282,9 +283,10 @@ class FileBuilder:
282
283
 
283
284
  return result
284
285
  finally:
285
- # Clean up temp file
286
+ # Clean up temp file and directory
286
287
  try:
287
288
  os.unlink(temp_path)
289
+ os.rmdir(temp_dir)
288
290
  except Exception:
289
291
  pass
290
292
 
@@ -326,9 +328,9 @@ class FileBuilder:
326
328
  if self._experiment._write_protected:
327
329
  raise RuntimeError("Experiment is write-protected and cannot be modified.")
328
330
 
329
- # Create temporary file
330
- temp_fd, temp_path = tempfile.mkstemp(suffix='.pt')
331
- os.close(temp_fd) # Close the file descriptor
331
+ # Create temporary file with desired filename
332
+ temp_dir = tempfile.mkdtemp()
333
+ temp_path = os.path.join(temp_dir, file_name)
332
334
 
333
335
  try:
334
336
  # Save model to temp file
@@ -346,9 +348,69 @@ class FileBuilder:
346
348
 
347
349
  return result
348
350
  finally:
349
- # Clean up temp file
351
+ # Clean up temp file and directory
350
352
  try:
351
353
  os.unlink(temp_path)
354
+ os.rmdir(temp_dir)
355
+ except Exception:
356
+ pass
357
+
358
+ def save_pkl(self, content: Any, file_name: str) -> Dict[str, Any]:
359
+ """
360
+ Save Python object to a pickle file.
361
+
362
+ Args:
363
+ content: Python object to pickle (must be pickle-serializable)
364
+ file_name: Name of the file to create (should end with .pkl or .pickle)
365
+
366
+ Returns:
367
+ File metadata dict with id, path, filename, checksum, etc.
368
+
369
+ Raises:
370
+ RuntimeError: If experiment is not open or write-protected
371
+ ValueError: If content cannot be pickled
372
+
373
+ Examples:
374
+ data = {"model": "resnet50", "weights": np.array([1, 2, 3])}
375
+ result = experiment.file(prefix="/data").save_pkl(data, "data.pkl")
376
+
377
+ # Or save any Python object
378
+ result = experiment.file(prefix="/models").save_pkl(trained_model, "model.pickle")
379
+ """
380
+ import pickle
381
+ import tempfile
382
+ import os
383
+
384
+ if not self._experiment._is_open:
385
+ raise RuntimeError("Experiment not open. Use experiment.run.start() or context manager.")
386
+
387
+ if self._experiment._write_protected:
388
+ raise RuntimeError("Experiment is write-protected and cannot be modified.")
389
+
390
+ # Create temporary file with desired filename
391
+ temp_dir = tempfile.mkdtemp()
392
+ temp_path = os.path.join(temp_dir, file_name)
393
+ try:
394
+ # Write pickled content to temp file
395
+ with open(temp_path, 'wb') as f:
396
+ pickle.dump(content, f)
397
+
398
+ # Save using existing save() method
399
+ original_file_path = self._file_path
400
+ self._file_path = temp_path
401
+
402
+ # Upload and get result
403
+ result = self.save()
404
+
405
+ # Restore original file_path
406
+ self._file_path = original_file_path
407
+
408
+ return result
409
+ finally:
410
+ # Clean up temp file and directory
411
+ try:
412
+ os.unlink(temp_path)
413
+ os.rmdir(temp_dir)
352
414
  except Exception:
353
415
  pass
354
416
 
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