Skip to main content

Library with a collection of useful classes and methods to DRY

Project description

Mango Calendar ๐Ÿฅญ๐Ÿ“…

A Python library for working with calendar data, holidays, and date-related features with a focus on Spanish holidays and autonomous communities.

Features โœจ

  • ๐Ÿ‡ช๐Ÿ‡ธ Spanish Holiday Support: Comprehensive support for Spanish national and autonomous community holidays
  • ๐ŸŒ Multi-Country Support: Built on the holidays library for international calendar support
  • ๐Ÿ“Š Flexible Data Formats: Support for both pandas and polars DataFrames
  • ๐Ÿ‹๏ธ Weighted Communities: Assign weights to different autonomous communities
  • ๐Ÿ“ Distance Calculations: Calculate distances to holidays for time-series analysis
  • ๐Ÿ›๏ธ Calendar Events: Support for commercial events like Black Friday
  • ๐Ÿฆ  COVID Lockdown Data: Built-in COVID-19 lockdown period data
  • ๐Ÿ”„ Pivot Functionality: Transform calendar data into pivot tables
  • ๐Ÿ—๏ธ Type Hints: Full type annotation support for better IDE integration

Installation ๐Ÿ“ฆ

# Using pip
pip install mango-calendar

# Using uv (recommended)
uv add mango-calendar

Quick Start ๐Ÿš€

from mango_calendar import get_calendar

# Get Spanish holidays for 2024
holidays_df = get_calendar(country="ES", start_year=2024, end_year=2025)
print(holidays_df.head())

Usage Examples ๐Ÿ“š

Basic Holiday Calendar

from mango_calendar import get_calendar

# Get basic Spanish holidays
holidays = get_calendar(
    country="ES",
    start_year=2024,
    end_year=2025
)
print(holidays[['date', 'name']].head())

Advanced Features

# Get holidays with autonomous communities and weights
holidays_with_communities = get_calendar(
    country="ES",
    start_year=2024,
    end_year=2025,
    communities=True,
    return_weights=True,
    calendar_events=True  # Include Black Friday
)

# Calculate distances to holidays
holidays_with_distances = get_calendar(
    country="ES",
    start_year=2024,
    end_year=2025,
    communities=True,
    return_distances=True,
    distances_config={
        "steps_back": 7,
        "steps_forward": 7
    }
)

Date Utilities

from mango_calendar.date_utils import get_holidays_df, get_covid_lockdowns

# Get holidays in a specific format with window bounds
holidays_polars = get_holidays_df(
    steps_back=3,
    steps_forward=7,
    start_year=2024,
    country="ES",
    output_format="polars"
)

# Get COVID lockdown periods
covid_data = get_covid_lockdowns()

Pivot Calendar Data

# Create a pivot table of holidays
pivot_calendar = get_calendar(
    country="ES",
    start_year=2024,
    end_year=2025,
    communities=True,
    return_weights=True,
    pivot=True,
    pivot_keep_communities=True
)

API Reference ๐Ÿ“–

get_calendar()

Main function to retrieve calendar data.

Parameters:

  • country (str): Country code (default: "ES")
  • start_year (int): Start year for the calendar (default: 2010)
  • end_year (int): End year for the calendar (default: current year + 2)
  • communities (bool): Include autonomous community holidays (default: False)
  • weight_communities (dict): Custom weights for communities
  • calendar_events (bool): Include events like Black Friday (default: False)
  • return_weights (bool): Return community weights (default: None)
  • return_distances (bool): Return distance calculations (default: False)
  • distances_config (dict): Configuration for distance calculations
  • name_transformations (bool): Apply name transformations (default: True)
  • pivot (bool): Return data in pivot format (default: False)
  • pivot_keep_communities (bool): Keep communities when pivoting (default: False)

Returns:

  • pd.DataFrame: Calendar data with requested features

get_holidays_df()

Get holidays dataframe with window bounds.

Parameters:

  • steps_back (int): Days to go back from holiday
  • steps_forward (int): Days to go forward from holiday
  • start_year (int): Start year (default: 2014)
  • country (str): Country code (default: "ES")
  • output_format (str): "polars" or "pandas" (default: "polars")

Development Setup ๐Ÿ”ง

Prerequisites

  • Python 3.12+
  • uv (recommended) or pip

Setup

# Clone the repository
git clone <repository-url>
cd mango_calendar

# Install dependencies
uv sync

# Run tests
python run_tests.py

Project Structure

mango_calendar/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ mango_calendar/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ calendar_features.py
โ”‚       โ””โ”€โ”€ date_utils.py
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_calendar_features.py
โ”‚   โ”œโ”€โ”€ test_date_utils.py
โ”‚   โ””โ”€โ”€ test_init.py
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ README.md

Dependencies

  • holidays>=0.76: Holiday data
  • numpy>=2.3.1: Numerical operations
  • pandas>=2.3.1: Data manipulation
  • polars>=1.31.0: Fast DataFrame operations
  • pyarrow>=20.0.0: Columnar data format
  • pycountry>=24.6.1: Country information
  • unidecode>=1.4.0: Unicode text processing

Code Quality ๐ŸŽฏ

This project uses:

  • Ruff: For linting and code formatting
  • Type hints: Full type annotation support
  • pytest: For testing
  • PEP 8: Code style compliance
  • Docstring conventions: PEP 257 compliance

Contributing ๐Ÿค

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/awesome-feature)
  3. Commit your changes (git commit -m 'Add awesome feature')
  4. Push to the branch (git push origin feature/awesome-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guidelines
  • Add type hints to all functions
  • Write comprehensive docstrings
  • Include tests for new features
  • Run uv run coverage run -m unittest discover -s tests -p "test_*.py" -v before submitting

License ๐Ÿ“„

This project is developed by baobab soluciones (mango@baobabsoluciones.es).

Support ๐Ÿ’ฌ

For questions, issues, or contributions, please contact:


Made with โค๏ธ by baobab soluciones

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mango_calendar-0.1.0a3.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mango_calendar-0.1.0a3-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file mango_calendar-0.1.0a3.tar.gz.

File metadata

  • Download URL: mango_calendar-0.1.0a3.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for mango_calendar-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 b5a4c80e3de146be4713f6e8dafb0b23f84fcf9bb326d81ca70646021b4a974a
MD5 79189058f7b07b4ce7a4298972a8b1a6
BLAKE2b-256 9fc30c34a4961c0937ad353e21f5e9b74bd1d84c8fae11e757b2b023a2e9cfdb

See more details on using hashes here.

File details

Details for the file mango_calendar-0.1.0a3-py3-none-any.whl.

File metadata

File hashes

Hashes for mango_calendar-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 13bb4f91bd70660a95f1b59b5edba0205e4ae15921dbf7ef73dd922f9dd93d21
MD5 d1f8f501e6591baa86463b4b8d948a36
BLAKE2b-256 f94889c443c343c2936f6ba6f440a23c33b19538d0203d5c566a0b5b978dc4f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page