26
26
from dateutil .tz .tz import tzutc
27
27
from dateutil .zoneinfo import tzfile
28
28
import numpy as np
29
- from numpy import float64 , int32 , ndarray
30
29
31
30
from pandas ._config .config import get_option , set_option
32
31
@@ -1125,7 +1124,7 @@ def __init__(
1125
1124
self .fixed_width = fixed_width
1126
1125
self .leading_space = leading_space
1127
1126
1128
- def get_result (self ) -> Union [ ndarray , List [str ] ]:
1127
+ def get_result (self ) -> List [str ]:
1129
1128
fmt_values = self ._format_strings ()
1130
1129
return _make_fixed_width (fmt_values , self .justify )
1131
1130
@@ -1261,7 +1260,7 @@ def formatter(value):
1261
1260
1262
1261
return formatter
1263
1262
1264
- def get_result_as_array (self ) -> Union [ ndarray , List [ str ]] :
1263
+ def get_result_as_array (self ) -> np . ndarray :
1265
1264
"""
1266
1265
Returns the float values converted into strings using
1267
1266
the parameters given at initialisation, as a numpy array
@@ -1301,9 +1300,10 @@ def format_values_with(float_format):
1301
1300
1302
1301
if self .fixed_width :
1303
1302
if is_complex :
1304
- return _trim_zeros_complex (values , na_rep )
1303
+ result = _trim_zeros_complex (values , na_rep )
1305
1304
else :
1306
- return _trim_zeros_float (values , na_rep )
1305
+ result = _trim_zeros_float (values , na_rep )
1306
+ return np .asarray (result , dtype = "object" )
1307
1307
1308
1308
return values
1309
1309
@@ -1368,7 +1368,7 @@ def _format_strings(self) -> List[str]:
1368
1368
class Datetime64Formatter (GenericArrayFormatter ):
1369
1369
def __init__ (
1370
1370
self ,
1371
- values : Union [ndarray , "Series" , DatetimeIndex , DatetimeArray ],
1371
+ values : Union [np . ndarray , "Series" , DatetimeIndex , DatetimeArray ],
1372
1372
nat_rep : str = "NaT" ,
1373
1373
date_format : None = None ,
1374
1374
** kwargs
@@ -1425,7 +1425,7 @@ def _format_strings(self) -> List[str]:
1425
1425
1426
1426
def format_percentiles (
1427
1427
percentiles : Union [
1428
- ndarray , List [Union [int , float ]], List [float ], List [Union [str , float ]]
1428
+ np . ndarray , List [Union [int , float ]], List [float ], List [Union [str , float ]]
1429
1429
]
1430
1430
) -> List [str ]:
1431
1431
"""
@@ -1493,7 +1493,9 @@ def format_percentiles(
1493
1493
return [i + "%" for i in out ]
1494
1494
1495
1495
1496
- def _is_dates_only (values : Union [ndarray , DatetimeArray , Index , DatetimeIndex ]) -> bool :
1496
+ def _is_dates_only (
1497
+ values : Union [np .ndarray , DatetimeArray , Index , DatetimeIndex ]
1498
+ ) -> bool :
1497
1499
# return a boolean if we are only dates (and don't have a timezone)
1498
1500
assert values .ndim == 1
1499
1501
@@ -1557,7 +1559,7 @@ def _get_format_datetime64(
1557
1559
1558
1560
1559
1561
def _get_format_datetime64_from_values (
1560
- values : Union [ndarray , DatetimeArray , DatetimeIndex ], date_format : Optional [str ]
1562
+ values : Union [np . ndarray , DatetimeArray , DatetimeIndex ], date_format : Optional [str ]
1561
1563
) -> Optional [str ]:
1562
1564
""" given values and a date_format, return a string format """
1563
1565
@@ -1589,7 +1591,7 @@ def _format_strings(self) -> List[str]:
1589
1591
class Timedelta64Formatter (GenericArrayFormatter ):
1590
1592
def __init__ (
1591
1593
self ,
1592
- values : Union [ndarray , TimedeltaIndex ],
1594
+ values : Union [np . ndarray , TimedeltaIndex ],
1593
1595
nat_rep : str = "NaT" ,
1594
1596
box : bool = False ,
1595
1597
** kwargs
@@ -1598,16 +1600,15 @@ def __init__(
1598
1600
self .nat_rep = nat_rep
1599
1601
self .box = box
1600
1602
1601
- def _format_strings (self ) -> ndarray :
1603
+ def _format_strings (self ) -> List [ str ] :
1602
1604
formatter = self .formatter or _get_format_timedelta64 (
1603
1605
self .values , nat_rep = self .nat_rep , box = self .box
1604
1606
)
1605
- fmt_values = np .array ([formatter (x ) for x in self .values ])
1606
- return fmt_values
1607
+ return [formatter (x ) for x in self .values ]
1607
1608
1608
1609
1609
1610
def _get_format_timedelta64 (
1610
- values : Union [ndarray , TimedeltaIndex , TimedeltaArray ],
1611
+ values : Union [np . ndarray , TimedeltaIndex , TimedeltaArray ],
1611
1612
nat_rep : str = "NaT" ,
1612
1613
box : bool = False ,
1613
1614
) -> Callable :
@@ -1652,11 +1653,11 @@ def _formatter(x):
1652
1653
1653
1654
1654
1655
def _make_fixed_width (
1655
- strings : Union [ ndarray , List [str ] ],
1656
+ strings : List [str ],
1656
1657
justify : str = "right" ,
1657
1658
minimum : Optional [int ] = None ,
1658
1659
adj : Optional [TextAdjustment ] = None ,
1659
- ) -> Union [ ndarray , List [str ] ]:
1660
+ ) -> List [str ]:
1660
1661
1661
1662
if len (strings ) == 0 or justify == "all" :
1662
1663
return strings
@@ -1684,7 +1685,7 @@ def just(x):
1684
1685
return result
1685
1686
1686
1687
1687
- def _trim_zeros_complex (str_complexes : ndarray , na_rep : str = "NaN" ) -> List [str ]:
1688
+ def _trim_zeros_complex (str_complexes : np . ndarray , na_rep : str = "NaN" ) -> List [str ]:
1688
1689
"""
1689
1690
Separates the real and imaginary parts from the complex number, and
1690
1691
executes the _trim_zeros_float method on each of those.
@@ -1696,7 +1697,7 @@ def _trim_zeros_complex(str_complexes: ndarray, na_rep: str = "NaN") -> List[str
1696
1697
1697
1698
1698
1699
def _trim_zeros_float (
1699
- str_floats : Union [ndarray , List [str ]], na_rep : str = "NaN"
1700
+ str_floats : Union [np . ndarray , List [str ]], na_rep : str = "NaN"
1700
1701
) -> List [str ]:
1701
1702
"""
1702
1703
Trims zeros, leaving just one before the decimal points if need be.
@@ -1760,7 +1761,7 @@ def __init__(self, accuracy: Optional[int] = None, use_eng_prefix: bool = False)
1760
1761
self .accuracy = accuracy
1761
1762
self .use_eng_prefix = use_eng_prefix
1762
1763
1763
- def __call__ (self , num : Union [float64 , int , float ]) -> str :
1764
+ def __call__ (self , num : Union [int , float ]) -> str :
1764
1765
""" Formats a number in engineering notation, appending a letter
1765
1766
representing the power of 1000 of the original number. Some examples:
1766
1767
@@ -1840,7 +1841,7 @@ def set_eng_float_format(accuracy: int = 3, use_eng_prefix: bool = False) -> Non
1840
1841
set_option ("display.column_space" , max (12 , accuracy + 9 ))
1841
1842
1842
1843
1843
- def _binify (cols : List [int32 ], line_width : Union [int32 , int ]) -> List [int ]:
1844
+ def _binify (cols : List [np . int32 ], line_width : Union [np . int32 , int ]) -> List [int ]:
1844
1845
adjoin_width = 1
1845
1846
bins = []
1846
1847
curr_width = 0
0 commit comments