L iUddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZmZddlmZddlmZddlmZmZddlmZdd lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&ddl'Z'ddl(Z'ddl)Z'ddl*m+cm,Z-dd l.m/Z/dd l0m1Z1ejdd k\r ddlm3Z3m4Z4m5Z5n ddl%m3Z3m4Z4m5Z5er[ddl6m7Z7ddlm8Z8ddl9m:Z:ddl;mZ>m?Z?nddl%m>Z>m?Z?dZ@deAd<eBe'jjZEdeAd<eFeGeEfZHdeAd<dZIdeAd<dZJdeAd <d!aKd"eAd#<ed$ZLdld%ZMdld&ZNejdmd'ZPe$ dnd(d) dod*ZQe$ dn dpd+ZQ dqd!d) drd,ZQ dq dsd-ZRdtd.ZSdud/ZTdvd0ZU dq dwd1ZVdxd2ZW dyd3ZX dzd4ZY d{d5ZZd|d6Z[ d}d7Z\d~d8Z]dyd9Z^dzd:Z_ dzd;Z`dzd<Zadd=Zbdd>Zcdd?Zddd@Ze dq ddAZfGdBdCe'jZge!dDe dEe dFe dGd!HZh e4dIee dJehfehfKZi e5GdLdMeehe3Zje5GdNdOeje dFe3ZkGdPdQZlelZme!dRZne"enelfZodeAdS< ddTZpe$ddVZqe$ddWZqddXZqe$ddYZre$ddZZrdd[ZrGd\d]Zsdd^Zt dd_Zue!d`esaZve!dUeseFeefeBeZw ddbZxddcZyeGezfdd ddeZ{ddfZ|GdgdhZ}GdidjZ~ddkZy)) annotationsN) defaultdict)IterableIteratorMappingSequence)partial)version)chain zip_longest)ceil) TYPE_CHECKINGAnyFinalGenericLiteralTypeVarUnioncastoverload) TypeAlias)Version)vegalite) )Protocol TypeAliasTyperuntime_checkable) ModuleType)ClassVar)Registry) ChartType)r )TypeIs)r )NeverSelfzModuleType | Noner_OptionalModuleValidationErrorListGroupedValidationErrorszurn:vega-lite-schemar_VEGA_LITE_ROOT_URIz'http://json-schema.org/draft-07/schema#_DEFAULT_JSON_SCHEMA_DRAFT_URLTbool DEBUG_MODE jsonschemacday)NTr.[/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/altair/utils/schemapi.pyenable_debug_moder5^sJr3cday)NFr1r2r3r4disable_debug_moder7csJr3c#8Kt}|a d|ay#|awxYwwNr1)argoriginals r4 debug_moder<hs$HJ  X s .) raise_errorcyr9r2specschema rootschemar=s r4validate_jsonschemarCss r3cyr9r2r?s r4rCrC}s47r3ct|||}|r^t|}t|}t|}t |}t t |jd}||_|r||Sy)a' Validates the passed in spec against the schema in the context of the rootschema. If any errors are found, they are deduplicated and prioritized and only the most relevant errors are kept. Errors are then either raised or returned, depending on the value of `raise_error`. rBrN) _get_errors_from_spec_get_leaves_of_error_tree_group_errors_by_json_path#_subset_to_most_specific_json_paths_deduplicate_errorsnextitervalues _all_errors)r@rArBr=errors leaf_errorsgrouped_errors main_errors r4rCrCsx#4J GF /7 3K@<^L,^<tN$9$9$;<=a@ "0    r3ct|xs|}tjjd|i}i}t |dr|j |d<t rt|}t|xs|||d<n&|tjj|nd|d<||fi|}t|j|}|S)z Uses the relevant jsonschema validator to validate the passed in spec against the schema using the rootschema to resolve references. The schema and rootschema themselves are not validated but instead considered as valid. $schemaFORMAT_CHECKERformat_checkerregistryNresolver) _get_json_schema_draft_urlr/ validators validator_forhasattrrV_use_referencing_library_prepare_references_in_schema_get_referencing_registry RefResolver from_schemalist iter_errors)r@rArBjson_schema_draft_url validator_clsvalidator_kwargs validatorrPs r4rGrGs(7z7KVL))77 )*M(*}./-:-I-I)*!.v6'@  &"7( $%  " " . .z : $ f9(89I )''- .F Mr3c.|jdtS)NrU)getr,rAs r4rZrZs ::i!? @@r3c8tttdk\S)zeIn version 4.18.0, the jsonschema package deprecated RefResolver in favor of the referencing library.z4.18)rjsonschema_version_strr2r3r4r^r^s ) *gfo ==r3cNtj|}dfd |}|S)Nc*|jD]~\}}|dk(rt||z||<t|tr |||<7t|tsHg}|D]+}t|tr|}|j |-|||<|S)a Add _VEGA_LITE_ROOT_URI in front of all $ref values. This function recursively iterates through the whole dictionary. $ref values can only be nested in dictionaries or lists as the passed in `d` dictionary comes from the Vega-Lite json schema and in json we only have arrays (-> lists in Python) and objects (-> dictionaries in Python) which we need to iterate through. $ref)itemsr+ isinstancedictrcappend)dkeyvalueprepared_valuesv _prepare_refss r4rzz4_prepare_references_in_schema.._prepare_refss'') )JCf},qv5#E4(&u-#E4("$.A!!T*)!,#**1-.)# )r3)rudict[str, Any]returnr{)copydeepcopy)rArzs @r4r_r_s)]]6 "F26 "F Mr3cddl}ddl}| t|}|jj |}|j |}|j jt|S)Nr)uriresource) referencingreferencing.jsonschemarZr/specification_withcreate_resourcer! with_resourcer+)rBrer specificationrs r4r`r` sh!$ :: F**==>STM,,Z8H    ! / / ( 0 r3cd}|jD]/}t|tr|dt|zdzz }(|d|zz }1|S)z Drop in replacement for the .json_path property of the jsonschema ValidationError class. This is not available as property for ValidationError with jsonschema<4.0.1. More info, see https://github.com/vega/altair/issues/3038. $[].) absolute_pathrrintstr)errpathelems r4 _json_pathr!sT D!! dC C#d)Oc) )D C$J D  Kr3ctt}|D],}t|dt|}||j |.t |S)a% Groups errors by the `json_path` attribute of the jsonschema ValidationError class. This attribute contains the path to the offending element within a chart specification and can therefore be considered as an identifier of an 'issue' in the chart that needs to be fixed. json_path)rrcgetattrrrtrs)rPerrors_by_json_pathrerr_keys r4rIrI2sQ&d+1#{JsO<G$++C01 # $$r3cg}|D]D}|jr%|jt|j4|j|F|S)a0 For each error in `errors`, it traverses down the "error tree" that is generated by the jsonschema library to find and return all "leaf" errors. These are errors which have no further errors that caused it and so they are the most specific errors with the most specific error messages. )contextextendrHrt)rPleavesrs r4rHrHCsJ#%F ;; MM3CKK@ A MM#  Mr3ci}|jD].\}}t|t|jr*|||<0|S)a Removes key (json path), value (errors) pairs where the json path is fully contained in another json path. For example if `errors_by_json_path` has two keys, `$.encoding.X` and `$.encoding.X.tooltip`, then the first one will be removed and only the second one is returned. This is done under the assumption that more specific json paths give more helpful error messages to the user. )rq*_contained_at_start_of_one_of_other_valuesrckeys)rerrors_by_json_path_specificrrPs r4rJrJXsX=? 0668= 69 t/4467 7= ( 3 = ('r3c,tfd|DS)Nc3LK|]}|k7s |jywr9) startswith).0rwxs r4 z=_contained_at_start_of_one_of_other_values..os"Eu!u*u"Es $$)any)rrNs` r4rrls EE EEr3cRi}|jD]\}}t|}ttd}g}|jD]:\}}|j |} | | |}|j t |<|D cgc]} t| r| }} |||<|Scc} w)z Some errors have very similar error messages or are just in general not helpful for a user. This function removes as many of these cases as possible and can be extended over time to handle new cases that come up. )enumadditionalProperties)rq_group_errors_by_validator_deduplicate_enum_errors)_deduplicate_additional_properties_errorsrjr_deduplicate_by_message_is_required_value_error) rRgrouped_errors_deduplicatedrelement_errorserrors_by_validatordeduplication_functionsdeduplicated_errorsrhrPdeduplication_funcrs r4rKrKrs<>%3%9%9%;E! >8H-$M# 46!4!:!:!< H Iv!8!v'F G  H/ 6Ns6SC  2E#I.3E4 '&  s B$B$cD|jdk(xr|jdgk(S)Nrequiredrw)rhvalidator_value)rs r4rrs# ==J & K3+>+>7)+KKr3ctt}|D] }||jj|"t |S)au Groups the errors by the json schema "validator" that casued the error. For example if the error is that a value is not one of an enumeration in the json schema then the "validator" is `"enum"`, if the error is due to an unknown property that was set although no additional properties are allowed then "validator" is `"additionalProperties`, etc. )rrcrhrtrs)rPrrs r4rrsGBMTAR7 CMM*11#6 7 # $$r3ct|dkDr^|Dcgc]}dj|j}}g}t||D]#\}}t ||r|j |%|}|Scc}w)ap Deduplicate enum errors by removing the errors where the allowed values are a subset of another error. For example, if `enum` contains two errors and one has `validator_value` (i.e. accepted values) ["A", "B"] and the other one ["A", "B", "C"] then the first one is removed and the final `enum` list only contains the error with ["A", "B", "C"]. ,)lenjoinrziprrt)rPr value_strings longest_enums value_strs r4rrs~ 6{QCII3#"5"56I I-/ !-8 *NIs=iW$$S) * M Js"A/ct|dkDrF|dj5jdk(r&tfd|ddDrt |dg}|S)a If there are multiple additional property errors it usually means that the offending element was validated against multiple schemas and its parent is a common anyOf validator. The error messages produced from these cases are usually very similar and we just take the shortest one. For example, the following 3 errors are raised for the `unknown` channel option in `alt.X("variety", unknown=2)`: - "Additional properties are not allowed ('unknown' was unexpected)" - "Additional properties are not allowed ('field', 'unknown' were unexpected)" - "Additional properties are not allowed ('field', 'type', 'unknown' were unexpected)". rrNanyOfc3:K|]}|juywr9)parent)rrrs r4rz<_deduplicate_additional_properties_errors..s?SCJJ&(?sc,t|jSr9)rmessage)rs r4z;_deduplicate_additional_properties_errors..sAIIr3)rv)rrrhallmin)rPrs @r4rrs` 6{Q!!    G+?F12J??&&>?@F Mr3cpt|Dcic]}|j|c}jScc}w)zaDeduplicate errors by message. This keeps the original order in case it was chosen intentionally.)rcrrN)rPes r4rrs, v.!A.557 88.s3c#Kt}|h}|r0||z}tjd|D}||z D]}||r/yyw)z=Breadth-first sequence of all classes which inherit from cls.c3NK|]}t|jywr9)set__subclasses__)rclss r4rz_subclasses..s!S#c&8&8&:";!Ss#%N)runion)rseen current_sets r4 _subclassesrsS 5D%K  ii!S{!ST % CI  s >AAc tj|dd}|jS#t$rt |cYSwxYw)NT)strict series_only)nw from_nativeto_list TypeErrorrc)objsers r4_from_array_likers>nnS4@{{} Cys'*AAc|j|j|jd}t|tj r|j tj jk7rK|j}|dk(r|n|dz}|j|j|j|j||jx}r4|tjjurd|d<|Sd|d}t!||S) z Parse native `datetime.(date|datetime)` into a `DateTime`_ schema. .. _DateTime: https://vega.github.io/vega-lite/docs/datetime.html )yearmonthdateri)hoursminutesseconds millisecondsTutczUnsupported timezone z. Only `'UTC'` or naive (local) datetimes are permitted. See https://altair-viz.github.io/user_guide/generated/core/altair.DateTime.html)rrdayrrdtdatetimetimer microsecondupdatehourminutesecondtzinfotimezonerr)rresultusmsrmsgs r4_from_date_datetimers'*hhCGGTF#r{{# 88: $BQwB%KB MMhh CJJUW  ZZ 6 ( $u  M ,F:6ff  n$ Mr3c ||}t||jr|Dcgc]}t||||c}St||jr t |St||j rt |}d|vr|dz }|St|tr|jd|St|ttfr|Dcgc]}t||||c}St|tr8|jDcic]\}}|tur|t||||c}}St|tr|jS|5t||jr|j|j!St#|t t$frtt'||||St|t(j*r t-|S|Scc}wcc}wcc}}w)z+Convert an object to a dict representation.Tz T00:00:00F)validaterexclude)rrndarray_todictnumberfloat datetime64r SchemaBaseto_dictrctuplersrq Undefined SchemaLike Timestamp isoformat _is_iterablebytesrrrr)rrnp_optpd_optnpryrks r4rrs   c2:: &ADEAGAw7E E RYY ':  R]] +XF& +%M#z"{{E7{;; C$ '=@A7FF3AA C   1 ! wq'662 2  C ${{}   30@0@ A$..00 cC< 0',gvvFF C !"3'' 9FB sG G.indent_second_line_onwardsqsf(*N&w}}T':; , T7s4y1}<$.D%%d+ ,99^, ,r3rr)startzError : zMultiple errors were found.  ))rrr-rr|r)rcrrNrt_get_message_for_errors_grouprr+r)r!r1error_messagesrPrerror_idms r4r z"SchemaValidationError._get_messageps -%'4<<..01"15 NF  ! !$"D"DV"L M N ~  "$-^1#EHa+VH:Rs+CDN 8 8G6;;~.. s3B)c|djdk(r$|j|d}|jS|j|}|jS)Nrr)rP)rh(_get_additional_properties_error_message_get_default_error_messagestrip)r!rPrs r4r7z3SchemaValidationError._get_message_for_errors_groups\ !9  "8 8 CCF1ING}}55V5DG}}r3c J|j|}tj|jj }|j |}|j jddjdd}d|jd|d|d|jd }|S) zFOutput all existing parameters when an unknown parameter is specified.z(''r`z` has no parameter named 'z!' Existing parameter names are: z See the help for `z2` to read the full description of these parameters) _get_altair_class_for_errorinspect signature parametersr_format_params_as_tablerr,__name__)r!error altair_clsparam_dict_keysparam_names_tableparameter_namers r4r<z>SchemaValidationError._get_additional_properties_error_messages 55e< !++J7BBGGI 88I ,,T226<kwdsr!Pg?c@||zdzg||zz||zg|||zz zzS)Nrr2)nps r4split_into_equal_partszMSchemaValidationError._format_params_as_table..split_into_equal_partss3FQJ<1q5)Q!VHAE ,BB Br3rc32K|]}t|ywr9)r)r param_names r4rz@SchemaValidationError._format_params_as_table..sN C ONsr@ fillvaluer2rz{:<{}}rr))rWrrXrr|z list[int]) rrmaxrr rrtr r+format)rKname param_names name_lengthsmax_name_lengthmax_column_widthnum_param_namessquare_columnscolumnsrYcolumn_heightsparam_names_columnscolumn_max_widths last_end_idxchparam_names_rowslirLparam_names_rownumr[max_name_length_column column_pads r4rGz-SchemaValidationError._format_params_as_tables %(,//s4y!% ! \l+k*T/3"678&/9>J C0I68')   -B  & &{<,QSBS'T U  $ $N6I"6MNN  ,L  -352AbA (B  # #B ' ("$/ .O#,_#= .Z):3)?& !X__ 6 C&!3/!34%-% . .! csD8c|g}t|}d|vr(|dD] }|jd|j"d|vr|dDcgc]}d|jd}}d}t|dk(r ||dz }n?t|dk(r||dd |dz }n |d j |dd d |d zz }|j||d}d|j d }|j r|d|j d dz }t|dk(r|dz }npt|dk(r |d|ddz }nU|Dcgc]}|dj|ddz}}|dz }|dj |Dcgc]}d| c}z }|dz }d|jD} |dj | z }|Scc}wcc}wcc}w)Nrzone of typerAzof type rrz or z, r@z, or z' is an invalid valuez for `rBz. z. Valid values are z. Valid values are: r)z- r5c3ZK|]#\}}|dvrdjd|D%yw)>rrsr)c34K|]}|jywr9r$)rrs r4rzMSchemaValidationError._get_default_error_message...-s0Aaii0sN)r)rrhrPs r4rzCSchemaValidationError._get_default_error_message..,s4 ! 6 00 II00 0 s)+r2) rrtrrrinstancerrPrq) r!rP bullet_pointsrrIrtypespointrits r4r=z0SchemaValidationError._get_default_error_messages/$& 8@ ( (,V4 H$$wu/D/D.E%FG H ( (;Nv;VWCq,,-Q/WEWE5zQq!UqE!H:T%(445":.5r 1DDD   ' q enn%%:;     3 3B 78: :G }  " w G  1 $ ,]1-=,>eD DGHUUeU1X^^-ab 9UMU 0 0G tyyM!J5Bug,!JK KG v G  %8%>%>%@  2772;UX8V!JsF/1 F4( F9 )rrrzjsonschema.ValidationErrorr|Noner|r)rPr)r|r)rI%jsonschema.exceptions.ValidationErrorr|r)rIr~r|ztype[SchemaBase])rKz Iterable[str]r|r) rH __module__ __qualname__rr&r r7r<rC staticmethodrGr= __classcell__r"s@r4rrPs+82#  4 *: ,6!6!p5#5 5r3r _JSON_VT_costringobjectarray) covariant_TypeMaprs) type_paramsc$eZdZUdZded<ddZy)ra  Represents ``altair`` classes which *may* not derive ``SchemaBase``. Attributes ---------- _schema A single item JSON Schema using the `type`_ keyword. Notes ----- Should be kept tightly defined to the **minimum** requirements for: - Converting into a form that can be validated by `jsonschema`_. - Avoiding calling ``.to_dict()`` on a class external to ``altair``. - ``_schema`` is more accurately described as a ``ClassVar`` - See `discussion`_ for blocking issue. .. _jsonschema: https://github.com/python-jsonschema/jsonschema .. _type: https://json-schema.org/understanding-json-schema/reference/type .. _discussion: https://github.com/python/typing/discussions/1424 z_TypeMap[_JSON_VT_co]_schemacyr9r2)r!argsrTs r4rzSchemaLike.to_dictwsr3N)r|r)rHrr__doc____annotations__rr2r3r4rr[s0#"0r3rc.eZdZUdZded<ddiZded<y) ConditionLikeaW Represents the wrapped state of a conditional encoding or property. Attributes ---------- condition One or more (predicate, statement) pairs which each form a condition. Notes ----- - Can be extended with additional conditions. - *Does not* define a default value, but can be finalized with one. r conditionrsrz_TypeMap[Literal['object']]rN)rHrrrrrr2r3r4rrzs N,2H+=G (=r3rc$eZdZdZdZddZddZy) UndefinedTypez4A singleton object for marking undefined parameters.Nct|j|stj|g|i||_|jSr9)rr_UndefinedType__instancer__new__)rrkwargss r4rzUndefinedType.__new__s4#..#.#^^CA$A&ACN~~r3cy)Nrr2r%s r4__repr__zUndefinedType.__repr__sr3)r|r'r})rHrrrrrrr2r3r4rrs>J r3rrOptionalc|tuS)a Type-safe singleton check for `UndefinedType`. Notes ----- - Using `obj is Undefined` does not narrow from `UndefinedType` in a union. - Due to the assumption that other `UndefinedType`'s could exist. - Current [typing spec advises](https://typing.readthedocs.io/en/latest/spec/concepts.html#support-for-singleton-types-in-unions) using an `Enum`. - Otherwise, requires an explicit guard to inform the type checker. rrs r4 is_undefinedrs ) r3 _CopyImplcyr9r2rs r4 _shallow_copyrs03r3cyr9r2rs r4rrs$'r3ct|tr|jdSt|ttfr|jS|S)NF)deep)rrrr}rcrsrs r4rrs<#z"xxUx## C$ &xxz r3cyr9r2rby_refs r4 _deep_copyrs?Br3cyr9r2rs r4rrs36r3ctt|t|trt |ddx}rt d5||cdddSfd|j D}|jjDcic]\}}|||vr|n|}}}t d5|j|i|cdddSt|tr|Dcgc] }| c}St|tr0|jDcic]\}}|||vr|n|c}}S|S#1swYxYwcc}}w#1swYyxYwcc}wcc}}w)N)r __deepcopy__Fc3.K|] }|ywr9r2)rr:r}s r4rz_deep_copy..s/cS /s) r rrrrrr<_args_kwdsrqr"rcrs)rrcopierrrryrTr}s @r4rrs2 :f -D#z"S.$7 76 7E" #c{ # #/SYY/CF99??CTU41aqDGA5UU   0 3==$/$/ 0 0 C !$%AQ%% C CF99;O41aqDGA5OO  # #V 0 0&Os)D,D8(D>E  E,D5>EceZdZUdZdZded<dZded<dZded <dd Z d dd Z e fd Z fd Z d dZ dZd dZd!dZd"dZ d#ddd d$dZ d%ddd d&dZed'dZe d# d(dZe d# d)dZe d* d+dZed*d,dZe d* d-dZd.fd ZxZS)/rz Base class for schema wrappers. Each derived class should set the _schema class attribute (and optionally the _rootschema class attribute) which is used for validation. NzClassVar[dict[str, Any] | Any]rzClassVar[dict[str, Any] | None] _rootschemaTzClassVar[bool] _class_is_valid_at_instantiationc<|jd|jd}t||rt|dk(sJt|dvsJtj |d|tj |d|t r |jr|jdyyy) Nz"Cannot instantiate object of type z): _schema class attribute is not defined.r>rrrrTr) rr" ValueErrorrr __setattr__r.rr)r!rrTrs r4rzSchemaBase.__init__s << 4T^^4DE  S/ ! t9> !>t9& && 4$/4$/ $?? LL$L '@:r3c `|dur3tdt||rt|StStd5|j|j i|j }dddt|r%|D] }tj|||<"S#1swY;xYw)a Return a copy of the object. Parameters ---------- deep : boolean or list, optional If True (default) then return a deep copy of all dict, list, and SchemaBase objects within the object structure. If False, then only copy the top object. If a list or iterable, then only copy the listed attributes. ignore : list, optional A list of keys for which the contents should not be copied, but only stored by reference. Tr'FN) rrrr<r"rrr r_get)r!rignorer}attrs r4r}zSchemaBase.copys" 4< 4V RS SCE RS S   =!4>>4::< !" 4 73 4s AAAc"||j|<yr9rr!itemvals r4rzSchemaBase.__setattr__C 4r3c |j|Sr9r)r!rs r4 __getitem__zSchemaBase.__getitem__Fszz$r3c"||j|<yr9rrs r4 __setitem__zSchemaBase.__setitem__Irr3ct|j}|jx}rTdt|j D}dj |j dd}d\}}|d|d|d|dS|d|jddS) Nc3BK|]\}}|tus|d|yw)r4Nr)rrrys r4rz&SchemaBase.__repr__..Os%WDAqAYDVQCr!-Ws z, r)z ){}()r)rsrHrsortedrqrreplacer)r!r_rTr{rLBRBs r4rzSchemaBase.__repr__LsDz"":: 4 WF4::<,@WB::b>))$7DFBV1RDTF"RD2 2V1TZZ]-Q/ /r3ct|t|uxr4|j|jk(xr|j|jk(Sr9)rsrr)r!others r4__eq__zSchemaBase.__eq__VsA J$u+ % * ekk) * ekk) r3)rrc|xsi}|xsg}tdd}|jr|js|jd}n|js|jj}h|d}|j ddx}r t ||}|j D cic] \}} ||vs || }}} |jdx} r1t| tr!d | i|d<nt|d } t| t|fd |i|} |r |j| | S| Scc} }w#tj$r} t!|| dd} ~ wwxYw) a Return a dictionary representation of the object. Parameters ---------- validate : bool, optional If True (default), then validate the result against the schema. ignore : list[str], optional A list of keys to ignore. context : dict[str, Any], optional A context dictionary. Raises ------ SchemaValidationError : If ``validate`` and the result does not conform to the schema. Notes ----- - ``ignore``, ``context`` are usually not needed to be specified as a user. - *Technical*: ``ignore`` will **not** be passed to child :meth:`.to_dict()`. numpypandasr rr shorthandparsed_shorthandNmarkrszD instance has both a value and properties : cannot serialize to dictr)_get_optional_modulesrrr}pop_replace_parsed_shorthandrqrjrrrrsrrrr/ValidationErrorr)r!rrroptsrTrparsedrryrrrrs r4rzSchemaBase.to_dict]sU:-R2$GHE ::djj::a=D::??$D,, ,G %7>>v>0>%)ZZ\FTQQg5EAqDFDF(((js.C &~V $ZL deCS/ !7w7$7  A f% v G-- A+D#6D@ As$! D .D  D&&E 9 EE c l|g}|i}|j|||}tj|f||d|S)a Emit the JSON representation for this object as a string. Parameters ---------- validate : bool, optional If True (default), then validate the result against the schema. indent : int, optional The number of spaces of indentation to use. The default is 2. sort_keys : bool, optional If True (default), sort keys in the output. ignore : list[str], optional A list of keys to ignore. context : dict[str, Any], optional A context dictionary. **kwargs Additional keyword arguments are passed to ``json.dumps()`` Raises ------ SchemaValidationError : If ``validate`` and the result does not conform to the schema. Notes ----- - ``ignore``, ``context`` are usually not needed to be specified as a user. - *Technical*: ``ignore`` will **not** be passed to child :meth:`.to_dict()`. )rrr)r- sort_keys)rjsondumps)r!rr-rrrrdcts r4to_jsonzSchemaBase.to_jsonsHL >F ?GllHVWlMzz#Lf LVLLr3c ttS)z6Return the set of classes used within cls.from_dict().)rr)rs r4_default_wrapper_classesz#SchemaBase._default_wrapper_classess:&&r3c~|r|j|t|j}|j||S)a Construct class from a dictionary representation. Parameters ---------- dct : dictionary The dict from which to construct the class validate : boolean If True (default), then validate the input against the schema. Raises ------ jsonschema.ValidationError : If ``validate`` and ``dct`` does not conform to the schema )r _FromDictr from_dict)rrr converters r4rzSchemaBase.from_dicts9&  LL c::<= ""3,,r3c Ttj|fi|}|j||S)a Instantiate the object from a valid JSON string. Parameters ---------- json_string : string The string containing a valid JSON chart specification. validate : boolean If True (default), then validate the input against the schema. **kwargs : Additional keyword arguments are passed to json.loads Returns ------- chart : Chart object The altair Chart object built from the specification. r)rloadsr)r json_stringrrrs r4 from_jsonzSchemaBase.from_jsons*4#jj??}}S8}44r3ct| |j}|Jt|||jxs |jy)zPValidate the instance against the class schema in the context of the rootschema.NrF)rrCr)rrwrAs r4rzSchemaBase.validates7 >[[F!!!Hf9WCKKXr3c||xs |j}|Jt||jxs|jxs|S)zIResolve references in the context of this object's schema or root schema.)rArB)rrr)rrAschema_to_passs r4resolve_referenceszSchemaBase.resolve_referencessC .3;;)))"!@3;;@&  r3ctdd}t|fdii|}|j|xs |jj di}t ||j |i|j xs |jy)zMValidate a property against property schema in the context of the rootschema.rrrr propertiesrFN)rrrrrjrCr)rr_rwrArpropss r4validate_propertyzSchemaBase.validate_propertysr %GHE2r2T2&&v'<=AA,PRS 599T2&3??3Qckk r3cZttt| |jSr9)rr r__dir__r)r!r"s r4rzSchemaBase.__dir__s eEGO-tzz:;;r3)rrrTrr|r|)TN)rzbool | Iterable[Any]rlist[str] | Noner|r'r|r|r})rrr|r-T)rr-rrrdict[str, Any] | Noner|r{)TrtT) rr-r-zint | str | Nonerr-rrrrr|r)r|zIterator[type[SchemaBase]])rtype[TSchemaBase]rr{rr-r| TSchemaBase)rrrr-rrr|r"r9)rwr{rArr|r|)rArr|r{)r_rrwrrArr|r|)r|z list[str])rHrrrrrrrrr}rrrrrrrrrr classmethodrrrrrrrrrs@r4rrs-/3G +237K077;$n;(4MQ(9I 4"+ " 0 5$()- 55! 5 ' 5  5r#$ +M $()-+M+M!+M +M ! +M'+M +MZ''FJ- -%3-?C- --.555 5 558GKY%Y/DY YY  DH    "  ,A      <>> import pandas as pd # doctest: +SKIP >>> import polars as pl # doctest: +SKIP >>> from altair.utils.schemapi import _get_optional_modules # doctest: +SKIP >>> >>> _get_optional_modules(pd="pandas", pl="polars", ibis="ibis") # doctest: +SKIP { "pd": , "pl": , "ibis": None, } If the user later imports ``ibis``, it would appear in subsequent calls. >>> import ibis # doctest: +SKIP >>> >>> _get_optional_modules(ibis="ibis") # doctest: +SKIP { "ibis": , } )rqsysmodulesrj)r rrys r4rr!s5H/6mmo >daAs{{q! ! >> >s*Acd|vr"dvs ddthvr|jdjfd|jDS)a `parsed_shorthand` is added by `FieldChannelMixin`. It's used below to replace shorthand with its long form equivalent `parsed_shorthand` is removed from `context` if it exists so that it is not passed to child `to_dict` function calls. sortrsordinalc3dK|]'\}}j|ttur||f)ywr9)rjr)rrryrTs r4rz,_replace_parsed_shorthand..Zs4 Aq 88Ay !Y . As-0)rrrrq)rrTs `r4rrHs]!!dd6l9i2HHV$KK$**, Kr3r)boundc"t|tSr9)rrrsrs r4_is_dictrl c4  r3c"t|tSr9)rrrcrs r4_is_listrprr3rc@t|| xrt|tSr9)rrr)rrs r4r r ts #w' ' EJsH,EEr3c|r|dS|SNrr2)rrTs r4 _passthroughrzs47$$r3cLeZdZdZdZd dZed ddZe d ddZ e d ddZ e d ddZ e d ddZ e d dd Z d d d e f dd Z y )ra< Class used to construct SchemaBase class hierarchies from a dict. The primary purpose of using this class is to be able to build a hash table that maps schemas to their wrapper classes. The candidate classes are specified in the ``wrapper_classes`` positional-only argument to the constructor. ) definitionstitle descriptionrUidctt|_|D]F}|j|j|j |jj |Hyr9)rrc class_dictr hash_schemart)r!wrapper_classestps r4rz_FromDict.__init__sR>I=N! IBzz% 0 0 <=DDRH Ir3c|jrAt|tr1|jDcic]\}}||jvr||}}}|r"t j |d}t |Sfdt |Scc}}w)a Compute a python hash for a nested dictionary which properly handles dicts, lists, sets, and tuples. At the top level, the function excludes from the hashed schema all keys listed in `exclude_keys`. This implements two methods: one based on conversion to JSON, and one based on recursive conversions of unhashable to hashable types; the former seems to be slightly faster in several benchmarks. T)rc t|tr"tfd|jDSt|trtt |St|t tfrtt |S|S)Nc38K|]\}}||fywr9r2)rrry_freezes r4rz9_FromDict.hash_schema.._freeze..s$MAa_$Ms)rrrs frozensetrqrmaprcr)rr's r4r'z&_FromDict.hash_schema.._freezesec4($$M$MMMS)$S#%677dE]3 Wc!233Jr3)_hash_exclude_keysrrrsrqrrhash)rrAuse_jsonrvrsr's @r4r!z_FromDict.hash_schemas  ! !j&>!' Cc444SF  6T2A7N ( ()sB cyr9r2r!rr#rArB default_classs r4rz_FromDict.from_dictr3cyr9r2r/s r4rz_FromDict.from_dictr1r3cyr9r2r/s r4rz_FromDict.from_dictsr3cyr9r2r/s r4rz_FromDict.from_dictr1r3cyr9r2r/s r4rz_FromDict.from_dictsr3Nc Rt|tr|S|#|j}|xs|jxs|}|}n?|0|}|xs|}|j|j |} | r| dn|}n d} t | t|j|} t||} d| vsd| vrG| jdg| jdgz} | D]} t|||| |||cSt|rN| jdi}|jDcic]\}}|||vr | |||n|}}}|d i|St!|r0| jd i}||Dcgc] }| ||c}S||S#tj$rYwxYwcc}}wcc}w) z/Construct an object from a dict representation.rz3Must provide either `tp` or `schema`, but not both.rFroneOf)rAr0rrkrqr2)rrrrrr r!rr rrrjrCr/rrrqr)r!rr#rArBr0current_schema root_schema target_tpmatchesrrrschemaspossiblerrryrT item_schemas r4rz_FromDict.from_dicts c: &J ^ZZN*4*X*X.KI  $N$6Kood&6&6~&FGG&- =IGCS/ !DNN{C &~{C h 'X"5ll7B/(,,w2KKG# TT'X+N%SSS  T C=$,LLr$BE IIKAqQ%ZIaa1QFD$t$ $ c]*2,,w*CKL1i+>LM MS> !%"11Ms FF%F$FF)r"zIterable[type[SchemaBase]]r|r|r)rAr{r,r-r|r)....) rrr#r|rAr|rBr|r0rr|r) r%dict[str, Any] | list[dict[str, Any]]r#rrArrBrr0rr|r) rr{r#r|rAr{rBr|r0rr|r)...) rr{r#rrAr|rBr|r0rr|r)..) rr?r#rrAr{rBrr0rr|r&) rz3dict[str, Any] | list[dict[str, Any]] | TSchemaBaser#ztype[TSchemaBase] | NonerArrBrr0rr|zTSchemaBase | SchemaBase) rHrrrr*rrr!rrrr2r3r4rr~s;RI ) )D         +.  2     )  !$                    -0  2   *    (,(,,0) 7" @7" %7"& 7" * 7"  7" "7"r3rc"eZdZddZdZddZy)_PropertySetterc ||_||_yr9)proprA)r!rCrAs r4rz_PropertySetter.__init__s  r3c||_||_|jdjdd|_|j dj |j ddz}tt|rtt|}|jjd}|dkDrX|jd|jdd |jztjd |j|dz|_n1|jjdd d z|jz|_tj||_tj ||_|j$|_|S |S) Nr__z**rrz Parameters r@z r2z r))rrrArrrCrPr]rrfindtextwrapdedentrDrE __signature__getfullargspec __wrapped__rH)r!rr property_name altair_propparameter_indexs r4__get__z_PropertySetter.__get__ s^{{=199$E 99+q)//1tyyk124FF 8] +!(M:K*1166~FO#''(89AA&"Mll#oo";#6#67G#H"IJ  ''//;dBT\\Q ")!2!2;!?D &55kBD '00DM    r3cf|jj}|r|dn|||j<|Sr)rr}rC)r!rrrs r4__call__z_PropertySetter.__call__Ds+hhmmo$(afDII r3N)rCrrAr{r|r|)rrrr)rHrrrrOrQr2r3r4rArAs"Hr3rAc |j}|jdijD]\}}t||t |||S)z4Decorator to add property setters to a Schema class.r)rrjrqsetattrrA)rrArC propschemas r4with_property_settersrUKsP  # # %F"JJ|R8>>@>jT?4<=> Jr3r)r:r-r|zIterator[None]).) r@rrAr{rBrr=z Literal[True]r|r&) r@rrAr{rBrr=zLiteral[False]r|,jsonschema.exceptions.ValidationError | Noner9)rAr{rBrr=r-r|rV)r@r{rAr{rBrr|r))rAr{r|r)r|r-)rAr{r|r{)rBr{rez str | Noner|r!)rr~r|r)rPr)r|r*)rPr)r|r))rr*r|r*)rrrNz Sequence[str]r|r-)rRr*r|r*)rr~r|r-)rz type[Any]r|zIterator[type[Any]])rz Iterable[Any]r|z list[Any])rzdt.date | dt.datetimer|r{) rrrrr rrrr|r)rAr{rBrr|r{)rrr|zTypeIs[UndefinedType])rrr|r)rrr|r)r_CopyImpl | Anyr|rW)rrrset[str]r|r)rrrrXr|r)rrWrrXr|rW)r rr|zdict[str, _OptionalModule])rr{rTr{r|r{)rzAny | dict[Any, Any]r|zTypeIs[dict[Any, Any]])rzAny | list[Any]r|zTypeIs[list[Any]])rrrztype | tuple[type, ...]r|zTypeIs[Iterable[Any]])rrrTrr|zAny | dict[str, Any])rrr|r) __future__r contextlibr}rrrDrr rG collectionsrcollections.abcrrrr functoolsr importlib.metadatar importlib_version itertoolsr r mathr typingrrrrrrrrrtyping_extensionsrr/jsonschema.exceptionsjsonschema.validatorsnarwhals.stable.v1stablev1rpackaging.versionraltairr version_inforrrryrr rr! altair.typingr"r$r&r'r(rrc exceptionsrr)rsrr*r+r,r.rmr5r7contextmanagerr<rCrGrZr^r_r`rrIrHrJrrKrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrArUr2r3r4ros*#  #AA;(   (% wAALL $' 7"!, 7"&&1!4OY4!%j&;&;&K&K!LYL%)#/B*B%CC 4U3)RQ D*<8    ), "%   &      ),7 7 7&7  7 2 7 7)-#  # #&#  # 2 #R)-, , ,&, ,^A> LEI7A ."% %%" *(0(((F $'+$'$'NL%$* <9 8!JAE (=,bJ66bJ H H G   45K>  &1%x11<>Jwx018>>&   O  CLA},-)-@  3 3 ' ' B B 6 6$n<n