Skip to content

Commit 8c38b24

Browse files
ganevgvmroeschke
authored andcommitted
TST: new test for str to small float conversion dtype (#29372)
* add str to small float conversion type test * restrucutre test
1 parent 28c9ccc commit 8c38b24

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/frame/test_dtypes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,18 @@ def test_asarray_homogenous(self):
10631063
expected = np.array([[1, 1], [2, 2]], dtype="object")
10641064
tm.assert_numpy_array_equal(result, expected)
10651065

1066+
def test_str_to_small_float_conversion_type(self):
1067+
# GH 20388
1068+
np.random.seed(13)
1069+
col_data = [str(np.random.random() * 1e-12) for _ in range(5)]
1070+
result = pd.DataFrame(col_data, columns=["A"])
1071+
expected = pd.DataFrame(col_data, columns=["A"], dtype=object)
1072+
tm.assert_frame_equal(result, expected)
1073+
# change the dtype of the elements from object to float one by one
1074+
result.loc[result.index, "A"] = [float(x) for x in col_data]
1075+
expected = pd.DataFrame(col_data, columns=["A"], dtype=float)
1076+
tm.assert_frame_equal(result, expected)
1077+
10661078

10671079
class TestDataFrameDatetimeWithTZ:
10681080
def test_interleave(self, timezone_frame):

0 commit comments

Comments
 (0)