Skip to content

Commit abe0580

Browse files
author
Santhosh18
committed
Inferred dtype at the end of df.explode()
1 parent 998e2ab commit abe0580

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7007,6 +7007,7 @@ def explode(self, column: Union[str, Tuple]) -> "DataFrame":
70077007
result = df.drop([column], axis=1).join(result)
70087008
result.index = self.index.take(result.index)
70097009
result = result.reindex(columns=self.columns, copy=False)
7010+
result = result.infer_objects()
70107011

70117012
return result
70127013

pandas/tests/series/methods/test_explode.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def test_basic():
99
s = pd.Series([[0, 1, 2], np.nan, [], (3, 4)], index=list("abcd"), name="foo")
10-
result = s.explode()
10+
result = s. explode()
1111
expected = pd.Series(
1212
[0, 1, 2, np.nan, np.nan, 3, 4], index=list("aaabcdd"), dtype=object, name="foo"
1313
)
@@ -118,3 +118,11 @@ def test_duplicate_index():
118118
result = s.explode()
119119
expected = pd.Series([1, 2, 3, 4], index=[0, 0, 0, 0], dtype=object)
120120
tm.assert_series_equal(result, expected)
121+
122+
123+
def test_inferred_dtype():
124+
s = pd.Series([1,None,3])
125+
df = pd.DataFrame({'A':[s,s,s,s], "B":1})
126+
result = df.explode("A").dtypes.values
127+
expected = np.array([np.dtype('float64'), np.dtype('int64')])
128+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)