dfm-python 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dfm_python/__init__.py CHANGED
@@ -34,7 +34,7 @@ Example (High-level API - Recommended):
34
34
 
35
35
  Example (Low-level API - For advanced usage):
36
36
  >>> from dfm_python import DFM, DFMConfig, SeriesConfig
37
- >>> from dfm_python.data_loader import load_data
37
+ >>> from dfm_python.data import load_data # Preferred import
38
38
  >>> # Option 1: Load from YAML
39
39
  >>> config = load_config('config.yaml')
40
40
  >>> # Option 2: Create directly
@@ -50,7 +50,7 @@ Example (Low-level API - For advanced usage):
50
50
  For detailed documentation, see the README.md file and the tutorial notebooks/scripts.
51
51
  """
52
52
 
53
- __version__ = "0.2.4"
53
+ __version__ = "0.2.5"
54
54
 
55
55
  from .config import DFMConfig, SeriesConfig, BlockConfig, Params, DEFAULT_GLOBAL_BLOCK_NAME
56
56
  from .config import (
@@ -62,62 +62,19 @@ from .config import (
62
62
  MergedConfigSource,
63
63
  make_config_source,
64
64
  )
65
- from .data_loader import transform_data
66
- from .dfm import DFMResult, calculate_rmse, diagnose_series, print_series_diagnosis
65
+ from .data import transform_data
66
+ from .dfm import DFMResult
67
+ from .core import calculate_rmse, diagnose_series, print_series_diagnosis
67
68
  from .dfm import DFM as _DFMCore # Core DFM class from dfm.py
68
69
  from .kalman import run_kf, skf, fis, miss_data
69
70
  from .news import update_nowcast, news_dfm, para_const
70
71
 
71
72
  # Import high-level API (extends core DFM with convenience methods)
72
- from .api import DFM, _dfm_instance, from_yaml, from_spec, from_spec_df, from_dict
73
-
74
- # Module-level API: expose singleton instance methods and properties
75
- # This allows: import dfm_python as dfm; dfm.load_config(...); dfm.result
76
- def load_config(
77
- source=None,
78
- *,
79
- yaml=None,
80
- mapping=None,
81
- spec=None,
82
- hydra=None,
83
- base=None,
84
- override=None,
85
- config=None,
86
- ):
87
- """Load configuration (module-level convenience function).
88
-
89
- See DFM.load_config() for parameter documentation.
90
- """
91
- return _dfm_instance.load_config(
92
- source=source,
93
- yaml=yaml,
94
- mapping=mapping,
95
- spec=spec,
96
- hydra=hydra,
97
- base=base,
98
- override=override,
99
- config=config,
100
- )
101
-
102
- def load_data(data_path=None, data=None, **kwargs):
103
- """Load data (module-level convenience function)."""
104
- return _dfm_instance.load_data(data_path=data_path, data=data, **kwargs)
105
-
106
- def train(threshold=None, max_iter=None, **kwargs):
107
- """Train the model (module-level convenience function)."""
108
- return _dfm_instance.train(threshold=threshold, max_iter=max_iter, **kwargs)
109
-
110
- def predict(horizon=12, **kwargs):
111
- """Forecast using the trained model (module-level convenience function)."""
112
- return _dfm_instance.predict(horizon=horizon, **kwargs)
113
-
114
- def plot(**kwargs):
115
- """Plot common visualizations (module-level convenience function)."""
116
- return _dfm_instance.plot(**kwargs)
117
-
118
- def reset():
119
- """Reset state (module-level convenience function)."""
120
- return _dfm_instance.reset()
73
+ # Import module-level convenience functions directly from api.py to avoid duplication
74
+ from .api import (
75
+ DFM, _dfm_instance, from_yaml, from_spec, from_spec_df, from_dict,
76
+ load_config, load_data, train, predict, plot, reset
77
+ )
121
78
 
122
79
  # Expose properties as module-level attributes
123
80
  # Use property-like access via functions or direct attribute access
dfm_python/api.py CHANGED
@@ -23,7 +23,7 @@ import numpy as np
23
23
  import pandas as pd
24
24
 
25
25
  from .config import DFMConfig, Params
26
- from .data_loader import load_data as _load_data
26
+ from .data import load_data as _load_data
27
27
  from .config import (
28
28
  make_config_source,
29
29
  ConfigSource,
@@ -272,7 +272,7 @@ class DFM(_DFMCore):
272
272
  if forecast_horizon is not None and forecast_horizon > 0:
273
273
  Z_fore = self.predict(forecast_horizon, return_series=False, return_factors=True)
274
274
  # Build forecast dates
275
- last_date = time_hist[-1]
275
+ last_date = time_hist.iloc[-1] if hasattr(time_hist, 'iloc') else time_hist[-1]
276
276
  # Use same monthly-end spacing; if freq missing, fallback to monthly-end
277
277
  try:
278
278
  forecast_dates = pd.date_range(start=last_date + pd.tseries.frequencies.to_offset('ME'),
@@ -390,7 +390,7 @@ def from_spec(spec_path: Union[str, Path], params: Optional[Params] = None) -> D
390
390
 
391
391
  def from_spec_df(spec_df: pd.DataFrame, params: Optional[Params] = None) -> DFM:
392
392
  """Load configuration from spec DataFrame (convenience constructor)."""
393
- from .data_loader import _load_config_from_dataframe
393
+ from .data import _load_config_from_dataframe
394
394
 
395
395
  if params is None:
396
396
  params = Params()
@@ -414,7 +414,7 @@ def from_dict(mapping: Dict[str, Any]) -> DFM:
414
414
 
415
415
  # Expose singleton instance for direct access
416
416
  # Users can access: dfm.config, dfm.data, dfm.result, etc.
417
- __all__ = ['DFM', 'load_config', 'load_data', 'train', 'reset',
417
+ __all__ = ['DFM', 'load_config', 'load_data', 'train', 'predict', 'plot', 'reset',
418
418
  'from_yaml', 'from_spec', 'from_spec_df', 'from_dict']
419
419
 
420
420