Skip to content

Fix #28552 Add test for DataFrame min/max preserve timezone #33905

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 4 commits into from May 12, 2020
Merged
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions pandas/tests/frame/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,19 @@ def test_constructor_data_aware_dtype_naive(self, tz_aware_fixture):
result = DataFrame({"d": [pd.Timestamp("2019", tz=tz)]}, dtype="datetime64[ns]")
expected = DataFrame({"d": [pd.Timestamp("2019")]})
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"initial",
["2018-10-08 13:36:45+00:00", "2018-10-08 13:36:45+03:00"], # Non-UTC timezone
)
@pytest.mark.parametrize("method", [DataFrame.min, DataFrame.max])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the strings ['min', 'max'] here, and then below you can do getattr(df, method)(axis=1)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

def test_preserve_timezone(self, initial: str, method):
# GH 28552
# Given
initial_dt = pd.to_datetime(initial)
series = pd.Series([initial_dt])
df = DataFrame([series])
# When
actual_df = method(df, axis=1)
# Then
assert actual_df[0].tz == initial_dt.tz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the results result and expected and compare 2 DataFrame or Series objects and use tm.assert_equal(result, expected)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Please note that min and max methods of the DataFrame both return Series, so I choose to use the tm.assert_series_equal instead in the same manner as it is being used in test_frame_no_datetime64_dtype.