Skip to content

Commit

Permalink
TST/CLN: Remove makeMixedDataFrame and getMixedTypeDict (#56202)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored Nov 27, 2023
1 parent a38ecd5 commit 6f080bd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 29 deletions.
19 changes: 0 additions & 19 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,23 +482,6 @@ def makeDataFrame() -> DataFrame:
return DataFrame(data)


def getMixedTypeDict():
index = Index(["a", "b", "c", "d", "e"])

data = {
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
"D": bdate_range("1/1/2009", periods=5),
}

return index, data


def makeMixedDataFrame() -> DataFrame:
return DataFrame(getMixedTypeDict()[1])


def makeCustomIndex(
nentries,
nlevels,
Expand Down Expand Up @@ -1026,7 +1009,6 @@ def shares_memory(left, right) -> bool:
"get_dtype",
"getitem",
"get_locales",
"getMixedTypeDict",
"get_finest_unit",
"get_obj",
"get_op_from_name",
Expand All @@ -1042,7 +1024,6 @@ def shares_memory(left, right) -> bool:
"makeDateIndex",
"makeFloatIndex",
"makeIntIndex",
"makeMixedDataFrame",
"makeNumericIndex",
"makeObjectSeries",
"makePeriodIndex",
Expand Down
14 changes: 12 additions & 2 deletions pandas/tests/frame/methods/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
from pandas import (
DataFrame,
DatetimeIndex,
Index,
IntervalIndex,
Series,
Timestamp,
bdate_range,
date_range,
timedelta_range,
)
Expand Down Expand Up @@ -108,9 +110,17 @@ def test_transpose_float(self, float_frame):
else:
assert value == frame[col][idx]

def test_transpose_mixed(self):
# mixed type
index, data = tm.getMixedTypeDict()
mixed = DataFrame(data, index=index)
mixed = DataFrame(
{
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
"D": bdate_range("1/1/2009", periods=5),
},
index=Index(["a", "b", "c", "d", "e"], dtype=object),
)

mixed_T = mixed.T
for col, s in mixed_T.items():
Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/io/pytables/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,14 @@ def check_col(key, name, size):
store.append("df_new", df_new)

# min_itemsize on Series index (GH 11412)
df = tm.makeMixedDataFrame().set_index("C")
df = DataFrame(
{
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": pd.Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
"D": date_range("20130101", periods=5),
}
).set_index("C")
store.append("ss", df["B"], min_itemsize={"index": 4})
tm.assert_series_equal(store.select("ss"), df["B"])

Expand Down
9 changes: 8 additions & 1 deletion pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,14 @@ def test_to_hdf_with_min_itemsize(tmp_path, setup_path):
path = tmp_path / setup_path

# min_itemsize in index with to_hdf (GH 10381)
df = tm.makeMixedDataFrame().set_index("C")
df = DataFrame(
{
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
"D": date_range("20130101", periods=5),
}
).set_index("C")
df.to_hdf(path, key="ss3", format="table", min_itemsize={"index": 6})
# just make sure there is a longer string:
df2 = df.copy().reset_index().assign(C="longer").set_index("C")
Expand Down
10 changes: 8 additions & 2 deletions pandas/tests/reshape/merge/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MultiIndex,
Series,
Timestamp,
bdate_range,
concat,
merge,
)
Expand Down Expand Up @@ -57,8 +58,13 @@ def df2(self):

@pytest.fixture
def target_source(self):
index, data = tm.getMixedTypeDict()
target = DataFrame(data, index=index)
data = {
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
"D": bdate_range("1/1/2009", periods=5),
}
target = DataFrame(data, index=Index(["a", "b", "c", "d", "e"], dtype=object))

# Join on string value

Expand Down
18 changes: 16 additions & 2 deletions pandas/tests/series/methods/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Index,
MultiIndex,
Series,
bdate_range,
isna,
timedelta_range,
)
Expand Down Expand Up @@ -154,8 +155,13 @@ def test_list_raises(string_series):
string_series.map([lambda x: x])


def test_map(datetime_series):
index, data = tm.getMixedTypeDict()
def test_map():
data = {
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": ["foo1", "foo2", "foo3", "foo4", "foo5"],
"D": bdate_range("1/1/2009", periods=5),
}

source = Series(data["B"], index=data["C"])
target = Series(data["C"][:4], index=data["D"][:4])
Expand All @@ -171,10 +177,14 @@ def test_map(datetime_series):
for k, v in merged.items():
assert v == source[target[k]]


def test_map_datetime(datetime_series):
# function
result = datetime_series.map(lambda x: x * 2)
tm.assert_series_equal(result, datetime_series * 2)


def test_map_category():
# GH 10324
a = Series([1, 2, 3, 4])
b = Series(["even", "odd", "even", "odd"], dtype="category")
Expand All @@ -185,6 +195,8 @@ def test_map(datetime_series):
exp = Series(["odd", "even", "odd", np.nan])
tm.assert_series_equal(a.map(c), exp)


def test_map_category_numeric():
a = Series(["a", "b", "c", "d"])
b = Series([1, 2, 3, 4], index=pd.CategoricalIndex(["b", "c", "d", "e"]))
c = Series([1, 2, 3, 4], index=Index(["b", "c", "d", "e"]))
Expand All @@ -194,6 +206,8 @@ def test_map(datetime_series):
exp = Series([np.nan, 1, 2, 3])
tm.assert_series_equal(a.map(c), exp)


def test_map_category_string():
a = Series(["a", "b", "c", "d"])
b = Series(
["B", "C", "D", "E"],
Expand Down
18 changes: 16 additions & 2 deletions pandas/tests/util/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ def test_multiindex_objects():
DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3]}),
DataFrame(),
DataFrame(np.full((10, 4), np.nan)),
tm.makeMixedDataFrame(),
DataFrame(
{
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
"D": pd.date_range("20130101", periods=5),
}
),
tm.makeTimeDataFrame(),
tm.makeTimeSeries(),
Series(tm.makePeriodIndex()),
Expand All @@ -162,7 +169,14 @@ def test_hash_pandas_object(obj, index):
Series([True, False, True]),
DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3]}),
DataFrame(np.full((10, 4), np.nan)),
tm.makeMixedDataFrame(),
DataFrame(
{
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
"C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
"D": pd.date_range("20130101", periods=5),
}
),
tm.makeTimeDataFrame(),
tm.makeTimeSeries(),
Series(tm.makePeriodIndex()),
Expand Down

0 comments on commit 6f080bd

Please sign in to comment.