CustomDateFormat(pattern)
Source¶
A pattern describing how dates, datetimes or times of day are written as texts, used by TableConversion.
It serves when no DateFormat fits, and for times of day. The pattern uses the codes of Python
datetime.strptime: %d day, %m month, %Y year,
%b short month name, %B full month name, %H hour, %M minute, %S second.
Month names are in English.
Added in version 0.1.0
Parameters:
-
pattern(str)The pattern, such as
"%d %b %Y"for"31 Dec 2026".
Raises:
-
InvalidTypeErrorWhen a setting is not of the type its annotation names.
-
InvalidDateFormatErrorWhen the pattern has no date code (day, month, year) nor time code (hour, minute, second), or has a time zone code (
%z,%Z). A pattern without date only reads or writesTIME, and a pattern with a date never does.
Examples:
import numdaplot as ndp
days = ndp.Table.from_arrays({"day": ndp.Array.from_list(["31 Dec 2026", "1 Feb 2026"])})
days.convert(ndp.TableConversion(columns=["day"], dtype=ndp.Type.DATE, format=ndp.CustomDateFormat("%d %b %Y")))
# day
# DATE
# 0 2026-12-31
# 1 2026-02-01
hours = ndp.Table.from_arrays({"hrmn": ndp.Array.from_list(["1535", "0805"])})
hours.convert(ndp.TableConversion(columns=["hrmn"], dtype=ndp.Type.TIME, format=ndp.CustomDateFormat("%H%M")))
# hrmn
# TIME
# 0 15:35:00
# 1 08:05:00