We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
sample_categorical does not work with RDBStorage
`sample_categorical` raises errors when storage is an RDBStorage, due to a cast problem.

Repro:
```python
from pfnopt import minimize
from pfnopt.storage import RDBStorage
from pfnopt.study import create_new_study


def objective(client):
    
    y = client.sample_categorical('y', (-1.0, 1.0))
    return y


if __name__ == '__main__':

    storage = RDBStorage('sqlite:///:memory:')
    study = create_new_study(storage)

    minimize(objective, storage=storage, n_trials=500)
```

Error messages:
```
Traceback (most recent call last):
  File "/Users/sano/PycharmProjects/pfnopt/repro.py", line 17, in <module>
    minimize(objective, storage=storage, n_trials=500)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py", line 145, in minimize
    study.run(func, n_trials, timeout_seconds, n_jobs)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py", line 66, in run
    self._run_sequential(func, n_trials, timeout_seconds)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py", line 88, in _run_sequential
    result = func(client)
  File "/Users/sano/PycharmProjects/pfnopt/repro.py", line 8, in objective
    y = client.sample_categorical('y', (-1.0, 1.0))
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py", line 33, in sample_categorical
    return self._sample(name, distributions.CategoricalDistribution(choices=choices))
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py", line 90, in _sample
    self.storage, self.study_id, name, distribution)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py", line 54, in sample
    param_distribution, below_param_values, above_param_values)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py", line 80, in _sample_categorical
    upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/_hyperopt.py", line 627, in sample_categorical
    counts_b = np.bincount(obs_below, minlength=upper, weights=weights_b)
TypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe'
```

This does not happen when `n_trials` is small (e.g., 5).
sample_categorical does not work with RDBStorage
`sample_categorical` raises errors when storage is an RDBStorage, due to a cast problem.

Repro:
```python
from pfnopt import minimize
from pfnopt.storage import RDBStorage
from pfnopt.study import create_new_study


def objective(client):
    
    y = client.sample_categorical('y', (-1.0, 1.0))
    return y


if __name__ == '__main__':

    storage = RDBStorage('sqlite:///:memory:')
    study = create_new_study(storage)

    minimize(objective, storage=storage, n_trials=500)
```

Error messages:
```
Traceback (most recent call last):
  File "/Users/sano/PycharmProjects/pfnopt/repro.py", line 17, in <module>
    minimize(objective, storage=storage, n_trials=500)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py", line 145, in minimize
    study.run(func, n_trials, timeout_seconds, n_jobs)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py", line 66, in run
    self._run_sequential(func, n_trials, timeout_seconds)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py", line 88, in _run_sequential
    result = func(client)
  File "/Users/sano/PycharmProjects/pfnopt/repro.py", line 8, in objective
    y = client.sample_categorical('y', (-1.0, 1.0))
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py", line 33, in sample_categorical
    return self._sample(name, distributions.CategoricalDistribution(choices=choices))
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py", line 90, in _sample
    self.storage, self.study_id, name, distribution)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py", line 54, in sample
    param_distribution, below_param_values, above_param_values)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py", line 80, in _sample_categorical
    upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)
  File "/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/_hyperopt.py", line 627, in sample_categorical
    counts_b = np.bincount(obs_below, minlength=upper, weights=weights_b)
TypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe'
```

This does not happen when `n_trials` is small (e.g., 5).

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pfnopt/samplers/tpe.py`
Content:
```
1 import math
2 import numpy
3 from typing import List  # NOQA
4 from typing import Optional  # NOQA
5 
6 from pfnopt import distributions  # NOQA
7 from pfnopt.samplers import _hyperopt
8 from pfnopt.samplers import base
9 from pfnopt.samplers import random
10 from pfnopt.storage.base import BaseStorage  # NOQA
11 
12 
13 class TPESampler(base.BaseSampler):
14 
15     def __init__(self,
16                  prior_weight=_hyperopt.default_prior_weight,
17                  n_startup_trials=_hyperopt.default_n_startup_trials,
18                  n_ei_candidates=_hyperopt.default_n_ei_candidates,
19                  gamma=_hyperopt.default_gamma,
20                  seed=None):
21         # type: (float, int, int, float, Optional[int]) -> None
22         self.prior_weight = prior_weight
23         self.n_startup_trials = n_startup_trials
24         self.n_ei_candidates = n_ei_candidates
25         self.gamma = gamma
26         self.seed = seed
27 
28         self.rng = numpy.random.RandomState(seed)
29         self.random_sampler = random.RandomSampler(seed=seed)
30 
31     def sample(self, storage, study_id, param_name, param_distribution):
32         # type: (BaseStorage, int, str, distributions.BaseDistribution) -> float
33         observation_pairs = storage.get_trial_param_result_pairs(
34             study_id, param_name)
35         n = len(observation_pairs)
36 
37         # TODO(Akiba): this behavior is slightly different from hyperopt
38         if n < self.n_startup_trials:
39             return self.random_sampler.sample(storage, study_id, param_name, param_distribution)
40 
41         below_param_values, above_param_values = _hyperopt.ap_filter_trials(
42             range(n), [p[0] for p in observation_pairs],
43             range(n), [p[1] for p in observation_pairs],
44             self.gamma)
45 
46         if isinstance(param_distribution, distributions.UniformDistribution):
47             return self._sample_uniform(
48                 param_distribution, below_param_values, above_param_values)
49         elif isinstance(param_distribution, distributions.LogUniformDistribution):
50             return self._sample_loguniform(
51                 param_distribution, below_param_values, above_param_values)
52         elif isinstance(param_distribution, distributions.CategoricalDistribution):
53             return self._sample_categorical(
54                 param_distribution, below_param_values, above_param_values)
55         else:
56             raise NotImplementedError
57 
58     def _sample_uniform(self, distribution, below, above):
59         # type: (distributions.UniformDistribution, List[float], List[float]) -> float
60         return _hyperopt.sample_uniform(
61             obs_below=below, obs_above=above, prior_weight=self.prior_weight,
62             low=distribution.low, high=distribution.high,
63             size=(self.n_ei_candidates,), rng=self.rng)
64 
65     def _sample_loguniform(self, distribution, below, above):
66         # type: (distributions.LogUniformDistribution, List[float], List[float]) -> float
67 
68         return _hyperopt.sample_loguniform(
69             obs_below=below, obs_above=above, prior_weight=self.prior_weight,
70             # `sample_loguniform` generates values in [exp(low), exp(high)]
71             low=math.log(distribution.low),
72             high=math.log(distribution.high),
73             size=(self.n_ei_candidates,), rng=self.rng)
74 
75     def _sample_categorical(self, distribution, below, above):
76         # type: (distributions.CategoricalDistribution, List[float], List[float]) -> float
77         choices = distribution.choices
78         idx = _hyperopt.sample_categorical(
79             obs_below=below, obs_above=above, prior_weight=self.prior_weight,
80             upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)
81         return idx
82
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pfnopt/samplers/tpe.py b/pfnopt/samplers/tpe.py
--- a/pfnopt/samplers/tpe.py
+++ b/pfnopt/samplers/tpe.py
@@ -75,6 +75,8 @@
     def _sample_categorical(self, distribution, below, above):
         # type: (distributions.CategoricalDistribution, List[float], List[float]) -> float
         choices = distribution.choices
+        below = list(map(int, below))
+        above = list(map(int, above))
         idx = _hyperopt.sample_categorical(
             obs_below=below, obs_above=above, prior_weight=self.prior_weight,
             upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)

{"golden_diff": "diff --git a/pfnopt/samplers/tpe.py b/pfnopt/samplers/tpe.py\n--- a/pfnopt/samplers/tpe.py\n+++ b/pfnopt/samplers/tpe.py\n@@ -75,6 +75,8 @@\n     def _sample_categorical(self, distribution, below, above):\n         # type: (distributions.CategoricalDistribution, List[float], List[float]) -> float\n         choices = distribution.choices\n+        below = list(map(int, below))\n+        above = list(map(int, above))\n         idx = _hyperopt.sample_categorical(\n             obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n             upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)\n", "issue": "sample_categorical does not work with RDBStorage\n`sample_categorical` raises errors when storage is an RDBStorage, due to a cast problem.\r\n\r\nRepro:\r\n```python\r\nfrom pfnopt import minimize\r\nfrom pfnopt.storage import RDBStorage\r\nfrom pfnopt.study import create_new_study\r\n\r\n\r\ndef objective(client):\r\n    \r\n    y = client.sample_categorical('y', (-1.0, 1.0))\r\n    return y\r\n\r\n\r\nif __name__ == '__main__':\r\n\r\n    storage = RDBStorage('sqlite:///:memory:')\r\n    study = create_new_study(storage)\r\n\r\n    minimize(objective, storage=storage, n_trials=500)\r\n```\r\n\r\nError messages:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/sano/PycharmProjects/pfnopt/repro.py\", line 17, in <module>\r\n    minimize(objective, storage=storage, n_trials=500)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py\", line 145, in minimize\r\n    study.run(func, n_trials, timeout_seconds, n_jobs)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py\", line 66, in run\r\n    self._run_sequential(func, n_trials, timeout_seconds)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py\", line 88, in _run_sequential\r\n    result = func(client)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/repro.py\", line 8, in objective\r\n    y = client.sample_categorical('y', (-1.0, 1.0))\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py\", line 33, in sample_categorical\r\n    return self._sample(name, distributions.CategoricalDistribution(choices=choices))\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py\", line 90, in _sample\r\n    self.storage, self.study_id, name, distribution)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py\", line 54, in sample\r\n    param_distribution, below_param_values, above_param_values)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py\", line 80, in _sample_categorical\r\n    upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/_hyperopt.py\", line 627, in sample_categorical\r\n    counts_b = np.bincount(obs_below, minlength=upper, weights=weights_b)\r\nTypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe'\r\n```\r\n\r\nThis does not happen when `n_trials` is small (e.g., 5).\nsample_categorical does not work with RDBStorage\n`sample_categorical` raises errors when storage is an RDBStorage, due to a cast problem.\r\n\r\nRepro:\r\n```python\r\nfrom pfnopt import minimize\r\nfrom pfnopt.storage import RDBStorage\r\nfrom pfnopt.study import create_new_study\r\n\r\n\r\ndef objective(client):\r\n    \r\n    y = client.sample_categorical('y', (-1.0, 1.0))\r\n    return y\r\n\r\n\r\nif __name__ == '__main__':\r\n\r\n    storage = RDBStorage('sqlite:///:memory:')\r\n    study = create_new_study(storage)\r\n\r\n    minimize(objective, storage=storage, n_trials=500)\r\n```\r\n\r\nError messages:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/Users/sano/PycharmProjects/pfnopt/repro.py\", line 17, in <module>\r\n    minimize(objective, storage=storage, n_trials=500)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py\", line 145, in minimize\r\n    study.run(func, n_trials, timeout_seconds, n_jobs)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py\", line 66, in run\r\n    self._run_sequential(func, n_trials, timeout_seconds)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/study.py\", line 88, in _run_sequential\r\n    result = func(client)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/repro.py\", line 8, in objective\r\n    y = client.sample_categorical('y', (-1.0, 1.0))\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py\", line 33, in sample_categorical\r\n    return self._sample(name, distributions.CategoricalDistribution(choices=choices))\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/client.py\", line 90, in _sample\r\n    self.storage, self.study_id, name, distribution)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py\", line 54, in sample\r\n    param_distribution, below_param_values, above_param_values)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/tpe.py\", line 80, in _sample_categorical\r\n    upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)\r\n  File \"/Users/sano/PycharmProjects/pfnopt/pfnopt/samplers/_hyperopt.py\", line 627, in sample_categorical\r\n    counts_b = np.bincount(obs_below, minlength=upper, weights=weights_b)\r\nTypeError: Cannot cast array data from dtype('float64') to dtype('int64') according to the rule 'safe'\r\n```\r\n\r\nThis does not happen when `n_trials` is small (e.g., 5).\n", "before_files": [{"content": "import math\nimport numpy\nfrom typing import List  # NOQA\nfrom typing import Optional  # NOQA\n\nfrom pfnopt import distributions  # NOQA\nfrom pfnopt.samplers import _hyperopt\nfrom pfnopt.samplers import base\nfrom pfnopt.samplers import random\nfrom pfnopt.storage.base import BaseStorage  # NOQA\n\n\nclass TPESampler(base.BaseSampler):\n\n    def __init__(self,\n                 prior_weight=_hyperopt.default_prior_weight,\n                 n_startup_trials=_hyperopt.default_n_startup_trials,\n                 n_ei_candidates=_hyperopt.default_n_ei_candidates,\n                 gamma=_hyperopt.default_gamma,\n                 seed=None):\n        # type: (float, int, int, float, Optional[int]) -> None\n        self.prior_weight = prior_weight\n        self.n_startup_trials = n_startup_trials\n        self.n_ei_candidates = n_ei_candidates\n        self.gamma = gamma\n        self.seed = seed\n\n        self.rng = numpy.random.RandomState(seed)\n        self.random_sampler = random.RandomSampler(seed=seed)\n\n    def sample(self, storage, study_id, param_name, param_distribution):\n        # type: (BaseStorage, int, str, distributions.BaseDistribution) -> float\n        observation_pairs = storage.get_trial_param_result_pairs(\n            study_id, param_name)\n        n = len(observation_pairs)\n\n        # TODO(Akiba): this behavior is slightly different from hyperopt\n        if n < self.n_startup_trials:\n            return self.random_sampler.sample(storage, study_id, param_name, param_distribution)\n\n        below_param_values, above_param_values = _hyperopt.ap_filter_trials(\n            range(n), [p[0] for p in observation_pairs],\n            range(n), [p[1] for p in observation_pairs],\n            self.gamma)\n\n        if isinstance(param_distribution, distributions.UniformDistribution):\n            return self._sample_uniform(\n                param_distribution, below_param_values, above_param_values)\n        elif isinstance(param_distribution, distributions.LogUniformDistribution):\n            return self._sample_loguniform(\n                param_distribution, below_param_values, above_param_values)\n        elif isinstance(param_distribution, distributions.CategoricalDistribution):\n            return self._sample_categorical(\n                param_distribution, below_param_values, above_param_values)\n        else:\n            raise NotImplementedError\n\n    def _sample_uniform(self, distribution, below, above):\n        # type: (distributions.UniformDistribution, List[float], List[float]) -> float\n        return _hyperopt.sample_uniform(\n            obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n            low=distribution.low, high=distribution.high,\n            size=(self.n_ei_candidates,), rng=self.rng)\n\n    def _sample_loguniform(self, distribution, below, above):\n        # type: (distributions.LogUniformDistribution, List[float], List[float]) -> float\n\n        return _hyperopt.sample_loguniform(\n            obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n            # `sample_loguniform` generates values in [exp(low), exp(high)]\n            low=math.log(distribution.low),\n            high=math.log(distribution.high),\n            size=(self.n_ei_candidates,), rng=self.rng)\n\n    def _sample_categorical(self, distribution, below, above):\n        # type: (distributions.CategoricalDistribution, List[float], List[float]) -> float\n        choices = distribution.choices\n        idx = _hyperopt.sample_categorical(\n            obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n            upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)\n        return idx\n", "path": "pfnopt/samplers/tpe.py"}], "after_files": [{"content": "import math\nimport numpy\nfrom typing import List  # NOQA\nfrom typing import Optional  # NOQA\n\nfrom pfnopt import distributions  # NOQA\nfrom pfnopt.samplers import _hyperopt\nfrom pfnopt.samplers import base\nfrom pfnopt.samplers import random\nfrom pfnopt.storage.base import BaseStorage  # NOQA\n\n\nclass TPESampler(base.BaseSampler):\n\n    def __init__(self,\n                 prior_weight=_hyperopt.default_prior_weight,\n                 n_startup_trials=_hyperopt.default_n_startup_trials,\n                 n_ei_candidates=_hyperopt.default_n_ei_candidates,\n                 gamma=_hyperopt.default_gamma,\n                 seed=None):\n        # type: (float, int, int, float, Optional[int]) -> None\n        self.prior_weight = prior_weight\n        self.n_startup_trials = n_startup_trials\n        self.n_ei_candidates = n_ei_candidates\n        self.gamma = gamma\n        self.seed = seed\n\n        self.rng = numpy.random.RandomState(seed)\n        self.random_sampler = random.RandomSampler(seed=seed)\n\n    def sample(self, storage, study_id, param_name, param_distribution):\n        # type: (BaseStorage, int, str, distributions.BaseDistribution) -> float\n        observation_pairs = storage.get_trial_param_result_pairs(\n            study_id, param_name)\n        n = len(observation_pairs)\n\n        # TODO(Akiba): this behavior is slightly different from hyperopt\n        if n < self.n_startup_trials:\n            return self.random_sampler.sample(storage, study_id, param_name, param_distribution)\n\n        below_param_values, above_param_values = _hyperopt.ap_filter_trials(\n            range(n), [p[0] for p in observation_pairs],\n            range(n), [p[1] for p in observation_pairs],\n            self.gamma)\n\n        if isinstance(param_distribution, distributions.UniformDistribution):\n            return self._sample_uniform(\n                param_distribution, below_param_values, above_param_values)\n        elif isinstance(param_distribution, distributions.LogUniformDistribution):\n            return self._sample_loguniform(\n                param_distribution, below_param_values, above_param_values)\n        elif isinstance(param_distribution, distributions.CategoricalDistribution):\n            return self._sample_categorical(\n                param_distribution, below_param_values, above_param_values)\n        else:\n            raise NotImplementedError\n\n    def _sample_uniform(self, distribution, below, above):\n        # type: (distributions.UniformDistribution, List[float], List[float]) -> float\n        return _hyperopt.sample_uniform(\n            obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n            low=distribution.low, high=distribution.high,\n            size=(self.n_ei_candidates,), rng=self.rng)\n\n    def _sample_loguniform(self, distribution, below, above):\n        # type: (distributions.LogUniformDistribution, List[float], List[float]) -> float\n\n        return _hyperopt.sample_loguniform(\n            obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n            # `sample_loguniform` generates values in [exp(low), exp(high)]\n            low=math.log(distribution.low),\n            high=math.log(distribution.high),\n            size=(self.n_ei_candidates,), rng=self.rng)\n\n    def _sample_categorical(self, distribution, below, above):\n        # type: (distributions.CategoricalDistribution, List[float], List[float]) -> float\n        choices = distribution.choices\n        below = list(map(int, below))\n        above = list(map(int, above))\n        idx = _hyperopt.sample_categorical(\n            obs_below=below, obs_above=above, prior_weight=self.prior_weight,\n            upper=len(choices), size=(self.n_ei_candidates, ), rng=self.rng)\n        return idx\n", "path": "pfnopt/samplers/tpe.py"}]}