DEPR: Deprecate returning a DataFrame in SeriesApply.apply_standard (… · pandas-dev/pandas@fe415f5 (original) (raw)

`@@ -361,11 +361,18 @@ def test_agg_apply_evaluate_lambdas_the_same(string_series):

`

361

361

`def test_with_nested_series(datetime_series):

`

362

362

`# GH 2316

`

363

363

`# .agg with a reducer and a transform, what to do

`

364

``

`-

result = datetime_series.apply(lambda x: Series([x, x**2], index=["x", "x^2"]))

`

``

364

`+

msg = "Returning a DataFrame from Series.apply when the supplied function"

`

``

365

`+

with tm.assert_produces_warning(FutureWarning, match=msg):

`

``

366

`+

GH52123

`

``

367

`+

result = datetime_series.apply(

`

``

368

`+

lambda x: Series([x, x**2], index=["x", "x^2"])

`

``

369

`+

)

`

365

370

`expected = DataFrame({"x": datetime_series, "x^2": datetime_series**2})

`

366

371

`tm.assert_frame_equal(result, expected)

`

367

372

``

368

``

`-

result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"]))

`

``

373

`+

with tm.assert_produces_warning(FutureWarning, match=msg):

`

``

374

`+

GH52123

`

``

375

`+

result = datetime_series.agg(lambda x: Series([x, x**2], index=["x", "x^2"]))

`

369

376

`tm.assert_frame_equal(result, expected)

`

370

377

``

371

378

``

`@@ -445,7 +452,10 @@ def test_apply_series_on_date_time_index_aware_series(dti, exp, aware):

`

445

452

`index = dti.tz_localize("UTC").index

`

446

453

`else:

`

447

454

`index = dti.index

`

448

``

`-

result = Series(index).apply(lambda x: Series([1, 2]))

`

``

455

`+

msg = "Returning a DataFrame from Series.apply when the supplied function"

`

``

456

`+

with tm.assert_produces_warning(FutureWarning, match=msg):

`

``

457

`+

GH52123

`

``

458

`+

result = Series(index).apply(lambda x: Series([1, 2]))

`

449

459

`tm.assert_frame_equal(result, exp)

`

450

460

``

451

461

``

`@@ -546,7 +556,11 @@ def test_apply_dictlike_transformer(string_series, ops):

`

546

556

`def test_apply_retains_column_name():

`

547

557

`# GH 16380

`

548

558

`df = DataFrame({"x": range(3)}, Index(range(3), name="x"))

`

549

``

`-

result = df.x.apply(lambda x: Series(range(x + 1), Index(range(x + 1), name="y")))

`

``

559

`+

func = lambda x: Series(range(x + 1), Index(range(x + 1), name="y"))

`

``

560

`+

msg = "Returning a DataFrame from Series.apply when the supplied function"

`

``

561

`+

with tm.assert_produces_warning(FutureWarning, match=msg):

`

``

562

`+

GH52123

`

``

563

`+

result = df.x.apply(func)

`

550

564

`expected = DataFrame(

`

551

565

` [[0.0, np.nan, np.nan], [0.0, 1.0, np.nan], [0.0, 1.0, 2.0]],

`

552

566

`columns=Index(range(3), name="y"),

`