@@ -8813,15 +8813,7 @@ def _align_frame(
8813
8813
right = right .fillna (method = method , axis = fill_axis , limit = limit )
8814
8814
8815
8815
# if DatetimeIndex have different tz, convert to UTC
8816
- if is_datetime64tz_dtype (left .index .dtype ):
8817
- if left .index .tz != right .index .tz :
8818
- if join_index is not None :
8819
- # GH#33671 ensure we don't change the index on
8820
- # our original Series (NB: by default deep=False)
8821
- left = left .copy ()
8822
- right = right .copy ()
8823
- left .index = join_index
8824
- right .index = join_index
8816
+ left , right = _align_as_utc (left , right , join_index )
8825
8817
8826
8818
return (
8827
8819
left .__finalize__ (self ),
@@ -8863,27 +8855,18 @@ def _align_series(
8863
8855
else :
8864
8856
# one has > 1 ndim
8865
8857
fdata = self ._mgr
8866
- if axis == 0 :
8867
- join_index = self .index
8858
+ if axis in [ 0 , 1 ] :
8859
+ join_index = self .axes [ axis ]
8868
8860
lidx , ridx = None , None
8869
- if not self . index .equals (other .index ):
8870
- join_index , lidx , ridx = self . index .join (
8861
+ if not join_index .equals (other .index ):
8862
+ join_index , lidx , ridx = join_index .join (
8871
8863
other .index , how = join , level = level , return_indexers = True
8872
8864
)
8873
8865
8874
8866
if lidx is not None :
8875
- fdata = fdata .reindex_indexer (join_index , lidx , axis = 1 )
8867
+ bm_axis = self ._get_block_manager_axis (axis )
8868
+ fdata = fdata .reindex_indexer (join_index , lidx , axis = bm_axis )
8876
8869
8877
- elif axis == 1 :
8878
- join_index = self .columns
8879
- lidx , ridx = None , None
8880
- if not self .columns .equals (other .index ):
8881
- join_index , lidx , ridx = self .columns .join (
8882
- other .index , how = join , level = level , return_indexers = True
8883
- )
8884
-
8885
- if lidx is not None :
8886
- fdata = fdata .reindex_indexer (join_index , lidx , axis = 0 )
8887
8870
else :
8888
8871
raise ValueError ("Must specify axis=0 or 1" )
8889
8872
@@ -8905,15 +8888,7 @@ def _align_series(
8905
8888
8906
8889
# if DatetimeIndex have different tz, convert to UTC
8907
8890
if is_series or (not is_series and axis == 0 ):
8908
- if is_datetime64tz_dtype (left .index .dtype ):
8909
- if left .index .tz != right .index .tz :
8910
- if join_index is not None :
8911
- # GH#33671 ensure we don't change the index on
8912
- # our original Series (NB: by default deep=False)
8913
- left = left .copy ()
8914
- right = right .copy ()
8915
- left .index = join_index
8916
- right .index = join_index
8891
+ left , right = _align_as_utc (left , right , join_index )
8917
8892
8918
8893
return (
8919
8894
left .__finalize__ (self ),
@@ -11887,3 +11862,23 @@ def _doc_params(cls):
11887
11862
The required number of valid values to perform the operation. If fewer than
11888
11863
``min_count`` non-NA values are present the result will be NA.
11889
11864
"""
11865
+
11866
+
11867
+ def _align_as_utc (
11868
+ left : FrameOrSeries , right : FrameOrSeries , join_index : Index | None
11869
+ ) -> tuple [FrameOrSeries , FrameOrSeries ]:
11870
+ """
11871
+ If we are aligning timezone-aware DatetimeIndexes and the timezones
11872
+ do not match, convert both to UTC.
11873
+ """
11874
+ if is_datetime64tz_dtype (left .index .dtype ):
11875
+ if left .index .tz != right .index .tz :
11876
+ if join_index is not None :
11877
+ # GH#33671 ensure we don't change the index on
11878
+ # our original Series (NB: by default deep=False)
11879
+ left = left .copy ()
11880
+ right = right .copy ()
11881
+ left .index = join_index
11882
+ right .index = join_index
11883
+
11884
+ return left , right
0 commit comments