Skip to content

Commit 9cf0755

Browse files
committed
Add test for float_precision parsers equality
1 parent 5fab153 commit 9cf0755

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

pandas/tests/io/parser/test_c_parser_only.py

+60
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,63 @@ def test_1000_sep_with_decimal(
644644
float_precision=float_precision,
645645
)
646646
tm.assert_frame_equal(result, expected)
647+
648+
649+
@pytest.mark.parametrize(
650+
"float_precision", [None, "high", "round_trip"],
651+
)
652+
@pytest.mark.parametrize(
653+
"value,expected",
654+
[
655+
("-1,0", -1.0),
656+
("-1,2e0", -1.2),
657+
("-1e0", -1.0),
658+
("+1e0", 1.0),
659+
("+1e+0", 1.0),
660+
("+1e-1", 0.1),
661+
("+,1e1", 1.0),
662+
("+1,e0", 1.0),
663+
("-,1e1", -1.0),
664+
("-1,e0", -1.0),
665+
("0,1", 0.1),
666+
("1,", 1.0),
667+
(",1", 0.1),
668+
("-,1", -0.1),
669+
("1_,", 1.0),
670+
("1_234,56", 1234.56),
671+
("1_234,56e0", 1234.56),
672+
# negative cases; must not parse as float
673+
("_", "_"),
674+
("-_", "-_"),
675+
("-_1", "-_1"),
676+
("-_1e0", "-_1e0"),
677+
("_1", "_1"),
678+
("_1,", "_1,"),
679+
("_1,_", "_1,_"),
680+
("_1e0", "_1e0"),
681+
("1,2e_1", "1,2e_1"),
682+
("1,2e1_0", "1,2e1_0"),
683+
("1,_2", "1,_2"),
684+
(",1__2", ",1__2"),
685+
(",1e", ",1e"),
686+
("-,1e", "-,1e"),
687+
("1_000,000_000", "1_000,000_000"),
688+
("1,e1_2", "1,e1_2"),
689+
],
690+
)
691+
def test_1000_sep_decimal_float_precision(
692+
c_parser_only, value, expected, float_precision
693+
):
694+
# test decimal and thousand sep handling in across 'float_precision'
695+
# parsers
696+
parser = c_parser_only
697+
df = parser.read_csv(
698+
StringIO(value),
699+
sep="|",
700+
thousands="_",
701+
decimal=",",
702+
header=None,
703+
float_precision=float_precision,
704+
)
705+
val = df.iloc[0, 0]
706+
assert val == expected

0 commit comments

Comments
 (0)