Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warning from pandas.read_json #2346

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ax/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from abc import abstractmethod
from functools import reduce
from hashlib import md5
from io import StringIO
from typing import Any, Dict, Iterable, List, Optional, Set, Type, TypeVar, Union

import numpy as np
Expand Down Expand Up @@ -202,7 +203,7 @@ def deserialize_init_args(
if "df" in args and not isinstance(args["df"], pd.DataFrame):
# NOTE: Need dtype=False, otherwise infers arm_names like
# "4_1" should be int 41.
args["df"] = pd.read_json(args["df"]["value"], dtype=False)
args["df"] = pd.read_json(StringIO(args["df"]["value"]), dtype=False)
return extract_init_args(args=args, class_=cls)

@property
Expand Down
3 changes: 2 additions & 1 deletion ax/core/tests/test_batch_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,9 @@ def test_clone_to(self, _) -> None:
batch.mark_running(no_runner_required=True)
new_batch_trial = batch.clone_to()
self.assertEqual(new_batch_trial.index, 2)
# Set index to original trial's value for equality check.
# Set index & time_created to original trial's value for equality check.
new_batch_trial._index = batch.index
new_batch_trial._time_created = batch._time_created
self.assertEqual(new_batch_trial, batch)

def test_Runner(self) -> None:
Expand Down
3 changes: 2 additions & 1 deletion ax/storage/json_store/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collections import OrderedDict
from enum import Enum
from inspect import isclass
from io import StringIO
from logging import Logger
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union

Expand Down Expand Up @@ -132,7 +133,7 @@ def object_from_json(
elif _type == "DataFrame":
# Need dtype=False, otherwise infers arm_names like "4_1"
# should be int 41
return pd.read_json(object_json["value"], dtype=False)
return pd.read_json(StringIO(object_json["value"]), dtype=False)
elif _type == "ndarray":
return np.array(object_json["value"])
elif _type == "Tensor":
Expand Down
3 changes: 2 additions & 1 deletion ax/storage/sqa_store/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import json
from collections import defaultdict, OrderedDict
from enum import Enum
from io import StringIO
from logging import Logger
from typing import Any, cast, Dict, List, Optional, Tuple, Type, Union

Expand Down Expand Up @@ -982,7 +983,7 @@ def data_from_sqa(
# Override df from deserialize_init_args with `data_json`.
# NOTE: Need dtype=False, otherwise infers arm_names like
# "4_1" should be int 41.
kwargs["df"] = pd.read_json(data_sqa.data_json, dtype=False)
kwargs["df"] = pd.read_json(StringIO(data_sqa.data_json), dtype=False)

dat = data_constructor(**kwargs)

Expand Down
Loading