Skip to content

Commit 423e7b9

Browse files
Backport PR #55460 on branch 2.1.x (COMPAT: Update old numpy aliases) (#55463)
Backport PR #55460: COMPAT: Update old numpy aliases Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 7486550 commit 423e7b9

File tree

8 files changed

+14
-16
lines changed

8 files changed

+14
-16
lines changed

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ def __init__(self) -> None:
977977
# with a label, but the underlying variable is -127 to 100
978978
# we're going to drop the label and cast to int
979979
self.DTYPE_MAP = dict(
980-
list(zip(range(1, 245), [np.dtype("a" + str(i)) for i in range(1, 245)]))
980+
[(i, np.dtype(f"S{i}")) for i in range(1, 245)]
981981
+ [
982982
(251, np.dtype(np.int8)),
983983
(252, np.dtype(np.int16)),

pandas/tests/frame/constructors/test_from_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_frame_from_records_utc(self):
281281

282282
def test_from_records_to_records(self):
283283
# from numpy documentation
284-
arr = np.zeros((2,), dtype=("i4,f4,a10"))
284+
arr = np.zeros((2,), dtype=("i4,f4,S10"))
285285
arr[:] = [(1, 2.0, "Hello"), (2, 3.0, "World")]
286286

287287
DataFrame.from_records(arr)

pandas/tests/frame/methods/test_select_dtypes.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ def test_select_dtypes_datetime_with_tz(self):
339339
expected = df3.reindex(columns=[])
340340
tm.assert_frame_equal(result, expected)
341341

342-
@pytest.mark.parametrize(
343-
"dtype", [str, "str", np.bytes_, "S1", "unicode", np.str_, "U1"]
344-
)
342+
@pytest.mark.parametrize("dtype", [str, "str", np.bytes_, "S1", np.str_, "U1"])
345343
@pytest.mark.parametrize("arg", ["include", "exclude"])
346344
def test_select_dtypes_str_raises(self, dtype, arg):
347345
df = DataFrame(

pandas/tests/frame/methods/test_to_records.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def test_to_records_with_categorical(self):
253253
),
254254
# Pass in a dtype instance.
255255
(
256-
{"column_dtypes": np.dtype("unicode")},
256+
{"column_dtypes": np.dtype(np.str_)},
257257
np.rec.array(
258258
[("0", "1", "0.2", "a"), ("1", "2", "1.5", "bc")],
259259
dtype=[

pandas/tests/indexes/base_class/test_setops.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ def test_symmetric_difference(self):
182182
"intersection",
183183
np.array(
184184
[(1, "A"), (2, "A"), (1, "B"), (2, "B")],
185-
dtype=[("num", int), ("let", "a1")],
185+
dtype=[("num", int), ("let", "S1")],
186186
),
187187
False,
188188
),
189189
(
190190
"intersection",
191191
np.array(
192192
[(1, "A"), (1, "B"), (2, "A"), (2, "B")],
193-
dtype=[("num", int), ("let", "a1")],
193+
dtype=[("num", int), ("let", "S1")],
194194
),
195195
None,
196196
),
197197
(
198198
"union",
199199
np.array(
200200
[(1, "A"), (1, "B"), (1, "C"), (2, "A"), (2, "B"), (2, "C")],
201-
dtype=[("num", int), ("let", "a1")],
201+
dtype=[("num", int), ("let", "S1")],
202202
),
203203
None,
204204
),
@@ -208,13 +208,13 @@ def test_tuple_union_bug(self, method, expected, sort):
208208
index1 = Index(
209209
np.array(
210210
[(1, "A"), (2, "A"), (1, "B"), (2, "B")],
211-
dtype=[("num", int), ("let", "a1")],
211+
dtype=[("num", int), ("let", "S1")],
212212
)
213213
)
214214
index2 = Index(
215215
np.array(
216216
[(1, "A"), (2, "A"), (1, "B"), (2, "B"), (1, "C"), (2, "C")],
217-
dtype=[("num", int), ("let", "a1")],
217+
dtype=[("num", int), ("let", "S1")],
218218
)
219219
)
220220

pandas/tests/io/json/test_pandas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def test_blocks_compat_GH9037(self):
599599
)
600600

601601
# JSON deserialisation always creates unicode strings
602-
df_mixed.columns = df_mixed.columns.astype("unicode")
602+
df_mixed.columns = df_mixed.columns.astype(np.str_)
603603
data = StringIO(df_mixed.to_json(orient="split"))
604604
df_roundtrip = read_json(data, orient="split")
605605
tm.assert_frame_equal(

pandas/tests/reshape/concat/test_append.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ def test_append_length0_frame(self, sort):
9191
tm.assert_frame_equal(df5, expected)
9292

9393
def test_append_records(self):
94-
arr1 = np.zeros((2,), dtype=("i4,f4,a10"))
94+
arr1 = np.zeros((2,), dtype=("i4,f4,S10"))
9595
arr1[:] = [(1, 2.0, "Hello"), (2, 3.0, "World")]
9696

97-
arr2 = np.zeros((3,), dtype=("i4,f4,a10"))
97+
arr2 = np.zeros((3,), dtype=("i4,f4,S10"))
9898
arr2[:] = [(3, 4.0, "foo"), (5, 6.0, "bar"), (7.0, 8.0, "baz")]
9999

100100
df1 = DataFrame(arr1)

pandas/tests/series/methods/test_astype.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,12 @@ def test_astype_unicode(self):
403403
# bytes with obj.decode() instead of str(obj)
404404
item = "野菜食べないとやばい"
405405
ser = Series([item.encode()])
406-
result = ser.astype("unicode")
406+
result = ser.astype(np.str_)
407407
expected = Series([item])
408408
tm.assert_series_equal(result, expected)
409409

410410
for ser in test_series:
411-
res = ser.astype("unicode")
411+
res = ser.astype(np.str_)
412412
expec = ser.map(str)
413413
tm.assert_series_equal(res, expec)
414414

0 commit comments

Comments
 (0)