Skip to content

Commit 7dc8a33

Browse files
committed
Refactor format class list and rename _trim_zeros to _trim_zeros_float
1 parent 5829a77 commit 7dc8a33

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pandas/io/formats/format.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,7 @@ def format_array(values, formatter, float_format=None, na_rep='NaN',
892892
fmt_klass = Timedelta64Formatter
893893
elif is_extension_array_dtype(values.dtype):
894894
fmt_klass = ExtensionArrayFormatter
895-
elif is_float_dtype(values.dtype):
896-
fmt_klass = FloatArrayFormatter
897-
elif is_complex_dtype(values.dtype):
895+
elif is_float_dtype(values.dtype) or is_complex_dtype(values.dtype):
898896
fmt_klass = FloatArrayFormatter
899897
elif is_integer_dtype(values.dtype):
900898
fmt_klass = IntArrayFormatter
@@ -1100,7 +1098,7 @@ def format_values_with(float_format):
11001098
if is_complex:
11011099
return _trim_zeros_complex(values, na_rep)
11021100
else:
1103-
return _trim_zeros(values, na_rep)
1101+
return _trim_zeros_float(values, na_rep)
11041102

11051103
return values
11061104

@@ -1433,19 +1431,19 @@ def just(x):
14331431
def _trim_zeros_complex(str_complexes, na_rep='NaN'):
14341432
"""
14351433
Separates the real and imaginary parts from the complex number, and
1436-
executes the _trim_zeros method on each of those.
1434+
executes the _trim_zeros_float method on each of those.
14371435
"""
14381436
def separate_and_trim(str_complex, na_rep):
14391437
num_arr = str_complex.split('+')
1440-
return (_trim_zeros([num_arr[0]], na_rep) +
1438+
return (_trim_zeros_float([num_arr[0]], na_rep) +
14411439
['+'] +
1442-
_trim_zeros([num_arr[1][:-1]], na_rep) +
1440+
_trim_zeros_float([num_arr[1][:-1]], na_rep) +
14431441
['j'])
14441442

14451443
return [''.join(separate_and_trim(x, na_rep)) for x in str_complexes]
14461444

14471445

1448-
def _trim_zeros(str_floats, na_rep='NaN'):
1446+
def _trim_zeros_float(str_floats, na_rep='NaN'):
14491447
"""
14501448
Trims zeros, leaving just one before the decimal points if need be.
14511449
"""

0 commit comments

Comments
 (0)