Skip to content

Commit

Permalink
fix: remove assertion for dtype (#3320)
Browse files Browse the repository at this point in the history
It also deprecates passing non-dataframe input to DataFrame.from_sample.
  • Loading branch information
aarnphm committed Dec 7, 2022
1 parent 687c3e0 commit c662b2f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/bentoml/_internal/io_descriptors/pandas.py
Expand Up @@ -387,8 +387,16 @@ def _from_sample(self, sample: ext.PdDataFrame) -> ext.PdDataFrame:
def predict(inputs: pd.DataFrame) -> pd.DataFrame: ...
"""
if LazyType["ext.NpNDArray"]("numpy", "ndarray").isinstance(sample):
logger.warning(
"'from_sample' from type '%s' is deprecated. Make sure to only pass pandas DataFrame.",
type(sample),
)
sample = pd.DataFrame(sample)
elif isinstance(sample, str):
logger.warning(
"'from_sample' from type '%s' is deprecated. Make sure to only pass pandas DataFrame.",
type(sample),
)
try:
if os.path.exists(sample):
try:
Expand Down Expand Up @@ -517,12 +525,10 @@ async def from_http_request(self, request: Request) -> ext.PdDataFrame:

obj = await request.body()
if serialization_format is SerializationFormat.JSON:
assert not isinstance(self._dtype, bool)
res = pd.read_json(io.BytesIO(obj), dtype=self._dtype, orient=self._orient)
elif serialization_format is SerializationFormat.PARQUET:
res = pd.read_parquet(io.BytesIO(obj), engine=get_parquet_engine())
elif serialization_format is SerializationFormat.CSV:
assert not isinstance(self._dtype, bool)
res: ext.PdDataFrame = pd.read_csv(io.BytesIO(obj), dtype=self._dtype)
else:
raise InvalidArgument(
Expand Down

0 comments on commit c662b2f

Please sign in to comment.