MCPcopy Create free account
hub / github.com/numpy/numpy / DatetimeFormat

Class DatetimeFormat

numpy/core/arrayprint.py:1304–1333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1302
1303
1304class DatetimeFormat(_TimelikeFormat):
1305 def __init__(self, x, unit=None, timezone=None, casting='same_kind',
1306 legacy=False):
1307 # Get the unit from the dtype
1308 if unit is None:
1309 if x.dtype.kind == 'M':
1310 unit = datetime_data(x.dtype)[0]
1311 else:
1312 unit = 's'
1313
1314 if timezone is None:
1315 timezone = 'naive'
1316 self.timezone = timezone
1317 self.unit = unit
1318 self.casting = casting
1319 self.legacy = legacy
1320
1321 # must be called after the above are configured
1322 super().__init__(x)
1323
1324 def __call__(self, x):
1325 if self.legacy <= 113:
1326 return self._format_non_nat(x)
1327 return super().__call__(x)
1328
1329 def _format_non_nat(self, x):
1330 return "'%s'" % datetime_as_string(x,
1331 unit=self.unit,
1332 timezone=self.timezone,
1333 casting=self.casting)
1334
1335
1336class TimedeltaFormat(_TimelikeFormat):

Callers 1

_get_formatdictFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected