| 1398 | |
| 1399 | |
| 1400 | class DatetimeFormat(_TimelikeFormat): |
| 1401 | def __init__(self, x, unit=None, timezone=None, casting='same_kind', |
| 1402 | legacy=False): |
| 1403 | # Get the unit from the dtype |
| 1404 | if unit is None: |
| 1405 | if x.dtype.kind == 'M': |
| 1406 | unit = datetime_data(x.dtype)[0] |
| 1407 | else: |
| 1408 | unit = 's' |
| 1409 | |
| 1410 | if timezone is None: |
| 1411 | timezone = 'naive' |
| 1412 | self.timezone = timezone |
| 1413 | self.unit = unit |
| 1414 | self.casting = casting |
| 1415 | self.legacy = legacy |
| 1416 | |
| 1417 | # must be called after the above are configured |
| 1418 | super().__init__(x) |
| 1419 | |
| 1420 | def __call__(self, x): |
| 1421 | if self.legacy <= 113: |
| 1422 | return self._format_non_nat(x) |
| 1423 | return super().__call__(x) |
| 1424 | |
| 1425 | def _format_non_nat(self, x): |
| 1426 | datetime_str = datetime_as_string(x, |
| 1427 | unit=self.unit, |
| 1428 | timezone=self.timezone, |
| 1429 | casting=self.casting) |
| 1430 | return f"'{datetime_str}'" |
| 1431 | |
| 1432 | |
| 1433 | class TimedeltaFormat(_TimelikeFormat): |
no outgoing calls
no test coverage detected
searching dependent graphs…