Skip to content

Commit a34dd96

Browse files
committed
BUG-25061 use local na_rep variable
1 parent 0ba733c commit a34dd96

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/io/formats/format.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1063,21 +1063,23 @@ def format_values_with(float_format):
10631063
# default formatter leaves a space to the left when formatting
10641064
# floats, must be consistent for left-justifying NaNs (GH #25061)
10651065
if self.justify == 'left':
1066-
self.na_rep = ' ' + self.na_rep
1066+
na_rep = ' ' + self.na_rep
1067+
else:
1068+
na_rep = self.na_rep
10671069

10681070
# separate the wheat from the chaff
10691071
values = self.values
10701072
mask = isna(values)
10711073
if hasattr(values, 'to_dense'): # sparse numpy ndarray
10721074
values = values.to_dense()
10731075
values = np.array(values, dtype='object')
1074-
values[mask] = self.na_rep
1076+
values[mask] = na_rep
10751077
imask = (~mask).ravel()
10761078
values.flat[imask] = np.array([formatter(val)
10771079
for val in values.ravel()[imask]])
10781080

10791081
if self.fixed_width:
1080-
return _trim_zeros(values, self.na_rep)
1082+
return _trim_zeros(values, na_rep)
10811083

10821084
return values
10831085

0 commit comments

Comments
 (0)