Skip to content

TST: tz_localize/tz_convert unclear test assertions #37498

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
Oct 30, 2020
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: 17 additions & 1 deletion pandas/tests/frame/methods/test_tz_convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pandas import DataFrame, Index, MultiIndex, date_range
from pandas import DataFrame, Index, MultiIndex, Series, date_range
import pandas._testing as tm


Expand Down Expand Up @@ -88,3 +88,19 @@ def test_tz_convert_and_localize(self, fn):
with pytest.raises(ValueError, match="not valid"):
df = DataFrame(index=l0)
df = getattr(df, fn)("US/Pacific", level=1)

@pytest.mark.parametrize("klass", [Series, DataFrame])
@pytest.mark.parametrize("copy", [True, False])
def test_tz_convert_copy_inplace_mutate(self, copy, klass):
# GH#6326
obj = klass(
np.arange(0, 5),
index=date_range("20131027", periods=5, freq="1H", tz="Europe/Berlin"),
)
orig = obj.copy()
result = obj.tz_convert("UTC", copy=copy)
expected = klass(np.arange(0, 5), index=obj.index.tz_convert("UTC"))
tm.assert_equal(result, expected)
tm.assert_equal(obj, orig)
assert result.index is not obj.index
assert result is not obj
23 changes: 22 additions & 1 deletion pandas/tests/frame/methods/test_tz_localize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from pandas import DataFrame, date_range
import numpy as np
import pytest

from pandas import DataFrame, Series, date_range
import pandas._testing as tm


Expand All @@ -19,3 +22,21 @@ def test_frame_tz_localize(self):
result = df.tz_localize("utc", axis=1)
assert result.columns.tz.zone == "UTC"
tm.assert_frame_equal(result, expected.T)

@pytest.mark.parametrize("klass", [Series, DataFrame])
@pytest.mark.parametrize("copy", [True, False])
def test_tz_localize_copy_inplace_mutate(self, copy, klass):
# GH#6326
obj = klass(
np.arange(0, 5), index=date_range("20131027", periods=5, freq="1H", tz=None)
)
orig = obj.copy()
result = obj.tz_localize("UTC", copy=copy)
expected = klass(
np.arange(0, 5),
index=date_range("20131027", periods=5, freq="1H", tz="UTC"),
)
tm.assert_equal(result, expected)
tm.assert_equal(obj, orig)
assert result.index is not obj.index
assert result is not obj
15 changes: 15 additions & 0 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import OrderedDict
from datetime import datetime, timedelta

from dateutil.tz import tzoffset
import numpy as np
import numpy.ma as ma
import pytest
Expand Down Expand Up @@ -1588,6 +1589,20 @@ def test_constructor_dict_timedelta_index(self):
)
tm.assert_series_equal(result, expected)

def test_constructor_infer_index_tz(self):
values = [188.5, 328.25]
tzinfo = tzoffset(None, 7200)
index = [
datetime(2012, 5, 11, 11, tzinfo=tzinfo),
datetime(2012, 5, 11, 12, tzinfo=tzinfo),
]
series = Series(data=values, index=index)

assert series.index.tz == tzinfo

# it works! GH#2443
repr(series.index[0])


class TestSeriesConstructorIndexCoercion:
def test_series_constructor_datetimelike_index_coercion(self):
Expand Down
43 changes: 0 additions & 43 deletions pandas/tests/series/test_timezones.py

This file was deleted.