Skip to content

Commit d305d6a

Browse files
TomAugspurgerjorisvandenbossche
authored andcommitted
BUG: Fixed Series.align(frame) with ExtensionArray (#20580)
Closes #20576
1 parent 6f7f367 commit d305d6a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pandas/core/dtypes/cast.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
is_complex, is_datetimetz, is_categorical_dtype,
1313
is_datetimelike,
1414
is_extension_type,
15+
is_extension_array_dtype,
1516
is_object_dtype,
1617
is_datetime64tz_dtype, is_datetime64_dtype,
1718
is_datetime64_ns_dtype,
@@ -329,7 +330,7 @@ def maybe_promote(dtype, fill_value=np.nan):
329330
dtype = np.object_
330331

331332
# in case we have a string that looked like a number
332-
if is_categorical_dtype(dtype):
333+
if is_extension_array_dtype(dtype):
333334
pass
334335
elif is_datetimetz(dtype):
335336
pass

pandas/tests/extension/base/reshaping.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import numpy as np
23

34
import pandas as pd
45
from pandas.core.internals import ExtensionBlock
@@ -64,6 +65,19 @@ def test_align_frame(self, data, na_value):
6465
self.assert_frame_equal(r1, e1)
6566
self.assert_frame_equal(r2, e2)
6667

68+
def test_align_series_frame(self, data, na_value):
69+
# https://github.com/pandas-dev/pandas/issues/20576
70+
ser = pd.Series(data, name='a')
71+
df = pd.DataFrame({"col": np.arange(len(ser) + 1)})
72+
r1, r2 = ser.align(df)
73+
74+
e1 = pd.Series(
75+
data._constructor_from_sequence(list(data) + [na_value]),
76+
name=ser.name)
77+
78+
self.assert_series_equal(r1, e1)
79+
self.assert_frame_equal(r2, df)
80+
6781
def test_set_frame_expand_regular_with_extension(self, data):
6882
df = pd.DataFrame({"A": [1] * len(data)})
6983
df['B'] = data

0 commit comments

Comments
 (0)