numpy  2.0.0
src/multiarray/datetime_busdaycal.c File Reference
#include <Python.h>
#include <numpy/arrayobject.h>
#include "npy_config.h"
#include "npy_pycompat.h"
#include "numpy/arrayscalars.h"
#include "lowlevel_strided_loops.h"
#include "_datetime.h"
#include "datetime_busday.h"
#include "datetime_busdaycal.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

Functions

NPY_NO_EXPORT int PyArray_WeekMaskConverter (PyObject *weekmask_in, npy_bool *weekmask)
static int qsort_datetime_compare (const void *elem1, const void *elem2)
NPY_NO_EXPORT void normalize_holidays_list (npy_holidayslist *holidays, npy_bool *weekmask)
NPY_NO_EXPORT int PyArray_HolidaysConverter (PyObject *dates_in, npy_holidayslist *holidays)
static PyObject * busdaycalendar_new (PyTypeObject *subtype, PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds))
static int busdaycalendar_init (NpyBusDayCalendar *self, PyObject *args, PyObject *kwds)
static void busdaycalendar_dealloc (NpyBusDayCalendar *self)
static PyObject * busdaycalendar_weekmask_get (NpyBusDayCalendar *self)
static PyObject * busdaycalendar_holidays_get (NpyBusDayCalendar *self)

Variables

static PyGetSetDef busdaycalendar_getsets []
NPY_NO_EXPORT PyTypeObject NpyBusDayCalendar_Type

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

static void busdaycalendar_dealloc ( NpyBusDayCalendar self) [static]
Clear the holidays
static PyObject* busdaycalendar_holidays_get ( NpyBusDayCalendar self) [static]
Create a date dtype
Allocate a date array (this steals the date_dtype reference)
Copy the holidays
static int busdaycalendar_init ( NpyBusDayCalendar self,
PyObject *  args,
PyObject *  kwds 
) [static]
Clear the holidays if necessary
Reset the weekmask to the default
Parse the parameters
Count the number of business days in a week
Normalize the holidays list

References PyArray_free.

static PyObject* busdaycalendar_new ( PyTypeObject *  subtype,
PyObject *  NPY_UNUSEDargs,
PyObject *  NPY_UNUSEDkwds 
) [static]
Start with an empty holidays list
Set the weekmask to the default
static PyObject* busdaycalendar_weekmask_get ( NpyBusDayCalendar self) [static]
Allocate a 7-element boolean array
Copy the weekmask data
NPY_NO_EXPORT void normalize_holidays_list ( npy_holidayslist holidays,
npy_bool weekmask 
)
Sorts the the array of dates provided in place and removes NaT, duplicates and any date which is already excluded on account of the weekmask.
Returns the number of dates left after removing weekmask-excluded dates.
Sort the dates
Sweep throught the array, eliminating unnecessary values
Skip any NaT or duplicate
Get the day of the week (1970-01-05 is Monday)
If the holiday falls on a possible business day, then keep it.
Adjust the end of the holidays array
NPY_NO_EXPORT int PyArray_HolidaysConverter ( PyObject *  dates_in,
npy_holidayslist holidays 
)
Converts a Python input into a non-normalized list of holidays.

IMPORTANT: This function can't do the normalization, because it doesn't
know the weekmask. You must call 'normalize_holiday_list' on the result before using it.
Make 'dates' into an array
Use the datetime dtype with generic units so it fills it in
This steals the datetime_dtype reference
Allocate the memory for the dates
Cast the data into a raw date array
NPY_NO_EXPORT int PyArray_WeekMaskConverter ( PyObject *  weekmask_in,
npy_bool weekmask 
)
Converts a Python input into a 7-element weekmask, where 0 means weekend and 1 means business day.
Make obj into an ASCII string if it is UNICODE
accept unicode input
Length 7 is a string like "1111100"
a string like "SatSun" or "Mon Tue Wed"
Something like [1,1,1,1,1,0,0]

References PyArray_Check, PyArray_NDIM, PyBytes_AsStringAndSize, and PyBytes_Check.

static int qsort_datetime_compare ( const void *  elem1,
const void *  elem2 
) [static]

Variable Documentation

PyGetSetDef busdaycalendar_getsets[] [static]
Initial value:
 {
    {"weekmask",
        (getter)busdaycalendar_weekmask_get,
        NULL, NULL, NULL},
    {"holidays",
        (getter)busdaycalendar_holidays_get,
        NULL, NULL, NULL},

    {NULL, NULL, NULL, NULL, NULL}
}