33imports, timestamp parsing and plotting.
44"""
55import datetime
6- import typing
76import warnings
87from collections .abc import Iterable
9- from typing import Literal , Optional , Sequence , Tuple
8+ from typing import List , Literal , Optional , Sequence , Tuple
109
1110import matplotlib
1211import numpy
@@ -52,7 +51,7 @@ def __getattr__(self, attr):
5251 pm = ImportWarner ("pymc" )
5352
5453
55- def parse_datetime (s : typing . Optional [str ]) -> typing . Optional [datetime .datetime ]:
54+ def parse_datetime (s : Optional [str ]) -> Optional [datetime .datetime ]:
5655 """Parses a timezone-aware datetime formatted like 2020-08-05T13:37:00Z.
5756
5857 Returns
@@ -65,7 +64,7 @@ def parse_datetime(s: typing.Optional[str]) -> typing.Optional[datetime.datetime
6564 return datetime .datetime .strptime (s .replace ("Z" , "+0000" ), "%Y-%m-%dT%H:%M:%S%z" )
6665
6766
68- def format_datetime (dt : typing . Optional [datetime .datetime ]) -> typing . Optional [str ]:
67+ def format_datetime (dt : Optional [datetime .datetime ]) -> Optional [str ]:
6968 """Formats a datetime like 2020-08-05T13:37:00Z.
7069
7170 Returns
@@ -176,7 +175,9 @@ def plot_norm_band(ax, independent, mu, scale):
176175 return artists
177176
178177
179- def plot_t_band (ax , independent , mu , scale , df , * , residual_type : typing .Optional [str ] = None ):
178+ def plot_t_band (
179+ ax , independent , mu , scale , df , * , residual_type : Optional [Literal ["absolute" , "relative" ]] = None
180+ ):
180181 """Helper function for plotting the 68, 90 and 95 % likelihood-bands of a t-distribution.
181182
182183 Parameters
@@ -241,7 +242,9 @@ def plot_t_band(ax, independent, mu, scale, df, *, residual_type: typing.Optiona
241242 return artists
242243
243244
244- def plot_continuous_band (ax , independent , model , residual_type : typing .Optional [str ] = None ):
245+ def plot_continuous_band (
246+ ax , independent , model , residual_type : Optional [Literal ["absolute" , "relative" ]] = None
247+ ):
245248 """Helper function for plotting the 68, 90 and 95 % likelihood-bands of a univariate distribution.
246249
247250 Parameters
@@ -364,9 +367,9 @@ def plot_model(
364367 * ,
365368 fig : Optional [matplotlib .figure .Figure ] = None ,
366369 axs : Optional [Sequence [matplotlib .axes .Axes ]] = None ,
367- residual_type = "absolute" ,
370+ residual_type : Literal [ "absolute" , "relative" ] = "absolute" ,
368371 band_xlim : Tuple [Optional [float ], Optional [float ]] = (None , None ),
369- ):
372+ ) -> Tuple [ matplotlib . figure . Figure , List [ matplotlib . axes . Axes ]] :
370373 """Makes a plot of the model with its data.
371374
372375 Parameters
@@ -416,6 +419,8 @@ def plot_model(
416419 axs .append (fig .add_subplot (gs1 [0 , 1 ], sharey = axs [0 ]))
417420 pyplot .setp (axs [1 ].get_yticklabels (), visible = False )
418421 axs .append (fig .add_subplot (gs2 [0 , 2 ]))
422+ else :
423+ axs = list (axs )
419424
420425 # ======= Left =======
421426 # Untransformed, outer range
0 commit comments