@@ -1900,10 +1900,8 @@ def test_concat_multiindex_dfs_with_deepcopy(self):
1900
1900
result_no_copy = pd .concat (example_dict , names = ['testname' ])
1901
1901
tm .assert_frame_equal (result_no_copy , expected )
1902
1902
1903
-
1904
1903
def test_concat_no_unnecessary_upcats (self ):
1905
1904
# GH 13247
1906
-
1907
1905
for pdt in [pd .Series , pd .DataFrame , pd .Panel , pd .Panel4D ]:
1908
1906
dims = pdt ().ndim
1909
1907
for dt in np .sctypes ['float' ]:
@@ -1913,9 +1911,9 @@ def test_concat_no_unnecessary_upcats(self):
1913
1911
x = pd .concat (dfs )
1914
1912
self .assertTrue (x .values .dtype == dt )
1915
1913
1916
- for dt in (np .sctypes ['int' ] + np .sctypes ['uint' ]):
1914
+ for dt in (np .sctypes ['int' ] + np .sctypes ['uint' ]):
1917
1915
dfs = [pdt (np .array ([1 ], dtype = dt , ndmin = dims )),
1918
- pdt (np .array ([5 ], dtype = dt , ndmin = dims ))]
1916
+ pdt (np .array ([5 ], dtype = dt , ndmin = dims ))]
1919
1917
x = pd .concat (dfs )
1920
1918
self .assertTrue (x .values .dtype == dt )
1921
1919
@@ -1934,3 +1932,31 @@ def test_concat_no_unnecessary_upcats(self):
1934
1932
objs .append (pdt (np .array ([1 ], dtype = np .int32 , ndmin = dims )))
1935
1933
objs .append (pdt (np .array ([1 ], dtype = np .float16 , ndmin = dims )))
1936
1934
self .assertTrue (pd .concat (objs ).values .dtype == np .float64 )
1935
+
1936
+ @parametrize ('dtype' , np .sctypes ('float' ))
1937
+ @parametrize ('klass' , [Series , DataFrame , Panel ])
1938
+ def test_concat_no_unnecessary_upcats_pytest (self , dtype , klass ):
1939
+ # GH 13247
1940
+ for pdt in klass :
1941
+ dims = pdt ().ndim
1942
+ for dt in dtype :
1943
+ dfs = [pdt (np .array ([1 ], dtype = dt , ndmin = dims )),
1944
+ pdt (np .array ([np .nan ], dtype = dt , ndmin = dims )),
1945
+ pdt (np .array ([5 ], dtype = dt , ndmin = dims ))]
1946
+ x = pd .concat (dfs )
1947
+ self .assertTrue (x .values .dtype == dt )
1948
+
1949
+ objs = []
1950
+ objs .append (pdt (np .array ([1 ], dtype = np .float32 , ndmin = dims )))
1951
+ objs .append (pdt (np .array ([1 ], dtype = np .float16 , ndmin = dims )))
1952
+ self .assertTrue (pd .concat (objs ).values .dtype == np .float32 )
1953
+
1954
+ objs = []
1955
+ objs .append (pdt (np .array ([1 ], dtype = np .int32 , ndmin = dims )))
1956
+ objs .append (pdt (np .array ([1 ], dtype = np .int64 , ndmin = dims )))
1957
+ self .assertTrue (pd .concat (objs ).values .dtype == np .int64 )
1958
+
1959
+ objs = []
1960
+ objs .append (pdt (np .array ([1 ], dtype = np .int32 , ndmin = dims )))
1961
+ objs .append (pdt (np .array ([1 ], dtype = np .float16 , ndmin = dims )))
1962
+ self .assertTrue (pd .concat (objs ).values .dtype == np .float64 )
0 commit comments