Skip to content

Commit ae6d279

Browse files
authored
TST/CLN: Remove makeDataFrame (#56210)
* TST/CLN: Remove makeDataFrame * Simplify some frames
1 parent e973b42 commit ae6d279

22 files changed

+429
-88
lines changed

pandas/tests/frame/methods/test_set_index.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ def test_set_index(self, float_string_frame):
156156
df.set_index(idx[::2])
157157

158158
def test_set_index_names(self):
159-
df = tm.makeDataFrame()
159+
df = DataFrame(
160+
np.ones((10, 4)),
161+
columns=Index(list("ABCD"), dtype=object),
162+
index=Index([f"i-{i}" for i in range(10)], dtype=object),
163+
)
160164
df.index.name = "name"
161165

162166
assert df.set_index(df.index).index.names == ["name"]

pandas/tests/frame/test_arithmetic.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,10 @@ def test_strings_to_numbers_comparisons_raises(self, compare_operators_no_eq_ne)
15661566
f(df, 0)
15671567

15681568
def test_comparison_protected_from_errstate(self):
1569-
missing_df = tm.makeDataFrame()
1569+
missing_df = DataFrame(
1570+
np.ones((10, 4), dtype=np.float64),
1571+
columns=Index(list("ABCD"), dtype=object),
1572+
)
15701573
missing_df.loc[missing_df.index[0], "A"] = np.nan
15711574
with np.errstate(invalid="ignore"):
15721575
expected = missing_df.values < 0

pandas/tests/indexing/test_chaining_and_caching.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pandas as pd
1313
from pandas import (
1414
DataFrame,
15+
Index,
1516
Series,
1617
Timestamp,
1718
date_range,
@@ -627,7 +628,10 @@ def test_chained_getitem_with_lists(self):
627628
def test_cache_updating(self):
628629
# GH 4939, make sure to update the cache on setitem
629630

630-
df = tm.makeDataFrame()
631+
df = DataFrame(
632+
np.zeros((10, 4)),
633+
columns=Index(list("ABCD"), dtype=object),
634+
)
631635
df["A"] # cache series
632636
df.loc["Hello Friend"] = df.iloc[0]
633637
assert "Hello Friend" in df["A"].index

pandas/tests/io/excel/test_writers.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1234,15 +1234,23 @@ def test_freeze_panes(self, path):
12341234
tm.assert_frame_equal(result, expected)
12351235

12361236
def test_path_path_lib(self, engine, ext):
1237-
df = tm.makeDataFrame()
1237+
df = DataFrame(
1238+
1.1 * np.arange(120).reshape((30, 4)),
1239+
columns=Index(list("ABCD"), dtype=object),
1240+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
1241+
)
12381242
writer = partial(df.to_excel, engine=engine)
12391243

12401244
reader = partial(pd.read_excel, index_col=0)
12411245
result = tm.round_trip_pathlib(writer, reader, path=f"foo{ext}")
12421246
tm.assert_frame_equal(result, df)
12431247

12441248
def test_path_local_path(self, engine, ext):
1245-
df = tm.makeDataFrame()
1249+
df = DataFrame(
1250+
1.1 * np.arange(120).reshape((30, 4)),
1251+
columns=Index(list("ABCD"), dtype=object),
1252+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
1253+
)
12461254
writer = partial(df.to_excel, engine=engine)
12471255

12481256
reader = partial(pd.read_excel, index_col=0)

pandas/tests/io/formats/test_to_csv.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pandas as pd
1111
from pandas import (
1212
DataFrame,
13+
Index,
1314
compat,
1415
)
1516
import pandas._testing as tm
@@ -665,7 +666,7 @@ def test_na_rep_truncated(self):
665666
def test_to_csv_errors(self, errors):
666667
# GH 22610
667668
data = ["\ud800foo"]
668-
ser = pd.Series(data, index=pd.Index(data))
669+
ser = pd.Series(data, index=Index(data))
669670
with tm.ensure_clean("test.csv") as path:
670671
ser.to_csv(path, errors=errors)
671672
# No use in reading back the data as it is not the same anymore
@@ -679,7 +680,11 @@ def test_to_csv_binary_handle(self, mode):
679680
680681
GH 35058 and GH 19827
681682
"""
682-
df = tm.makeDataFrame()
683+
df = DataFrame(
684+
1.1 * np.arange(120).reshape((30, 4)),
685+
columns=Index(list("ABCD"), dtype=object),
686+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
687+
)
683688
with tm.ensure_clean() as path:
684689
with open(path, mode="w+b") as handle:
685690
df.to_csv(handle, mode=mode)
@@ -713,7 +718,11 @@ def test_to_csv_encoding_binary_handle(self, mode):
713718

714719
def test_to_csv_iterative_compression_name(compression):
715720
# GH 38714
716-
df = tm.makeDataFrame()
721+
df = DataFrame(
722+
1.1 * np.arange(120).reshape((30, 4)),
723+
columns=Index(list("ABCD"), dtype=object),
724+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
725+
)
717726
with tm.ensure_clean() as path:
718727
df.to_csv(path, compression=compression, chunksize=1)
719728
tm.assert_frame_equal(
@@ -723,7 +732,11 @@ def test_to_csv_iterative_compression_name(compression):
723732

724733
def test_to_csv_iterative_compression_buffer(compression):
725734
# GH 38714
726-
df = tm.makeDataFrame()
735+
df = DataFrame(
736+
1.1 * np.arange(120).reshape((30, 4)),
737+
columns=Index(list("ABCD"), dtype=object),
738+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
739+
)
727740
with io.BytesIO() as buffer:
728741
df.to_csv(buffer, compression=compression, chunksize=1)
729742
buffer.seek(0)

pandas/tests/io/parser/common/test_file_buffer_url.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from urllib.error import URLError
1212
import uuid
1313

14+
import numpy as np
1415
import pytest
1516

1617
from pandas.errors import (
@@ -19,7 +20,10 @@
1920
)
2021
import pandas.util._test_decorators as td
2122

22-
from pandas import DataFrame
23+
from pandas import (
24+
DataFrame,
25+
Index,
26+
)
2327
import pandas._testing as tm
2428

2529
pytestmark = pytest.mark.filterwarnings(
@@ -66,15 +70,23 @@ def test_local_file(all_parsers, csv_dir_path):
6670
@xfail_pyarrow # AssertionError: DataFrame.index are different
6771
def test_path_path_lib(all_parsers):
6872
parser = all_parsers
69-
df = tm.makeDataFrame()
73+
df = DataFrame(
74+
1.1 * np.arange(120).reshape((30, 4)),
75+
columns=Index(list("ABCD"), dtype=object),
76+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
77+
)
7078
result = tm.round_trip_pathlib(df.to_csv, lambda p: parser.read_csv(p, index_col=0))
7179
tm.assert_frame_equal(df, result)
7280

7381

7482
@xfail_pyarrow # AssertionError: DataFrame.index are different
7583
def test_path_local_path(all_parsers):
7684
parser = all_parsers
77-
df = tm.makeDataFrame()
85+
df = DataFrame(
86+
1.1 * np.arange(120).reshape((30, 4)),
87+
columns=Index(list("ABCD"), dtype=object),
88+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
89+
)
7890
result = tm.round_trip_localpath(
7991
df.to_csv, lambda p: parser.read_csv(p, index_col=0)
8092
)

pandas/tests/io/pytables/test_append.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pandas as pd
1212
from pandas import (
1313
DataFrame,
14+
Index,
1415
Series,
1516
_testing as tm,
1617
concat,
@@ -401,7 +402,7 @@ def check_col(key, name, size):
401402
{
402403
"A": [0.0, 1.0, 2.0, 3.0, 4.0],
403404
"B": [0.0, 1.0, 0.0, 1.0, 0.0],
404-
"C": pd.Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
405+
"C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object),
405406
"D": date_range("20130101", periods=5),
406407
}
407408
).set_index("C")
@@ -658,7 +659,11 @@ def test_append_hierarchical(tmp_path, setup_path, multiindex_dataframe_random_d
658659

659660
def test_append_misc(setup_path):
660661
with ensure_clean_store(setup_path) as store:
661-
df = tm.makeDataFrame()
662+
df = DataFrame(
663+
1.1 * np.arange(120).reshape((30, 4)),
664+
columns=Index(list("ABCD"), dtype=object),
665+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
666+
)
662667
store.append("df", df, chunksize=1)
663668
result = store.select("df")
664669
tm.assert_frame_equal(result, df)
@@ -671,7 +676,11 @@ def test_append_misc(setup_path):
671676
@pytest.mark.parametrize("chunksize", [10, 200, 1000])
672677
def test_append_misc_chunksize(setup_path, chunksize):
673678
# more chunksize in append tests
674-
df = tm.makeDataFrame()
679+
df = DataFrame(
680+
1.1 * np.arange(120).reshape((30, 4)),
681+
columns=Index(list("ABCD"), dtype=object),
682+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
683+
)
675684
df["string"] = "foo"
676685
df["float322"] = 1.0
677686
df["float322"] = df["float322"].astype("float32")
@@ -715,7 +724,11 @@ def test_append_raise(setup_path):
715724
# test append with invalid input to get good error messages
716725

717726
# list in column
718-
df = tm.makeDataFrame()
727+
df = DataFrame(
728+
1.1 * np.arange(120).reshape((30, 4)),
729+
columns=Index(list("ABCD"), dtype=object),
730+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
731+
)
719732
df["invalid"] = [["a"]] * len(df)
720733
assert df.dtypes["invalid"] == np.object_
721734
msg = re.escape(
@@ -732,7 +745,11 @@ def test_append_raise(setup_path):
732745
store.append("df", df)
733746

734747
# datetime with embedded nans as object
735-
df = tm.makeDataFrame()
748+
df = DataFrame(
749+
1.1 * np.arange(120).reshape((30, 4)),
750+
columns=Index(list("ABCD"), dtype=object),
751+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
752+
)
736753
s = Series(datetime.datetime(2001, 1, 2), index=df.index)
737754
s = s.astype(object)
738755
s[0:5] = np.nan
@@ -756,7 +773,11 @@ def test_append_raise(setup_path):
756773
store.append("df", Series(np.arange(10)))
757774

758775
# appending an incompatible table
759-
df = tm.makeDataFrame()
776+
df = DataFrame(
777+
1.1 * np.arange(120).reshape((30, 4)),
778+
columns=Index(list("ABCD"), dtype=object),
779+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
780+
)
760781
store.append("df", df)
761782

762783
df["foo"] = "foo"

pandas/tests/io/pytables/test_errors.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CategoricalIndex,
1010
DataFrame,
1111
HDFStore,
12+
Index,
1213
MultiIndex,
1314
_testing as tm,
1415
date_range,
@@ -25,7 +26,11 @@
2526

2627

2728
def test_pass_spec_to_storer(setup_path):
28-
df = tm.makeDataFrame()
29+
df = DataFrame(
30+
1.1 * np.arange(120).reshape((30, 4)),
31+
columns=Index(list("ABCD"), dtype=object),
32+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
33+
)
2934

3035
with ensure_clean_store(setup_path) as store:
3136
store.put("df", df)
@@ -60,14 +65,22 @@ def test_unimplemented_dtypes_table_columns(setup_path):
6065

6166
# currently not supported dtypes ####
6267
for n, f in dtypes:
63-
df = tm.makeDataFrame()
68+
df = DataFrame(
69+
1.1 * np.arange(120).reshape((30, 4)),
70+
columns=Index(list("ABCD"), dtype=object),
71+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
72+
)
6473
df[n] = f
6574
msg = re.escape(f"[{n}] is not implemented as a table column")
6675
with pytest.raises(TypeError, match=msg):
6776
store.append(f"df1_{n}", df)
6877

6978
# frame
70-
df = tm.makeDataFrame()
79+
df = DataFrame(
80+
1.1 * np.arange(120).reshape((30, 4)),
81+
columns=Index(list("ABCD"), dtype=object),
82+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
83+
)
7184
df["obj1"] = "foo"
7285
df["obj2"] = "bar"
7386
df["datetime1"] = datetime.date(2001, 1, 2)

pandas/tests/io/pytables/test_file_handling.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas import (
1818
DataFrame,
1919
HDFStore,
20+
Index,
2021
Series,
2122
_testing as tm,
2223
read_hdf,
@@ -145,7 +146,11 @@ def test_reopen_handle(tmp_path, setup_path):
145146

146147
def test_open_args(setup_path):
147148
with tm.ensure_clean(setup_path) as path:
148-
df = tm.makeDataFrame()
149+
df = DataFrame(
150+
1.1 * np.arange(120).reshape((30, 4)),
151+
columns=Index(list("ABCD"), dtype=object),
152+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
153+
)
149154

150155
# create an in memory store
151156
store = HDFStore(
@@ -172,7 +177,11 @@ def test_flush(setup_path):
172177

173178
def test_complibs_default_settings(tmp_path, setup_path):
174179
# GH15943
175-
df = tm.makeDataFrame()
180+
df = DataFrame(
181+
1.1 * np.arange(120).reshape((30, 4)),
182+
columns=Index(list("ABCD"), dtype=object),
183+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
184+
)
176185

177186
# Set complevel and check if complib is automatically set to
178187
# default value
@@ -211,7 +220,11 @@ def test_complibs_default_settings(tmp_path, setup_path):
211220

212221
def test_complibs_default_settings_override(tmp_path, setup_path):
213222
# Check if file-defaults can be overridden on a per table basis
214-
df = tm.makeDataFrame()
223+
df = DataFrame(
224+
1.1 * np.arange(120).reshape((30, 4)),
225+
columns=Index(list("ABCD"), dtype=object),
226+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
227+
)
215228
tmpfile = tmp_path / setup_path
216229
store = HDFStore(tmpfile)
217230
store.append("dfc", df, complevel=9, complib="blosc")
@@ -325,7 +338,11 @@ def test_multiple_open_close(tmp_path, setup_path):
325338

326339
path = tmp_path / setup_path
327340

328-
df = tm.makeDataFrame()
341+
df = DataFrame(
342+
1.1 * np.arange(120).reshape((30, 4)),
343+
columns=Index(list("ABCD"), dtype=object),
344+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
345+
)
329346
df.to_hdf(path, key="df", mode="w", format="table")
330347

331348
# single
@@ -402,7 +419,11 @@ def test_multiple_open_close(tmp_path, setup_path):
402419
# ops on a closed store
403420
path = tmp_path / setup_path
404421

405-
df = tm.makeDataFrame()
422+
df = DataFrame(
423+
1.1 * np.arange(120).reshape((30, 4)),
424+
columns=Index(list("ABCD"), dtype=object),
425+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
426+
)
406427
df.to_hdf(path, key="df", mode="w", format="table")
407428

408429
store = HDFStore(path)

pandas/tests/io/pytables/test_keys.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import numpy as np
12
import pytest
23

34
from pandas import (
45
DataFrame,
56
HDFStore,
7+
Index,
68
Series,
79
_testing as tm,
810
)
@@ -20,7 +22,11 @@ def test_keys(setup_path):
2022
store["b"] = Series(
2123
range(10), dtype="float64", index=[f"i_{i}" for i in range(10)]
2224
)
23-
store["c"] = tm.makeDataFrame()
25+
store["c"] = DataFrame(
26+
1.1 * np.arange(120).reshape((30, 4)),
27+
columns=Index(list("ABCD"), dtype=object),
28+
index=Index([f"i-{i}" for i in range(30)], dtype=object),
29+
)
2430

2531
assert len(store) == 3
2632
expected = {"/a", "/b", "/c"}

0 commit comments

Comments
 (0)