All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S6900.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

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:

  1. As an array of 7 1 or 0 values, e.g. [1, 1, 1, 1, 1, 0, 0]
  2. As a string of 7 1 or 0 characters, e.g. "1111100"
  3. 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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy