Skip to content

Commit c5dbfa4

Browse files
committed
change according to comments
1 parent 6542ff2 commit c5dbfa4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pandas/_testing/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
from pandas.core.dtypes.common import (
3131
is_datetime64_dtype,
3232
is_datetime64tz_dtype,
33+
is_float_dtype,
34+
is_integer_dtype,
3335
is_period_dtype,
3436
is_sequence,
3537
is_timedelta64_dtype,
38+
is_unsigned_integer_dtype,
3639
pandas_dtype,
3740
)
3841

@@ -300,13 +303,13 @@ def makeNumericIndex(k=10, name=None, *, dtype):
300303
dtype = pandas_dtype(dtype)
301304
assert isinstance(dtype, np.dtype)
302305

303-
if dtype.kind == "i":
304-
values = list(range(k))
305-
elif dtype.kind == "u":
306-
start_num = 2 ** (dtype.itemsize * 8 - 1)
307-
values = [start_num + i for i in range(k)]
308-
elif dtype.kind == "f":
309-
values = sorted(np.random.random_sample(k)) - np.random.random_sample(1)
306+
if is_integer_dtype(dtype):
307+
values = np.arange(k, dtype=dtype)
308+
if is_unsigned_integer_dtype(dtype):
309+
values += 2 ** (dtype.itemsize * 8 - 1)
310+
elif is_float_dtype(dtype):
311+
values = np.random.random_sample(k) - np.random.random_sample(1)
312+
values.sort()
310313
values = values * (10 ** np.random.randint(0, 9))
311314
else:
312315
raise NotImplementedError(f"wrong dtype {dtype}")

0 commit comments

Comments
 (0)