Metadata-Version: 2.4
Name: calculate-age
Version: 0.1.2
Summary: Calculate ages from date columns in Pandas or Polars DataFrames
Author-email: Jeff Rodriguez <jeffrodriguez4321@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Jeff Rodriguez
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/xjefrod99/calculate_age
Project-URL: Source, https://github.com/xjefrod99/calculate_age
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE-MIT
Requires-Dist: pandas>=2.0
Requires-Dist: polars>=0.20
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-xdist; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Dynamic: license-file

# calculate-age

[![PyPI version](https://badge.fury.io/py/calculate-age.svg)](https://pypi.org/project/calculate-age/)

Calculate ages from date columns in Pandas/Polars DataFrames.

## Install
```bash
pip install calculate-age
```

## Usage


### Accessor API (chainable)
```python
import pandas as pd
import polars as pl
import calculate_age  # registers accessors on import

#init a df
df = pd.DataFrame({
    "name":       ["Alice", "Bob"],
    "birth_date": pd.to_datetime(["1990-01-01", "2000-06-15"])
})

# Pandas
df = df.calculate_age("birth_date")
# Adds column "age" (whole years vs today)
#    name  birth_date  age
# 0  Alice  1990-01-01   36
# 1  Bob    2000-06-15   25

df = df.calculate_age_indays("birth_date")
# Adds column "age_in_days" (total days vs today)
#    name  birth_date  age_in_days
# 0  Alice  1990-01-01        13223
# 1  Bob    2000-06-15         9374

df = df.calculate_age_exact("birth_date")
# Adds column "age_exact" (years to 2 decimal places vs today)
#    name  birth_date  age_exact
# 0  Alice  1990-01-01      36.20
# 1  Bob    2000-06-15      25.75


# Polars
df_pl = df_pl.calculate_age("birth_date")
df_pl = df_pl.calculate_age_indays("birth_date")
df_pl = df_pl.calculate_age_exact("birth_date")
```

### Function API
```python
import datetime
from calculate_age import calculate_age, calculate_age_indays, calculate_age_exact
import pandas as pd
import polars as pl

# Pandas
df = pd.DataFrame({"birth_date": pd.to_datetime(["1990-01-01"])})
result = calculate_age(df, "birth_date")                              # vs today
result = calculate_age(df, "birth_date", datetipip install buildme.date(2026, 3, 15))  # vs a fixed date
result = calculate_age(df, "birth_date", "hire_date")                 # vs another column
result = calculate_age_indays(df, "birth_date")                       # age in total days
result = calculate_age_exact(df, "birth_date")                        # age in years (2 decimals)

# Polars
df_pl = pl.DataFrame({"birth_date": ["1990-01-01"]}).with_columns(
    pl.col("birth_date").str.strptime(pl.Date, "%Y-%m-%d")
)
result = calculate_age(df_pl, "birth_date")
```
