demetrapy
demetrapy is a Python toolkit for the seasonal-adjustment procedures in
JDemetra+. It provides a Python
API for individual and pandas-based workflows, a command-line interface, and
an interactive dashboard. Calculations use the JDemetra+ X13 and TRAMO/SEATS
implementations through JPype; neither procedure is reimplemented in Python.
The package is intended for empirical work in which adjustment specifications must be recorded, repeated, and applied to several series. It accepts regular monthly, quarterly, half-yearly, and yearly observations. Calendar effects, intervention variables, outliers, ARIMA specifications, forecasts, and the principal decomposition options can be set in code or in a JSON file.
Seasonal adjustment is an inferential procedure, not merely a filter applied
to a column of numbers. Results depend on the transformation, regression
effects, ARIMA model, decomposition method, and span of the sample. Published
series should therefore be accompanied by their specification and revision
policy. demetrapy exposes JDemetra+ diagnostics and processing messages for
this purpose, but it does not decide whether a specification is economically
appropriate.
Installation
demetrapy requires Python 3.9 or later and Java 8 or later.
python -m pip install demetrapy
For development from a clone:
python -m venv .venv
source .venv/bin/activate
python -m pip install -e .
The first calculation downloads the pinned demetra-tstoolkit 2.2.6 JAR from
Maven Central and stores it in ~/.cache/demetrapy. Set DEMETRAPY_JAR to the
path of a local copy when automatic download is not suitable. The
Windows guide
covers Command Prompt, proxy-restricted, and
offline installations.
Python interface
For a pandas object with a regular DatetimeIndex, adjust_dataframe()
infers the observation frequency and adjusts each column separately:
import pandas as pd
from demetrapy import adjust_dataframe
data = pd.DataFrame(
{"production": observations},
index=pd.date_range("2015-01-01", periods=len(observations), freq="MS"),
)
result = adjust_dataframe(data, method="x13", spec="RSA4")
adjusted = result[("production", "sa")]
The lower-level adjust() function accepts one regular sequence and an
explicit starting period:
from demetrapy import adjust
result = adjust(
values,
frequency="Quarterly",
start_year=2005,
start_period=1,
method="tramoseats",
spec="RSA4",
)
adjusted = result["sa"]
By default, both functions return the five compact components used in routine work:
| Name | Series |
|---|---|
y |
observed series |
sa |
seasonally adjusted series |
t |
trend-cycle |
s |
seasonal component |
i |
irregular component |
Set detailed=True when the calculation must retain the full JDemetra+ result
dictionary, diagnostics, processing messages, forecasts, backcasts, and fitted
ARIMA model:
detailed = adjust(
values,
frequency="Monthly",
start_year=2015,
forecast_horizon=12,
detailed=True,
)
print(detailed.arima_model.notation)
forecast = detailed.series["final.sa_f"]
Command line
The command-line interface reads a regular CSV file with date and value columns:
date,value
2019-01-01,101.2
2019-02-01,103.8
The default calculation is monthly X13 with the RSA4 preset:
demetrapy input.csv --output adjusted.csv
A JSON file records a fuller specification:
demetrapy \
--data input.csv \
--config examples/full_config.json \
--output adjusted.csv
The output contains y, sa, t, s, and i, aligned with the input dates.
See the usage guide
for the complete command-line and Python API.
Specifications and regressors
The package constructs an isolated JDemetra+ processing context for each calculation. Preset defaults remain those of JDemetra+ unless an option is overridden explicitly.
| Area | Available controls |
|---|---|
| Methods | X13 and TRAMO/SEATS presets |
| RegARIMA | transformation, explicit ARIMA, automatic model selection, estimation controls |
| Calendar | built-in trading days, working days, leap year, Easter, and UserDefined variables |
| Regression | user variables, fixed coefficients, interventions, and ramps |
| Outliers | prespecified and automatic detection |
| Decomposition | X11 filters and limits; SEATS approximation and boundary controls |
| Output | forecasts, backcasts, benchmarking, diagnostics, and processing messages |
UserDefined trading-day variables follow the distinction made in the JDemetra+ graphical interface: a calendar pool may contain several registered series while each target selects only the variables relevant to its own equation. The target observations and calendar pool may be supplied as separate DataFrames, provided their frequencies agree and the calendar domain covers the estimation sample.
The configuration reference documents processing order, valid option groups, preset behavior, and result semantics.
Inspection
A static summary plot can be produced from the command line:
demetrapy --data input.csv --plot-output adjustment.png
The local dashboard is included in the standard installation:
demetrapy-dashboard
It accepts observation, configuration, and calendar-pool files and reports the adjusted series together with diagnostics, model information, processing messages, and downloadable results. The dashboard is a convenient inspection tool; it uses the same calculation path as the Python and command-line interfaces.
Examples
| Example | Subject |
|---|---|
| automatic_arima_example.py | automatic model selection with both methods |
| explicit_arima_example.py | prespecified seasonal ARIMA models |
| quarterly_example.py | quarterly frequency inference and period-four seasonality |
| compare_methods.py | component-wise X13 and TRAMO/SEATS comparison |
| dataframe_user_variables_example.py | multiple targets and a separate calendar pool |
| full_tramoseats_user_calendar_example.py | detailed TRAMO/SEATS specification with UserDefined trading days |
| RETAIL_CASE_STUDY.md | reproducible multi-series case study |
| dashboard files | ready-to-upload dashboard inputs |
Reproducibility and compatibility
The compact result schema is versioned, and the supported Python, Java, and JDemetra+ combinations are stated in the compatibility policy. Tests use both processing engines and include synthetic seasonal and calendar effects with known structure. CI runs on Linux, Windows, and macOS.
python -m unittest discover -s tests
demetrapy is an independent interface to JDemetra+ and is not an official
publication of the JDemetra+ project.
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 demetrapy-0.1.5.tar.gz.
File metadata
- Download URL: demetrapy-0.1.5.tar.gz
- Upload date:
- Size: 45.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c523c8af301a414586f28c5f9dbd95942ed5e5d505eb6211fffff195e056a53c
|
|
| MD5 |
096931a3d187c003a7eaf94d4658962e
|
|
| BLAKE2b-256 |
608f14ba7d4ed5038d0fe76c2f883031a6116d16d4d7a1d56af88e031794e576
|
File details
Details for the file demetrapy-0.1.5-py3-none-any.whl.
File metadata
- Download URL: demetrapy-0.1.5-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b605638837c80614ef4702ffca866a4fd05a442ef143447470d376158df7aff
|
|
| MD5 |
fc295f90151bf42e6b1c3ff428968168
|
|
| BLAKE2b-256 |
f31319065f31c54ab7d2c70b1e6c752cba2f9858dbc063b07b03f3fff64447fb
|