@@ -397,37 +397,30 @@ def __init__(
397
397
398
398
>>> dm = dm()
399
399
400
- Explore the results, starting with how much load could not be met.
401
-
402
- >>> dm.lost_load().collect() # doctest: +NORMALIZE_WHITESPACE
403
- shape: (1, 2)
404
- ┌─────────────┬───────┐
405
- │ category ┆ count │
406
- │ --- ┆ --- │
407
- │ cat ┆ u32 │
408
- ╞═════════════╪═══════╡
409
- │ (-inf, 0.0] ┆ 8784 │
410
- └─────────────┴───────┘
400
+ Explore the results, starting with how much load could not be met. The results
401
+ are now returned as :class:`polars.LazyFrame` so `collect()` must be called on
402
+ them to see the results. We convert to :class:`pandas.DataFrame` to show how
403
+ that would be done.
404
+
405
+ >>> dm.lost_load().collect().to_pandas() # doctest: +NORMALIZE_WHITESPACE
406
+ category count
407
+ 0 (-inf, 0.0] 8784
411
408
412
409
Generate a full, combined output of all resources at specified frequency.
413
410
414
- >>> dm.full_output(freq="YS").collect() # doctest: +NORMALIZE_WHITESPACE
415
- shape: (9, 28)
416
- ┌──────────────┬──────────────┬─────────────┬─────────────────────┬───┬─────────────┬──────────────┬───────────────┬─────────┐
417
- │ plant_id_eia ┆ generator_id ┆ capacity_mw ┆ datetime ┆ … ┆ gridcharge ┆ duration_hrs ┆ roundtrip_eff ┆ reserve │
418
- │ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
419
- │ i32 ┆ str ┆ f64 ┆ datetime[μs] ┆ ┆ f32 ┆ i64 ┆ f64 ┆ f64 │
420
- ╞══════════════╪══════════════╪═════════════╪═════════════════════╪═══╪═════════════╪══════════════╪═══════════════╪═════════╡
421
- │ 0 ┆ curtailment ┆ null ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
422
- │ 0 ┆ deficit ┆ null ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
423
- │ 1 ┆ 1 ┆ 350.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
424
- │ 1 ┆ 2 ┆ 500.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
425
- │ 2 ┆ 1 ┆ 600.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
426
- │ 5 ┆ 1 ┆ 500.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
427
- │ 5 ┆ es ┆ 250.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ 3031.205566 ┆ 4 ┆ 0.9 ┆ 0.0 │
428
- │ 6 ┆ 1 ┆ 500.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ null ┆ null ┆ null ┆ null │
429
- │ 7 ┆ 1 ┆ 200.0 ┆ 2020-01-01 00:00:00 ┆ … ┆ 184.283997 ┆ 12 ┆ 0.5 ┆ 0.0 │
430
- └──────────────┴──────────────┴─────────────┴─────────────────────┴───┴─────────────┴──────────────┴───────────────┴─────────┘
411
+ >>> dm.full_output(freq="YS").collect().to_pandas() # doctest: +NORMALIZE_WHITESPACE
412
+ plant_id_eia generator_id capacity_mw ... duration_hrs roundtrip_eff reserve
413
+ 0 0 curtailment NaN ... NaN NaN NaN
414
+ 1 0 deficit NaN ... NaN NaN NaN
415
+ 2 1 1 350.0 ... NaN NaN NaN
416
+ 3 1 2 500.0 ... NaN NaN NaN
417
+ 4 2 1 600.0 ... NaN NaN NaN
418
+ 5 5 1 500.0 ... NaN NaN NaN
419
+ 6 5 es 250.0 ... 4.0 0.9 0.0
420
+ 7 6 1 500.0 ... NaN NaN NaN
421
+ 8 7 1 200.0 ... 12.0 0.5 0.0
422
+ <BLANKLINE>
423
+ [9 rows x 28 columns]
431
424
"""
432
425
if not name and "balancing_authority_code_eia" in dispatchable_specs :
433
426
name = dispatchable_specs .balancing_authority_code_eia .mode ().iloc [0 ]
@@ -636,8 +629,9 @@ def _add_optional_cols(df: pd.DataFrame, df_name) -> pd.DataFrame:
636
629
def __getstate__ (self ):
637
630
state = {}
638
631
for name in self .__slots__ :
639
- if all ((hasattr (self , name ), name not in ("_cached" , "dt_idx" ))):
632
+ if all ((hasattr (self , name ), name not in ("_cached" , "dt_idx" , "_polars" ))):
640
633
state [name ] = getattr (self , name )
634
+ state ["polars_state" ] = self ._polars .__getstate__ ()
641
635
if not self .redispatch .collect ().is_empty ():
642
636
for df_name in ("full_output" , "load_summary" ):
643
637
try :
@@ -653,6 +647,8 @@ def __setstate__(self, state: tuple[Any, dict]):
653
647
setattr (self , k , v )
654
648
self .dt_idx = self .load_profile .index
655
649
self ._cached = {}
650
+ self ._polars = IDConverter .__new__ (IDConverter )
651
+ self ._polars .__setstate__ (state ["polars_state" ])
656
652
657
653
@classmethod
658
654
def from_patio (cls , * args , ** kwargs ) -> DispatchModel :
0 commit comments