Skip to content

Commit 281d650

Browse files
authored
CLN/TST: Remove tm.makeUnicodeIndex (pandas-dev#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

+1-1
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

+7-13
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

-12
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

-1
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

+2-2
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

+1-1
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

+13-11
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

+1-2
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

-3
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

+25-26
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 = [

pandas/tests/io/pytables/test_put.py

-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ def test_put_mixed_type(setup_path):
227227
["fixed", tm.makeDateIndex],
228228
["table", tm.makePeriodIndex], # GH#7796
229229
["fixed", tm.makePeriodIndex],
230-
["table", tm.makeUnicodeIndex],
231-
["fixed", tm.makeUnicodeIndex],
232230
],
233231
)
234232
def test_store_index_types(setup_path, format, index):

pandas/tests/io/pytables/test_store.py

-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ def test_to_hdf_with_object_column_names(setup_path):
993993
types_should_run = [
994994
tm.makeStringIndex,
995995
tm.makeCategoricalIndex,
996-
tm.makeUnicodeIndex,
997996
]
998997

999998
for index in types_should_fail:

pandas/tests/io/test_fsspec.py

+18-15
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
import pandas._testing as tm
1919
from pandas.util import _test_decorators as td
2020

21-
df1 = DataFrame(
22-
{
23-
"int": [1, 3],
24-
"float": [2.0, np.nan],
25-
"str": ["t", "s"],
26-
"dt": date_range("2018-06-18", periods=2),
27-
}
28-
)
29-
text = str(df1.to_csv(index=False)).encode()
21+
22+
@pytest.fixture
23+
def df1():
24+
return DataFrame(
25+
{
26+
"int": [1, 3],
27+
"float": [2.0, np.nan],
28+
"str": ["t", "s"],
29+
"dt": date_range("2018-06-18", periods=2),
30+
}
31+
)
3032

3133

3234
@pytest.fixture
@@ -38,7 +40,8 @@ def cleared_fs():
3840
memfs.store.clear()
3941

4042

41-
def test_read_csv(cleared_fs):
43+
def test_read_csv(cleared_fs, df1):
44+
text = str(df1.to_csv(index=False)).encode()
4245
with cleared_fs.open("test/test.csv", "wb") as w:
4346
w.write(text)
4447
df2 = read_csv("memory://test/test.csv", parse_dates=["dt"])
@@ -63,7 +66,7 @@ def test_reasonable_error(monkeypatch, cleared_fs):
6366
read_csv("couldexist://test/test.csv")
6467

6568

66-
def test_to_csv(cleared_fs):
69+
def test_to_csv(cleared_fs, df1):
6770
df1.to_csv("memory://test/test.csv", index=True)
6871

6972
df2 = read_csv("memory://test/test.csv", parse_dates=["dt"], index_col=0)
@@ -72,7 +75,7 @@ def test_to_csv(cleared_fs):
7275

7376

7477
@pytest.mark.parametrize("ext", ["xls", "xlsx"])
75-
def test_to_excel(cleared_fs, ext):
78+
def test_to_excel(cleared_fs, ext, df1):
7679
if ext == "xls":
7780
pytest.importorskip("xlwt")
7881
else:
@@ -87,7 +90,7 @@ def test_to_excel(cleared_fs, ext):
8790

8891

8992
@pytest.mark.parametrize("binary_mode", [False, True])
90-
def test_to_csv_fsspec_object(cleared_fs, binary_mode):
93+
def test_to_csv_fsspec_object(cleared_fs, binary_mode, df1):
9194
fsspec = pytest.importorskip("fsspec")
9295

9396
path = "memory://test/test.csv"
@@ -151,7 +154,7 @@ def test_excel_options(fsspectest, extension):
151154

152155

153156
@td.skip_if_no("fastparquet")
154-
def test_to_parquet_new_file(cleared_fs):
157+
def test_to_parquet_new_file(cleared_fs, df1):
155158
"""Regression test for writing to a not-yet-existent GCS Parquet file."""
156159
df1.to_parquet(
157160
"memory://test/test.csv", index=True, engine="fastparquet", compression=None
@@ -228,7 +231,7 @@ def test_s3_protocols(s3_resource, tips_file, protocol, s3so):
228231
@td.skip_array_manager_not_yet_implemented # TODO(ArrayManager) fastparquet
229232
@td.skip_if_no("s3fs")
230233
@td.skip_if_no("fastparquet")
231-
def test_s3_parquet(s3_resource, s3so):
234+
def test_s3_parquet(s3_resource, s3so, df1):
232235
fn = "s3://pandas-test/test.parquet"
233236
df1.to_parquet(
234237
fn, index=False, engine="fastparquet", compression=None, storage_options=s3so

pandas/tests/reductions/test_reductions.py

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def get_objs():
3838
tm.makeDateIndex(10, name="a").tz_localize(tz="US/Eastern"),
3939
tm.makePeriodIndex(10, name="a"),
4040
tm.makeStringIndex(10, name="a"),
41-
tm.makeUnicodeIndex(10, name="a"),
4241
]
4342

4443
arr = np.random.randn(10)

pandas/tests/resample/test_time_grouper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def f(df):
8181
"name, func",
8282
[
8383
("Int64Index", tm.makeIntIndex),
84-
("Index", tm.makeUnicodeIndex),
84+
("Index", tm.makeStringIndex),
8585
("Float64Index", tm.makeFloatIndex),
8686
("MultiIndex", lambda m: tm.makeCustomIndex(m, 2)),
8787
],

0 commit comments

Comments
 (0)