From 75409da761eedef4e5b294f307fb01b4b537a014 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 31 May 2025 11:02:06 +0300 Subject: [PATCH 1/2] gh-74232: Add a note about roundtrip of non-float numerics in CSV --- Doc/library/csv.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 533cdf13974be6..80b51ac0a0dd0d 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -70,7 +70,7 @@ The :mod:`csv` module defines the following functions: section :ref:`csv-fmt-params`. Each row read from the csv file is returned as a list of strings. No - automatic data type conversion is performed unless the ``QUOTE_NONNUMERIC`` format + automatic data type conversion is performed unless the :data:`QUOTE_NONNUMERIC` format option is specified (in which case unquoted fields are transformed into floats). A short usage example:: @@ -331,8 +331,14 @@ The :mod:`csv` module defines the following constants: Instructs :class:`writer` objects to quote all non-numeric fields. - Instructs :class:`reader` objects to convert all non-quoted fields to type *float*. + Instructs :class:`reader` objects to convert all non-quoted fields to type :class:`float`. + .. note:: + Some numeric types, such as :class:`bool`, :class:`~fractions.Fraction`, + or :class:`~enum.IntEnum`, have a string representation that cannot be + converted to :class:`float`. + They cannot be read in the :data:`QUOTE_NONNUMERIC` and + :data:`QUOTE_STRING` modes. .. data:: QUOTE_NONE From 4221f6edfeaf4c027b3a133a0a0d3237690a6a33 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 31 May 2025 11:41:26 +0300 Subject: [PATCH 2/2] Fix a typo. --- Doc/library/csv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst index 80b51ac0a0dd0d..5297be17bd708e 100644 --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -338,7 +338,7 @@ The :mod:`csv` module defines the following constants: or :class:`~enum.IntEnum`, have a string representation that cannot be converted to :class:`float`. They cannot be read in the :data:`QUOTE_NONNUMERIC` and - :data:`QUOTE_STRING` modes. + :data:`QUOTE_STRINGS` modes. .. data:: QUOTE_NONE