|
1 | 1 | import numpy as np
|
2 | 2 | import pytest
|
| 3 | +import pytz |
3 | 4 |
|
4 | 5 | import pandas as pd
|
5 |
| -from pandas import DataFrame, Index, Series |
| 6 | +from pandas import DataFrame, Index, Series, date_range |
6 | 7 | import pandas._testing as tm
|
7 | 8 |
|
8 | 9 |
|
9 | 10 | class TestDataFrameAlign:
|
| 11 | + def test_frame_align_aware(self): |
| 12 | + idx1 = date_range("2001", periods=5, freq="H", tz="US/Eastern") |
| 13 | + idx2 = date_range("2001", periods=5, freq="2H", tz="US/Eastern") |
| 14 | + df1 = DataFrame(np.random.randn(len(idx1), 3), idx1) |
| 15 | + df2 = DataFrame(np.random.randn(len(idx2), 3), idx2) |
| 16 | + new1, new2 = df1.align(df2) |
| 17 | + assert df1.index.tz == new1.index.tz |
| 18 | + assert df2.index.tz == new2.index.tz |
| 19 | + |
| 20 | + # different timezones convert to UTC |
| 21 | + |
| 22 | + # frame with frame |
| 23 | + df1_central = df1.tz_convert("US/Central") |
| 24 | + new1, new2 = df1.align(df1_central) |
| 25 | + assert new1.index.tz == pytz.UTC |
| 26 | + assert new2.index.tz == pytz.UTC |
| 27 | + |
| 28 | + # frame with Series |
| 29 | + new1, new2 = df1.align(df1_central[0], axis=0) |
| 30 | + assert new1.index.tz == pytz.UTC |
| 31 | + assert new2.index.tz == pytz.UTC |
| 32 | + |
| 33 | + df1[0].align(df1_central, axis=0) |
| 34 | + assert new1.index.tz == pytz.UTC |
| 35 | + assert new2.index.tz == pytz.UTC |
| 36 | + |
10 | 37 | def test_align_float(self, float_frame):
|
11 | 38 | af, bf = float_frame.align(float_frame)
|
12 | 39 | assert af._mgr is not float_frame._mgr
|
|
0 commit comments