a utility module for lead time analysis in procurement & logistic division mineral alam abadi
Project description
Lead Time Utils
a utility module for lead time analysis, specifically designed for handling business logic related to date calculations and constraints internally in procurement & logistic division mineral alam abadi.
Installation
pip install leadtimeutils
Quick Start
import pandas as pd
import numpy as np
import leadtimeutils as ltu
Available Functions
has_weekday_in_range()
Checks whether a specific weekday occurs within a date range, with a minimum number of days after the start date.
Signature:
has_weekday_in_range(
df: pd.DataFrame,
start_date_col: str,
end_date_col: str,
chosen_day: int,
main_days: int
) -> np.ndarray
Parameters:
df(pd.DataFrame): DataFrame containing the date columnsstart_date_col(str): Name of the start date columnend_date_col(str): Name of the end date columnchosen_day(int): Weekday to check for (0=Monday, 1=Tuesday, ..., 6=Sunday)main_days(int): Minimum number of days after start_date before checking for the weekday
Returns:
np.ndarray: Boolean array indicating whether the condition is met for each row
Behavior:
- Returns
Trueif the chosen weekday occurs betweenstart_date + main_daysandend_date - Returns
Falseif the end_date itself is the chosen weekday - Handles invalid dates gracefully (returns
Falsefor those rows)
get_days_between()
Returns a list of day names between two dates for each row.
Signature:
get_days_between(
df: pd.DataFrame,
start_date_col: str,
end_date_col: str
) -> np.ndarray
Parameters:
df(pd.DataFrame): DataFrame containing the date columnsstart_date_col(str): Name of the start date columnend_date_col(str): Name of the end date column
Returns:
np.ndarray: Object array where each element is a list of day names (e.g.,['Monday', 'Tuesday', ...])
Usage Examples
Example 1: Check for Thursday After 5 Days
import pandas as pd
import leadtimeutils as ltu
df = pd.DataFrame({
'start': ['2023-10-01', '2023-10-05'],
'end': ['2023-10-15', '2023-10-08']
})
# Check if Thursday (day 3) occurs at least 5 days after start
results = ltu.has_weekday_in_range(df, 'start', 'end', chosen_day=3, main_days=5)
print(results) # [True, False]
Example 2: Check for Monday After 7 Days
df = pd.DataFrame({
'first_date': ['2023-11-01', '2023-11-10'],
'end_date': ['2023-11-15', '2023-11-20']
})
# Check if Monday (day 0) occurs at least 7 days after order
results = ltu.has_weekday_in_range(df, 'first_date', 'end_date', chosen_day=0, main_days=7)
print(results)
Example 3: Check for Friday After 3 Days
df = pd.DataFrame({
'first_date': ['2023-12-01'],
'end_date': ['2023-12-10']
})
# Check if Friday (day 4) occurs at least 3 days after request
results = ltu.has_weekday_in_range(df, 'first_date', 'end_date', chosen_day=4, main_days=3)
print(results)
Example 4: Get All Days Between Dates
df = pd.DataFrame({
'first_date': ['2023-10-01'],
'end_date': ['2023-10-05']
})
day_lists = ltu.get_days_between(df, 'first_date', 'end_date')
print(day_lists[0]) # ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday']
Weekday Reference
Use these values for the chosen_day parameter:
| Day | Value |
|---|---|
| Monday | 0 |
| Tuesday | 1 |
| Wednesday | 2 |
| Thursday | 3 |
| Friday | 4 |
| Saturday | 5 |
| Sunday | 6 |
Migration Guide (v0.1.x → v0.2.0)
Breaking Changes
The hardcoded has_thursday_after_5_days() functions have been replaced with a flexible has_weekday_in_range() function.
Old (v0.1.x):
# Scalar version
result = ltu.has_thursday_after_5_days(start, end)
# Vectorized version
results = ltu.has_thursday_after_5_days_vectorized(df, 'start_col', 'end_col')
New (v0.2.0):
# Unified vectorized function
results = ltu.has_weekday_in_range(df, 'start_col', 'end_col', chosen_day=3, main_days=5)
Migration Steps
- Replace
has_thursday_after_5_days_vectorized()calls withhas_weekday_in_range() - Add
chosen_day=3(for Thursday) andmain_days=5parameters - For scalar checks, create a single-row DataFrame first
License
MIT License - see LICENSE file for details.
Author
Fajar Amry (nagabonar27)
Email: faajaramry@gmail.com
Repository
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leadtimeutils-0.2.0.tar.gz.
File metadata
- Download URL: leadtimeutils-0.2.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fda5aa8d4a399cb3f486be3ed81e567c599ef76edb6acc71e0dbe19101b1f827
|
|
| MD5 |
9ffa61fce39b2e4a4c87709a9c0a6122
|
|
| BLAKE2b-256 |
ec709e8720d755f68ececfaa791f001b8803154747378ad7b250d3f77b164664
|
File details
Details for the file leadtimeutils-0.2.0-py3-none-any.whl.
File metadata
- Download URL: leadtimeutils-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad294bb525ebd9ee745c61538e851db8357a875e433c96a84ee52bc883858f08
|
|
| MD5 |
1d70e353230b1700548341eabe225d5b
|
|
| BLAKE2b-256 |
ddaa21040106788a8ef1daefdfdb778aff93e011af64841ba13bdab80d3e0112
|