Skip to content

Commit 794ed5a

Browse files
committed
Add missing types
1 parent d20aefa commit 794ed5a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pandas/io/formats/csvs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
npt,
5151
)
5252

53+
from pandas.core.series import Series
54+
5355
from pandas.io.formats.format import DataFrameFormatter
5456

5557

@@ -317,7 +319,7 @@ def _save_body(self) -> None:
317319

318320
# tz-aware CSV formatting helper
319321
@staticmethod
320-
def _csv_format_datetime_tz_ea(ser, na_rep: str):
322+
def _csv_format_datetime_tz_ea(ser: Series, na_rep: str) -> Series:
321323
"""
322324
Consistent tz-aware formatting for ExtensionArray datetimes:
323325
'YYYY-MM-DD HH:MM:SS.ffffff+HH:MM'
@@ -329,7 +331,7 @@ def _csv_format_datetime_tz_ea(ser, na_rep: str):
329331

330332
# tz-aware CSV formatting helper
331333
@staticmethod
332-
def _csv_format_py_tz_aware_obj(ser, na_rep: str):
334+
def _csv_format_py_tz_aware_obj(ser: Series, na_rep: str) -> Series:
333335
"""
334336
For object-dtype Series containing stdlib tz-aware datetimes, render
335337
with microseconds and colonized offset. Leave other objects untouched.
@@ -340,11 +342,10 @@ def _csv_format_py_tz_aware_obj(ser, na_rep: str):
340342
vals = ser.to_numpy(object, copy=False)
341343

342344
def _is_tzaware_dt(x: object) -> bool:
343-
return (
344-
isinstance(x, _pydatetime)
345-
and getattr(x, "tzinfo", None) is not None
346-
and x.tzinfo.utcoffset(x) is not None
347-
)
345+
if not isinstance(x, _pydatetime):
346+
return False
347+
tz = getattr(x, "tzinfo", None)
348+
return tz is not None and tz.utcoffset(x) is not None
348349

349350
mask = np.fromiter(
350351
(_is_tzaware_dt(x) for x in vals), dtype=bool, count=len(vals)

0 commit comments

Comments
 (0)