org.sonar.l10n.py.rules.python.S6900.html Maven / Gradle / Ivy
This rule raises an issue when a numpy
weekmask format is incorrect.
Why is this an issue?
To allow a datetime to be used in contexts where only certain days of the week are valid, NumPy includes a set of business day functions.
Weekmask
is used to customize valid business days.
Weekmask
can be specified in several formats:
- As an array of 7
1
or 0
values, e.g. [1, 1, 1, 1, 1, 0, 0]
- As a string of 7
1
or 0
characters, e.g. "1111100"
- As a string with abbreviations of valid days from this list:
Mon Tue Wed Thu Fri Sat Sun
, e.g. "Mon Tue Wed Thu Fri"
Setting an incorrect weekmask
leads to ValueError
.
How to fix it
Provide a weekmask
with correct values.
Code examples
Noncompliant code example
import numpy as np
offset = np.busday_offset('2012-05', 1, roll='forward', weekmask='01') # Noncompliant: ValueError
Compliant solution
import numpy as np
offset = np.busday_offset('2012-05', 1, roll='forward', weekmask='0111100') # OK
Resources
Documentation
- Numpy documentation - Business Day
Functionality
- Numpy documentation - Custom Weekmasks
© 2015 - 2024 Weber Informatics LLC | Privacy Policy