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 2 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
15 changes: 15 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,20 @@ 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):
# /Users/taugspurger/sandbox/pandas-ip/pandas/pandas/tests/extension/base/reshaping.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suppose this is a left over?

# https://github.com/pandas-dev/pandas/issues/20576
ser = pd.Series(data[:3], name='a')
df = pd.DataFrame({"col": np.arange(4)})
r1, r2 = ser.align(df)

e1 = pd.Series(
data._constructor_from_sequence(list(data[:3]) + [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
4 changes: 4 additions & 0 deletions pandas/tests/extension/category/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def test_align(self, data, na_value):
def test_align_frame(self, data, na_value):
pass

@pytest.mark.skip(reason="Unobserved categories preseved in concat.")
def test_align_series_frame(self, data, na_value):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this only because the way the test is constructed? You can also do it with the full of data instead of only the first 3 elements. Then this is not an issue?

pass


class TestGetitem(base.BaseGetitemTests):
@pytest.mark.skip(reason="Backwards compatibility")
Expand Down