File tree 3 files changed +18
-3
lines changed
3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ Bug Fixes
52
52
**I/O **
53
53
54
54
- Bug in reading a HDF5 table-format ``DataFrame `` created in Python 2, in Python 3 (:issue: `24925 `)
55
- -
55
+ - Bug where float indexes could have misaligned values when printing ( :issue: ` 25061 `)
56
56
-
57
57
58
58
**Categorical **
Original file line number Diff line number Diff line change @@ -1060,19 +1060,26 @@ def get_result_as_array(self):
1060
1060
def format_values_with (float_format ):
1061
1061
formatter = self ._value_formatter (float_format , threshold )
1062
1062
1063
+ # default formatter leaves a space to the left when formatting
1064
+ # floats, must be consistent for left-justifying NaNs (GH #25061)
1065
+ if self .justify == 'left' :
1066
+ na_rep = ' ' + self .na_rep
1067
+ else :
1068
+ na_rep = self .na_rep
1069
+
1063
1070
# separate the wheat from the chaff
1064
1071
values = self .values
1065
1072
mask = isna (values )
1066
1073
if hasattr (values , 'to_dense' ): # sparse numpy ndarray
1067
1074
values = values .to_dense ()
1068
1075
values = np .array (values , dtype = 'object' )
1069
- values [mask ] = self . na_rep
1076
+ values [mask ] = na_rep
1070
1077
imask = (~ mask ).ravel ()
1071
1078
values .flat [imask ] = np .array ([formatter (val )
1072
1079
for val in values .ravel ()[imask ]])
1073
1080
1074
1081
if self .fixed_width :
1075
- return _trim_zeros (values , self . na_rep )
1082
+ return _trim_zeros (values , na_rep )
1076
1083
1077
1084
return values
1078
1085
Original file line number Diff line number Diff line change @@ -198,6 +198,14 @@ def test_latex_repr(self):
198
198
199
199
assert s ._repr_latex_ () is None
200
200
201
+ def test_index_repr_in_frame_with_nan (self ):
202
+ # see gh-25061
203
+ i = Index ([1 , np .nan ])
204
+ s = Series ([1 , 2 ], index = i )
205
+ exp = """1.0 1\n NaN 2\n dtype: int64"""
206
+
207
+ assert repr (s ) == exp
208
+
201
209
202
210
class TestCategoricalRepr (object ):
203
211
You can’t perform that action at this time.
0 commit comments