Skip to content

Commit 30d4a07

Browse files
committed
Edited original merge to be inline with pandas-dev#62869, added 'object' as dtype to be captured in frame:to_series
1 parent 32360a8 commit 30d4a07

File tree

3 files changed

+11
-113
lines changed

3 files changed

+11
-113
lines changed

pandas/core/frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8491,7 +8491,10 @@ def to_series(right):
84918491
# pass dtype to avoid doing inference, which would break consistency
84928492
# with Index/Series ops
84938493
dtype = None
8494-
if getattr(right, "dtype", None) == object:
8494+
if (
8495+
getattr(right, "dtype", None) == "object"
8496+
or getattr(right, "dtype", None) == object
8497+
):
84958498
# can't pass right.dtype unconditionally as that would break on e.g.
84968499
# datetime64[h] ndarray
84978500
dtype = object

pandas/tests/arithmetic/test_string.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ def test_mul(any_string_dtype):
244244

245245
def test_add_strings(any_string_dtype, request):
246246
dtype = any_string_dtype
247-
if dtype != np.dtype(object):
248-
mark = pytest.mark.xfail(reason="GH-28527")
249-
request.applymarker(mark)
250247
arr = pd.array(["a", "b", "c", "d"], dtype=dtype)
251248
df = pd.DataFrame([["t", "y", "v", "w"]], dtype=object)
252249
assert arr.__add__(df) is NotImplemented
@@ -261,10 +258,15 @@ def test_add_strings(any_string_dtype, request):
261258

262259

263260
@pytest.mark.xfail(reason="GH-28527")
264-
def test_add_frame(dtype):
261+
def test_add_frame(request, dtype):
262+
if dtype.storage == "python":
263+
# Inconsistent behavior between different versions of the python engine.
264+
# Some return correctly, some return but with the wrong dtype
265+
# Others just fail, we are blanket failing all
266+
mark = pytest.mark.xfail(reason="[XPASS(strict)] GH-28527")
267+
request.node.applymarker(mark)
265268
arr = pd.array(["a", "b", np.nan, np.nan], dtype=dtype)
266269
df = pd.DataFrame([["x", np.nan, "y", np.nan]])
267-
268270
assert arr.__add__(df) is NotImplemented
269271

270272
result = arr + df

pandas/tests/arrays/string_/test_string.py

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -159,113 +159,6 @@ def test_astype_roundtrip(dtype):
159159
tm.assert_series_equal(result2, ser2)
160160

161161

162-
def test_add(dtype):
163-
a = pd.Series(["a", "b", "c", None, None], dtype=dtype)
164-
b = pd.Series(["x", "y", None, "z", None], dtype=dtype)
165-
166-
result = a + b
167-
expected = pd.Series(["ax", "by", None, None, None], dtype=dtype)
168-
tm.assert_series_equal(result, expected)
169-
170-
result = a.add(b)
171-
tm.assert_series_equal(result, expected)
172-
173-
result = a.radd(b)
174-
expected = pd.Series(["xa", "yb", None, None, None], dtype=dtype)
175-
tm.assert_series_equal(result, expected)
176-
177-
result = a.add(b, fill_value="-")
178-
expected = pd.Series(["ax", "by", "c-", "-z", None], dtype=dtype)
179-
tm.assert_series_equal(result, expected)
180-
181-
182-
def test_add_2d(dtype, request):
183-
if dtype.storage == "pyarrow":
184-
reason = "Failed: DID NOT RAISE <class 'ValueError'>"
185-
mark = pytest.mark.xfail(raises=None, reason=reason)
186-
request.applymarker(mark)
187-
188-
a = pd.array(["a", "b", "c"], dtype=dtype)
189-
b = np.array([["a", "b", "c"]], dtype=object)
190-
with pytest.raises(ValueError, match="3 != 1"):
191-
a + b
192-
193-
s = pd.Series(a)
194-
with pytest.raises(ValueError, match="3 != 1"):
195-
s + b
196-
197-
198-
def test_add_sequence(dtype):
199-
a = pd.array(["a", "b", None, None], dtype=dtype)
200-
other = ["x", None, "y", None]
201-
202-
result = a + other
203-
expected = pd.array(["ax", None, None, None], dtype=dtype)
204-
tm.assert_extension_array_equal(result, expected)
205-
206-
result = other + a
207-
expected = pd.array(["xa", None, None, None], dtype=dtype)
208-
tm.assert_extension_array_equal(result, expected)
209-
210-
211-
def test_mul(dtype):
212-
a = pd.array(["a", "b", None], dtype=dtype)
213-
result = a * 2
214-
expected = pd.array(["aa", "bb", None], dtype=dtype)
215-
tm.assert_extension_array_equal(result, expected)
216-
217-
result = 2 * a
218-
tm.assert_extension_array_equal(result, expected)
219-
220-
221-
def test_add_series(dtype):
222-
arr = pd.array(["a", "b", "c", "d"], dtype=dtype)
223-
ser = pd.Series(["t", "y", "v", "w"], dtype=object)
224-
225-
result = arr + ser
226-
expected = pd.Series(["at", "by", "cv", "dw"]).astype(dtype)
227-
tm.assert_series_equal(result, expected)
228-
229-
result = ser + arr
230-
expected = pd.Series(["ta", "yb", "vc", "wd"]).astype(dtype)
231-
tm.assert_series_equal(result, expected)
232-
233-
234-
def test_add_strings(dtype):
235-
arr = pd.array(["a", "b", "c", "d"], dtype=dtype)
236-
df = pd.DataFrame([["t", "y", "v", "w"]], dtype=object)
237-
assert arr.__add__(df) is NotImplemented
238-
239-
result = arr + df
240-
expected = pd.DataFrame([["at", "by", "cv", "dw"]]).astype(dtype)
241-
tm.assert_frame_equal(result, expected)
242-
243-
result = df + arr
244-
expected = pd.DataFrame([["ta", "yb", "vc", "wd"]]).astype(dtype)
245-
tm.assert_frame_equal(result, expected)
246-
247-
248-
@pytest.mark.xfail(reason="GH-28527")
249-
def test_add_frame(request, dtype):
250-
if dtype.storage == "python":
251-
# Inconsistent behavior between different versions of the python engine.
252-
# Some return correctly, some return but with the wrong dtype
253-
# Others just fail, we are blanket failing all
254-
mark = pytest.mark.xfail(reason="[XPASS(strict)] GH-28527")
255-
request.node.applymarker(mark)
256-
arr = pd.array(["a", "b", np.nan, np.nan], dtype=dtype)
257-
df = pd.DataFrame([["x", np.nan, "y", np.nan]])
258-
assert arr.__add__(df) is NotImplemented
259-
260-
result = arr + df
261-
expected = pd.DataFrame([["ax", np.nan, np.nan, np.nan]]).astype(dtype)
262-
tm.assert_frame_equal(result, expected)
263-
264-
result = df + arr
265-
expected = pd.DataFrame([["xa", np.nan, np.nan, np.nan]]).astype(dtype)
266-
tm.assert_frame_equal(result, expected)
267-
268-
269162
def test_constructor_raises(cls):
270163
if cls is pd.arrays.StringArray:
271164
msg = "StringArray requires a sequence of strings or pandas.NA"

0 commit comments

Comments
 (0)