Skip to content

Commit dc86902

Browse files
committed
Modified base.py get_values_for_csv() to prevent extra decimal places for float16, float32 in output
1 parent 1fdae29 commit dc86902

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

pandas/core/indexes/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7755,12 +7755,12 @@ def get_values_for_csv(
77557755
if float_format is None and decimal == ".":
77567756
mask = isna(values)
77577757

7758-
if not quoting:
7759-
values = values.astype(str)
7760-
else:
7761-
values = np.array(values, dtype="str") # Convert float16 -> string
7762-
values = values.astype(float, copy=False) # Parse string -> Python float64
7763-
7758+
# GH60699
7759+
# Ensure quoting don't add extra decimal places in output for float16, float32
7760+
if values.dtype in [np.float16, np.float32]:
7761+
values = np.array(values, dtype="str")
7762+
values = values.astype(float, copy=False)
7763+
77647764
values = values.astype(object, copy=False)
77657765
values[mask] = na_rep
77667766
return values

sample.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)