Skip to content

Commit 281d650

Browse files
authored
CLN/TST: Remove tm.makeUnicodeIndex (#47050)
1 parent e068f4c commit 281d650

File tree

17 files changed

+71
-96
lines changed

17 files changed

+71
-96
lines changed

asv_bench/benchmarks/strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def time_get_dummies(self, dtype):
268268

269269
class Encode:
270270
def setup(self):
271-
self.ser = Series(tm.makeUnicodeIndex())
271+
self.ser = Series(tm.makeStringIndex())
272272

273273
def time_encode_decode(self):
274274
self.ser.str.encode("utf-8").str.decode("utf-8")

pandas/_testing/__init__.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
randbool,
6363
rands,
6464
rands_array,
65-
randu_array,
6665
)
6766
from pandas._testing._warnings import ( # noqa:F401
6867
assert_produces_warning,
@@ -305,10 +304,6 @@ def makeStringIndex(k=10, name=None):
305304
return Index(rands_array(nchars=10, size=k), name=name)
306305

307306

308-
def makeUnicodeIndex(k=10, name=None):
309-
return Index(randu_array(nchars=10, size=k), name=name)
310-
311-
312307
def makeCategoricalIndex(k=10, n=3, name=None, **kwargs):
313308
"""make a length k index or n categories"""
314309
x = rands_array(nchars=4, size=n, replace=False)
@@ -521,10 +516,10 @@ def makeCustomIndex(
521516
label will repeated at the corresponding level, you can specify just
522517
the first few, the rest will use the default ndupe_l of 1.
523518
len(ndupe_l) <= nlevels.
524-
idx_type - "i"/"f"/"s"/"u"/"dt"/"p"/"td".
519+
idx_type - "i"/"f"/"s"/"dt"/"p"/"td".
525520
If idx_type is not None, `idx_nlevels` must be 1.
526521
"i"/"f" creates an integer/float index,
527-
"s"/"u" creates a string/unicode index
522+
"s" creates a string
528523
"dt" create a datetime index.
529524
"td" create a datetime index.
530525
@@ -554,7 +549,6 @@ def makeCustomIndex(
554549
"i": makeIntIndex,
555550
"f": makeFloatIndex,
556551
"s": makeStringIndex,
557-
"u": makeUnicodeIndex,
558552
"dt": makeDateIndex,
559553
"td": makeTimedeltaIndex,
560554
"p": makePeriodIndex,
@@ -569,7 +563,7 @@ def makeCustomIndex(
569563
elif idx_type is not None:
570564
raise ValueError(
571565
f"{repr(idx_type)} is not a legal value for `idx_type`, "
572-
"use 'i'/'f'/'s'/'u'/'dt'/'p'/'td'."
566+
"use 'i'/'f'/'s'/'dt'/'p'/'td'."
573567
)
574568

575569
if len(ndupe_l) < nlevels:
@@ -651,10 +645,10 @@ def makeCustomDataframe(
651645
nrows/ncol, the last label might have lower multiplicity.
652646
dtype - passed to the DataFrame constructor as is, in case you wish to
653647
have more control in conjunction with a custom `data_gen_f`
654-
r_idx_type, c_idx_type - "i"/"f"/"s"/"u"/"dt"/"td".
648+
r_idx_type, c_idx_type - "i"/"f"/"s"/"dt"/"td".
655649
If idx_type is not None, `idx_nlevels` must be 1.
656650
"i"/"f" creates an integer/float index,
657-
"s"/"u" creates a string/unicode index
651+
"s" creates a string index
658652
"dt" create a datetime index.
659653
"td" create a timedelta index.
660654
@@ -689,10 +683,10 @@ def makeCustomDataframe(
689683
assert c_idx_nlevels > 0
690684
assert r_idx_nlevels > 0
691685
assert r_idx_type is None or (
692-
r_idx_type in ("i", "f", "s", "u", "dt", "p", "td") and r_idx_nlevels == 1
686+
r_idx_type in ("i", "f", "s", "dt", "p", "td") and r_idx_nlevels == 1
693687
)
694688
assert c_idx_type is None or (
695-
c_idx_type in ("i", "f", "s", "u", "dt", "p", "td") and c_idx_nlevels == 1
689+
c_idx_type in ("i", "f", "s", "dt", "p", "td") and c_idx_nlevels == 1
696690
)
697691

698692
columns = makeCustomIndex(

pandas/_testing/_random.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,6 @@ def rands_array(nchars, size, dtype="O", replace=True):
2626
return retval.astype(dtype)
2727

2828

29-
def randu_array(nchars, size, dtype="O"):
30-
"""
31-
Generate an array of unicode strings.
32-
"""
33-
retval = (
34-
np.random.choice(RANDU_CHARS, size=nchars * np.prod(size))
35-
.view((np.unicode_, nchars))
36-
.reshape(size)
37-
)
38-
return retval.astype(dtype)
39-
40-
4129
def rands(nchars):
4230
"""
4331
Generate one random byte string.

pandas/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ def _create_mi_with_dt64tz_level():
543543

544544

545545
indices_dict = {
546-
"unicode": tm.makeUnicodeIndex(100),
547546
"string": tm.makeStringIndex(100),
548547
"datetime": tm.makeDateIndex(100),
549548
"datetime-tz": tm.makeDateIndex(100, tz="US/Pacific"),

pandas/tests/computation/test_eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def should_warn(*args):
730730

731731
class TestAlignment:
732732

733-
index_types = ["i", "u", "dt"]
733+
index_types = ["i", "s", "dt"]
734734
lhs_index_types = index_types + ["s"] # 'p'
735735

736736
def test_align_nested_unary_op(self, engine, parser):
@@ -829,7 +829,7 @@ def test_basic_frame_series_alignment(
829829
@pytest.mark.parametrize("index_name", ["index", "columns"])
830830
@pytest.mark.parametrize(
831831
"r_idx_type, c_idx_type",
832-
list(product(["i", "u", "s"], ["i", "u", "s"])) + [("dt", "dt")],
832+
list(product(["i", "s"], ["i", "s"])) + [("dt", "dt")],
833833
)
834834
@pytest.mark.filterwarnings("ignore::RuntimeWarning")
835835
def test_basic_series_frame_alignment(

pandas/tests/frame/methods/test_to_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_to_csv_nrows(self, nrows):
346346
"nrows", [2, 10, 99, 100, 101, 102, 198, 199, 200, 201, 202, 249, 250, 251]
347347
)
348348
@pytest.mark.parametrize(
349-
"r_idx_type, c_idx_type", [("i", "i"), ("s", "s"), ("u", "dt"), ("p", "p")]
349+
"r_idx_type, c_idx_type", [("i", "i"), ("s", "s"), ("s", "dt"), ("p", "p")]
350350
)
351351
@pytest.mark.parametrize("ncols", [1, 2, 3, 4])
352352
def test_to_csv_idx_types(self, nrows, r_idx_type, c_idx_type, ncols):

pandas/tests/groupby/test_grouping.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,26 @@ def test_indices_grouped_by_tuple_with_lambda(self):
150150

151151

152152
class TestGrouping:
153-
def test_grouper_index_types(self):
154-
# related GH5375
155-
# groupby misbehaving when using a Floatlike index
156-
df = DataFrame(np.arange(10).reshape(5, 2), columns=list("AB"))
157-
for index in [
153+
@pytest.mark.parametrize(
154+
"index",
155+
[
158156
tm.makeFloatIndex,
159157
tm.makeStringIndex,
160-
tm.makeUnicodeIndex,
161158
tm.makeIntIndex,
162159
tm.makeDateIndex,
163160
tm.makePeriodIndex,
164-
]:
161+
],
162+
)
163+
def test_grouper_index_types(self, index):
164+
# related GH5375
165+
# groupby misbehaving when using a Floatlike index
166+
df = DataFrame(np.arange(10).reshape(5, 2), columns=list("AB"))
165167

166-
df.index = index(len(df))
167-
df.groupby(list("abcde"), group_keys=False).apply(lambda x: x)
168+
df.index = index(len(df))
169+
df.groupby(list("abcde"), group_keys=False).apply(lambda x: x)
168170

169-
df.index = list(reversed(df.index.tolist()))
170-
df.groupby(list("abcde"), group_keys=False).apply(lambda x: x)
171+
df.index = list(reversed(df.index.tolist()))
172+
df.groupby(list("abcde"), group_keys=False).apply(lambda x: x)
171173

172174
def test_grouper_multilevel_freq(self):
173175

pandas/tests/indexes/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ def test_view_with_args(self, index):
318318
@pytest.mark.parametrize(
319319
"index",
320320
[
321-
"unicode",
322321
"string",
323322
pytest.param("categorical", marks=pytest.mark.xfail(reason="gh-25464")),
324323
"bool-object",
@@ -927,7 +926,7 @@ def test_slice_keep_name(self):
927926

928927
@pytest.mark.parametrize(
929928
"index",
930-
["unicode", "string", "datetime", "int", "uint", "float"],
929+
["string", "datetime", "int", "uint", "float"],
931930
indirect=True,
932931
)
933932
def test_join_self(self, index, join_type):

pandas/tests/indexing/test_floats.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def check(self, result, original, indexer, getitem):
4545
"index_func",
4646
[
4747
tm.makeStringIndex,
48-
tm.makeUnicodeIndex,
4948
tm.makeCategoricalIndex,
5049
tm.makeDateIndex,
5150
tm.makeTimedeltaIndex,
@@ -83,7 +82,6 @@ def test_scalar_non_numeric(self, index_func, frame_or_series, indexer_sl):
8382
"index_func",
8483
[
8584
tm.makeStringIndex,
86-
tm.makeUnicodeIndex,
8785
tm.makeCategoricalIndex,
8886
tm.makeDateIndex,
8987
tm.makeTimedeltaIndex,
@@ -220,7 +218,6 @@ def test_scalar_float(self, frame_or_series):
220218
"index_func",
221219
[
222220
tm.makeStringIndex,
223-
tm.makeUnicodeIndex,
224221
tm.makeDateIndex,
225222
tm.makeTimedeltaIndex,
226223
tm.makePeriodIndex,

pandas/tests/io/formats/test_format.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -950,36 +950,35 @@ def test_to_string_with_column_specific_col_space(self):
950950
result = df.to_string(col_space=[10, 11, 12])
951951
assert len(result.split("\n")[1]) == (3 + 1 + 10 + 11 + 12)
952952

953-
def test_to_string_truncate_indices(self):
954-
for index in [
953+
@pytest.mark.parametrize(
954+
"index",
955+
[
955956
tm.makeStringIndex,
956-
tm.makeUnicodeIndex,
957957
tm.makeIntIndex,
958958
tm.makeDateIndex,
959959
tm.makePeriodIndex,
960-
]:
961-
for column in [tm.makeStringIndex]:
962-
for h in [10, 20]:
963-
for w in [10, 20]:
964-
with option_context("display.expand_frame_repr", False):
965-
df = DataFrame(index=index(h), columns=column(w))
966-
with option_context("display.max_rows", 15):
967-
if h == 20:
968-
assert has_vertically_truncated_repr(df)
969-
else:
970-
assert not has_vertically_truncated_repr(df)
971-
with option_context("display.max_columns", 15):
972-
if w == 20:
973-
assert has_horizontally_truncated_repr(df)
974-
else:
975-
assert not (has_horizontally_truncated_repr(df))
976-
with option_context(
977-
"display.max_rows", 15, "display.max_columns", 15
978-
):
979-
if h == 20 and w == 20:
980-
assert has_doubly_truncated_repr(df)
981-
else:
982-
assert not has_doubly_truncated_repr(df)
960+
],
961+
)
962+
@pytest.mark.parametrize("h", [10, 20])
963+
@pytest.mark.parametrize("w", [10, 20])
964+
def test_to_string_truncate_indices(self, index, h, w):
965+
with option_context("display.expand_frame_repr", False):
966+
df = DataFrame(index=index(h), columns=tm.makeStringIndex(w))
967+
with option_context("display.max_rows", 15):
968+
if h == 20:
969+
assert has_vertically_truncated_repr(df)
970+
else:
971+
assert not has_vertically_truncated_repr(df)
972+
with option_context("display.max_columns", 15):
973+
if w == 20:
974+
assert has_horizontally_truncated_repr(df)
975+
else:
976+
assert not (has_horizontally_truncated_repr(df))
977+
with option_context("display.max_rows", 15, "display.max_columns", 15):
978+
if h == 20 and w == 20:
979+
assert has_doubly_truncated_repr(df)
980+
else:
981+
assert not has_doubly_truncated_repr(df)
983982

984983
def test_to_string_truncate_multilevel(self):
985984
arrays = [

0 commit comments

Comments
 (0)