Skip to content

STYLE: Inconsistent namespace - apply (pandas-dev#39992) #40029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,13 @@ def test_frame_apply_dont_convert_datetime64():

def test_apply_non_numpy_dtype():
# GH 12244
df = DataFrame({"dt": pd.date_range("2015-01-01", periods=3, tz="Europe/Brussels")})
df = DataFrame({"dt": date_range("2015-01-01", periods=3, tz="Europe/Brussels")})
result = df.apply(lambda x: x)
tm.assert_frame_equal(result, df)

result = df.apply(lambda x: x + pd.Timedelta("1day"))
expected = DataFrame(
{"dt": pd.date_range("2015-01-02", periods=3, tz="Europe/Brussels")}
{"dt": date_range("2015-01-02", periods=3, tz="Europe/Brussels")}
)
tm.assert_frame_equal(result, expected)

Expand Down Expand Up @@ -1149,11 +1149,9 @@ def test_agg_transform(axis, float_frame):
result = float_frame.apply([np.sqrt], axis=axis)
expected = f_sqrt.copy()
if axis in {0, "index"}:
expected.columns = pd.MultiIndex.from_product(
[float_frame.columns, ["sqrt"]]
)
expected.columns = MultiIndex.from_product([float_frame.columns, ["sqrt"]])
else:
expected.index = pd.MultiIndex.from_product([float_frame.index, ["sqrt"]])
expected.index = MultiIndex.from_product([float_frame.index, ["sqrt"]])
tm.assert_frame_equal(result, expected)

# multiple items in list
Expand All @@ -1162,11 +1160,11 @@ def test_agg_transform(axis, float_frame):
result = float_frame.apply([np.abs, np.sqrt], axis=axis)
expected = zip_frames([f_abs, f_sqrt], axis=other_axis)
if axis in {0, "index"}:
expected.columns = pd.MultiIndex.from_product(
expected.columns = MultiIndex.from_product(
[float_frame.columns, ["absolute", "sqrt"]]
)
else:
expected.index = pd.MultiIndex.from_product(
expected.index = MultiIndex.from_product(
[float_frame.index, ["absolute", "sqrt"]]
)
tm.assert_frame_equal(result, expected)
Expand Down Expand Up @@ -1228,7 +1226,7 @@ def test_agg_multiple_mixed_no_warning():
"A": [1, 2, 3],
"B": [1.0, 2.0, 3.0],
"C": ["foo", "bar", "baz"],
"D": pd.date_range("20130101", periods=3),
"D": date_range("20130101", periods=3),
}
)
expected = DataFrame(
Expand Down Expand Up @@ -1343,7 +1341,7 @@ def test_nuiscance_columns():
"A": [1, 2, 3],
"B": [1.0, 2.0, 3.0],
"C": ["foo", "bar", "baz"],
"D": pd.date_range("20130101", periods=3),
"D": date_range("20130101", periods=3),
}
)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ def test_transform(string_series):
# multiple items in list
# these are in the order as if we are applying both functions per
# series and then concatting
expected = pd.concat([f_sqrt, f_abs], axis=1)
expected = concat([f_sqrt, f_abs], axis=1)
expected.columns = ["sqrt", "absolute"]
result = string_series.apply([np.sqrt, np.abs])
tm.assert_frame_equal(result, expected)

# dict, provide renaming
expected = pd.concat([f_sqrt, f_abs], axis=1)
expected = concat([f_sqrt, f_abs], axis=1)
expected.columns = ["foo", "bar"]
expected = expected.unstack().rename("series")

Expand Down