Skip to content

Commit

Permalink
fix: pydantic/numpy patching causes `Cannot interpret 'numpy.float16 …
Browse files Browse the repository at this point in the history
…| numpy.float32' as a data type` (#4933)

* fix: bug: pydantic/numpy patching causes `Cannot interpret 'numpy.float16 | numpy.float32' as a data type`
Fixes #4926

Signed-off-by: Frost Ming <[email protected]>

* fix: correct type

Signed-off-by: Frost Ming <[email protected]>

---------

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Aug 23, 2024
1 parent eeae86b commit 737d402
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/_bentoml_sdk/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def numpy_prepare_pydantic_annotations(
return None

args = get_args(source)
dtype = np.dtype(get_args(args[1])[0]).name if args else None
try:
dtype = np.dtype(get_args(args[1])[0]).name if args else None
except TypeError:
return None
shape: tuple[int, ...] | None = None

_, other_annotations = _known_annotated_metadata.collect_known_metadata(annotations)
Expand Down
10 changes: 2 additions & 8 deletions src/bentoml/_internal/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,30 +175,24 @@ class _ServiceTraceContext:
)

@property
def trace_id(self) -> t.Optional[int]:
def trace_id(self) -> int:
from opentelemetry import trace

span = trace.get_current_span()
if span is None:
return None
return span.get_span_context().trace_id

@property
def sampled(self) -> int:
from opentelemetry import trace

span = trace.get_current_span()
if span is None:
return 0
return 1 if span.get_span_context().trace_flags.sampled else 0

@property
def span_id(self) -> t.Optional[int]:
def span_id(self) -> int:
from opentelemetry import trace

span = trace.get_current_span()
if span is None:
return None
return span.get_span_context().span_id

@property
Expand Down

0 comments on commit 737d402

Please sign in to comment.