mirror of
https://github.com/wassname/ray.git
synced 2026-08-13 12:30:18 +08:00
[tune] logger refactor part 1: move classes and utilities to own files (#11746)
* [tune] logger refactor part 1: move classes and utilities to own files * Fix circular dependency * Remove uneeded pretty print copy * Apply suggestions from code review
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
import numbers
|
||||
import os
|
||||
import inspect
|
||||
import threading
|
||||
@@ -538,6 +540,31 @@ def detect_config_single(func):
|
||||
return use_config_single
|
||||
|
||||
|
||||
class SafeFallbackEncoder(json.JSONEncoder):
|
||||
def __init__(self, nan_str="null", **kwargs):
|
||||
super(SafeFallbackEncoder, self).__init__(**kwargs)
|
||||
self.nan_str = nan_str
|
||||
|
||||
def default(self, value):
|
||||
try:
|
||||
if np.isnan(value):
|
||||
return self.nan_str
|
||||
|
||||
if (type(value).__module__ == np.__name__
|
||||
and isinstance(value, np.ndarray)):
|
||||
return value.tolist()
|
||||
|
||||
if issubclass(type(value), numbers.Integral):
|
||||
return int(value)
|
||||
if issubclass(type(value), numbers.Number):
|
||||
return float(value)
|
||||
|
||||
return super(SafeFallbackEncoder, self).default(value)
|
||||
|
||||
except Exception:
|
||||
return str(value) # give up, just stringify it (ok for logs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
ray.init()
|
||||
X = pin_in_object_store("hello")
|
||||
|
||||
Reference in New Issue
Block a user