Skip to content

Commit 94befe6

Browse files
committed
rremove copy
1 parent 4d0fa2a commit 94befe6

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

pandas/tests/groupby/test_transform.py

+25-30
Original file line numberDiff line numberDiff line change
@@ -356,54 +356,49 @@ def test_transform_transformation_func(transformation_func):
356356
tm.assert_frame_equal(result, expected)
357357

358358

359-
def test_groupby_corrwith(transformation_func, df_for_transformation_func):
359+
def test_groupby_corrwith(df_for_transformation_func):
360360

361361
# GH 27905
362-
df = df_for_transformation_func.copy()
362+
df = df_for_transformation_func
363363
g = df.groupby("A")
364364

365-
if transformation_func == "corrwith":
366-
op = lambda x: getattr(x, transformation_func)(df)
367-
result = op(g)
368-
expected = pd.DataFrame(dict(B=[1, np.nan, np.nan], A=[np.nan] * 3))
369-
expected.index = pd.Index([121, 231, 676], name="A")
370-
tm.assert_frame_equal(result, expected)
365+
op = lambda x: getattr(x, "corrwith")(df)
366+
result = op(g)
367+
expected = pd.DataFrame(dict(B=[1, np.nan, np.nan], A=[np.nan] * 3))
368+
expected.index = pd.Index([121, 231, 676], name="A")
369+
tm.assert_frame_equal(result, expected)
371370

372371

373-
def test_groupby_transform_nan(transformation_func, df_for_transformation_func):
372+
def test_groupby_transform_nan(df_for_transformation_func):
374373

375374
# GH 27905
376-
df = df_for_transformation_func.copy()
375+
df = df_for_transformation_func
377376
g = df.groupby("A")
378377

379-
if transformation_func == "fillna":
380-
381-
df["B"] = [1, np.nan, np.nan, 3, np.nan, 3, 4]
382-
result = g.transform(transformation_func, value=1)
383-
expected = pd.DataFrame({"B": [1.0, 1.0, 1.0, 3.0, 1.0, 3.0, 4.0]})
384-
tm.assert_frame_equal(result, expected)
385-
op = lambda x: getattr(x, transformation_func)(1)
386-
result = op(g)
387-
tm.assert_frame_equal(result, expected)
378+
df["B"] = [1, np.nan, np.nan, 3, np.nan, 3, 4]
379+
result = g.transform("fillna", value=1)
380+
expected = pd.DataFrame({"B": [1.0, 1.0, 1.0, 3.0, 1.0, 3.0, 4.0]})
381+
tm.assert_frame_equal(result, expected)
382+
op = lambda x: getattr(x, "fillna")(1)
383+
result = op(g)
384+
tm.assert_frame_equal(result, expected)
388385

389386

390-
def test_groupby_tshift(transformation_func, df_for_transformation_func):
387+
def test_groupby_tshift(df_for_transformation_func):
391388

392389
# GH 27905
393-
df = df_for_transformation_func.copy()
390+
df = df_for_transformation_func
394391
dt_periods = pd.date_range("2013-11-03", periods=7, freq="D")
395392
df["C"] = dt_periods
396393
g = df.set_index("C").groupby("A")
397394

398-
if transformation_func == "tshift":
399-
400-
op = lambda x: getattr(x, transformation_func)(2, "D")
401-
result = op(g)
402-
df["C"] = dt_periods + dt_periods.freq * 2
403-
expected = df
404-
tm.assert_frame_equal(
405-
result.reset_index().reindex(columns=["A", "B", "C"]), expected
406-
)
395+
op = lambda x: getattr(x, "tshift")(2, "D")
396+
result = op(g)
397+
df["C"] = dt_periods + dt_periods.freq * 2
398+
expected = df
399+
tm.assert_frame_equal(
400+
result.reset_index().reindex(columns=["A", "B", "C"]), expected
401+
)
407402

408403

409404
def test_check_original_and_transformed_index(transformation_func):

0 commit comments

Comments
 (0)