Skip to content

BUG: Fixed Series.align(frame) with ExtensionArray #20580

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
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
3 changes: 2 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
is_complex, is_datetimetz, is_categorical_dtype,
is_datetimelike,
is_extension_type,
is_extension_array_dtype,
is_object_dtype,
is_datetime64tz_dtype, is_datetime64_dtype,
is_datetime64_ns_dtype,
Expand Down Expand Up @@ -329,7 +330,7 @@ def maybe_promote(dtype, fill_value=np.nan):
dtype = np.object_

# in case we have a string that looked like a number
if is_categorical_dtype(dtype):
if is_extension_array_dtype(dtype):
pass
elif is_datetimetz(dtype):
pass
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/extension/base/reshaping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import numpy as np

import pandas as pd
from pandas.core.internals import ExtensionBlock
Expand Down Expand Up @@ -64,6 +65,19 @@ def test_align_frame(self, data, na_value):
self.assert_frame_equal(r1, e1)
self.assert_frame_equal(r2, e2)

def test_align_series_frame(self, data, na_value):
# https://github.com/pandas-dev/pandas/issues/20576
ser = pd.Series(data, name='a')
df = pd.DataFrame({"col": np.arange(len(ser) + 1)})
r1, r2 = ser.align(df)

e1 = pd.Series(
data._constructor_from_sequence(list(data) + [na_value]),
name=ser.name)

self.assert_series_equal(r1, e1)
self.assert_frame_equal(r2, df)

def test_set_frame_expand_regular_with_extension(self, data):
df = pd.DataFrame({"A": [1] * len(data)})
df['B'] = data
Expand Down