crandas.stateobject#
- class crandas.stateobject.DeferredObject(name, **kwargs)#
Bases:
StateObject
,Deferred
Represents a deferred VDL object that has a name but no further structure.
- class crandas.stateobject.ResponseHandlerAnyObject(cls, **kwargs)#
Bases:
ResponseHandler
Response handler for VDL objects of unknown structure
This response handler can be used for queries that return a VDL object of which the structure is not yet known, e.g., cd.get_table() where no schema is specified. In this case, a DeferredObject is returned. This object has a name but no further structure.
- get_deferred(json_query, handle)#
Implements get_deferred by dispatching to right class function
- get_dry_run_result(json_query, handle)#
Implements get_dry_run_result by dispatching to right class function
- parse_response(json_query, json_answer)#
Implements parse_response by dispatching to right class function
- class crandas.stateobject.ResponseHandlerObject(cls, init_args, init_kwargs, **kwargs)#
Bases:
ResponseHandler
Response handler for queries that return a VDL object
This class checks the type of query (regular, open, or defer) and dispatches to the right functions of the VDL object accordingly.
- get_deferred(json_query, handle)#
Implements get_deferred by dispatching to right class function
- get_dry_run_result(json_query, handle)#
Implements get_dry_run_result by dispatching to right class function
- make_deferred(name)#
Makes a deferred object for the class. Calls the constructor of the class with the init_args and init_kwargs with which this class was constructed. The DeferredObject subclasses Deferred and overrides the name property to prevent the object being used outside of the transaction, where obj.result should be used instead.
- parse_response(json_query, json_answer)#
Implements parse_response by dispatching to right class function
- class crandas.stateobject.StateObject(name, **kwargs)#
Bases:
ABC
Abstract base class for VDL state objects.
A VDL state object is an object that is stored remotely in the VDL and on which operations can be performed, such as a CDataFrame.
This class manages the name of the object. Subclasses should pass the name when calling super.__init__(), using the convention of https://rhettinger.wordpress.com/2011/05/26/super-considered-super/.
Implementations should implement the abstract methods as documented below.
- classmethod expect(*args, **kwargs)#
Return a ResponseHandler suitable as argument for vdl_query.
When the query is performed in a transaction or in deferred mode, a deferred instance of the class is created by calling the constructor of the class with the arguments to this function.
- classmethod expect_any()#
Retuns a ResponseHandler suitable as argument to vdl_query for the case that the structure of the returned object is not known, e.g., when calling cd.get_table() without providing a schema. In this case, when the query is performed in a transaction or in deferred mode, a Deferred is returned without additional structure.
- abstract classmethod json_to_closed(deferred, json_answer)#
Returns an instance of the class corresponding to to the provided JSON represention.
If the instance comes from a transaction, then deferred is the deferred object originally returned by vdl_query. This function should then check that the returned answer complies with the expected deferred. Otherwise, deferred is None.
- classmethod json_to_opened(deferred, json_answer, masker)#
Returns an opened object (e.g. a Pandas dataframe) corresponding to the provided JSON representation.
If the instance comes from a transaction, then deferred is the deferred object originally returned by vdl_query. This function should then check that the returned answer complies with the expected deferred. Otherwise, deferred is None.
- open_dry_run_result()#
Run on a deferred instance of the class as returned by cls.expect(). Should return an example opened object (e.g., DataFrame) of the same type as would be obtained by opening the object.