test_decimal.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """
  2. Tests that work on both the Python and C engines but do not have a
  3. specific classification into the other test modules.
  4. """
  5. from io import StringIO
  6. import pytest
  7. from pandas import DataFrame
  8. import pandas._testing as tm
  9. xfail_pyarrow = pytest.mark.usefixtures("pyarrow_xfail")
  10. @xfail_pyarrow
  11. @pytest.mark.parametrize(
  12. "data,thousands,decimal",
  13. [
  14. (
  15. """A|B|C
  16. 1|2,334.01|5
  17. 10|13|10.
  18. """,
  19. ",",
  20. ".",
  21. ),
  22. (
  23. """A|B|C
  24. 1|2.334,01|5
  25. 10|13|10,
  26. """,
  27. ".",
  28. ",",
  29. ),
  30. ],
  31. )
  32. def test_1000_sep_with_decimal(all_parsers, data, thousands, decimal):
  33. parser = all_parsers
  34. expected = DataFrame({"A": [1, 10], "B": [2334.01, 13], "C": [5, 10.0]})
  35. result = parser.read_csv(
  36. StringIO(data), sep="|", thousands=thousands, decimal=decimal
  37. )
  38. tm.assert_frame_equal(result, expected)
  39. def test_euro_decimal_format(all_parsers):
  40. parser = all_parsers
  41. data = """Id;Number1;Number2;Text1;Text2;Number3
  42. 1;1521,1541;187101,9543;ABC;poi;4,738797819
  43. 2;121,12;14897,76;DEF;uyt;0,377320872
  44. 3;878,158;108013,434;GHI;rez;2,735694704"""
  45. result = parser.read_csv(StringIO(data), sep=";", decimal=",")
  46. expected = DataFrame(
  47. [
  48. [1, 1521.1541, 187101.9543, "ABC", "poi", 4.738797819],
  49. [2, 121.12, 14897.76, "DEF", "uyt", 0.377320872],
  50. [3, 878.158, 108013.434, "GHI", "rez", 2.735694704],
  51. ],
  52. columns=["Id", "Number1", "Number2", "Text1", "Text2", "Number3"],
  53. )
  54. tm.assert_frame_equal(result, expected)