7.4.6 Delete Datastore Objects
The oml.ds.delete
function deletes datastores or objects in a datastore.
Use the oml.ds.delete
function to delete one or more datastores in your database schema or to delete objects in a datastore.
The syntax of oml.ds.delete
is the following:
oml.ds.delete(name, objs=None, regex_match=False)
The argument to the name
parameter may be one of the following:
-
A string that specifies the name of the datastore to modify or delete, or a regular expression that matches the datastores to delete.
-
A list of
str
objects that name the datastores from which to delete objects.
The objs
parameter specifies the objects to delete from a datastore. The argument to the objs
parameter may be one of the following:
-
A string that specifies the object to delete from one or more datastores, or a regular expression that matches the objects to delete.
-
None
(the default), which deletes the entire datastore or datastores.
The regex_match
parameter is a bool
that indicates whether the name
or objs
arguments are regular expressions. The default value is False
. The regex_match
parameter operates as follows:
-
If
regex_match=False
and ifname
is notNone
, and:-
If
objs=None
, thenoml.ds.delete
deletes the datastore or datastores specified in thename
argument. -
If you specify one or more datastores with the
name
argument and one or more datastore objects with theobjs
argument, thenoml.ds.delete
deletes the specified Python objects from the datastores.
-
-
If
regex_match=True
and:-
If
objs=None
, thenoml.ds.delete
deletes the datastores you specified in thename
argument. -
If the
name
argument is a string and you specify one or more datastore objects with theobjs
argument, thenoml.ds.delete
deletes from the datastore the objects whose names match the regular expression specified in theobjs
argument. -
If the
name
argument is a list ofstr
objects, then theobjs
argument must be a list ofstr
objects of the same length asname
, andoml.ds.delete
deletes from the datastores the objects whose names match the regular expressions specified inobjs
.
-
This function raises an error if the following occur:
-
A specified datastore does not exist.
-
Argument
regex_match
isFalse
and argumentname
is a list ofstr
objects larger than 1 and argumentobjs
is notNone
. -
Argument
regex_match
isTrue
and argumentsname
andobjs
are lists that are not the same length.
Example 7-18 Deleting Datastore Objects
This example demonstrates the using the oml.ds.delete
function. For the creation of the datastores used in this example, see Example 7-14.
import oml
# Show the existing datastores.
oml.ds.dir()
# Show the Python objects in the ds_pydata datastore.
oml.ds.describe(name='ds_pydata')
# Delete some objects from the datastore.
oml.ds.delete(name="ds_pydata", objs=["wine", "oml_boston"])
# Delete a datastore.
oml.ds.delete(name="ds_pydata")
# Delete all datastores whose names match a pattern.
oml.ds.delete(name="_pymodel", regex_match=True)
# Show the existing datastores again.
oml.ds.dir()
Listing for This Example
>>> import oml
>>>
>>> # Show the existing datastores.
... oml.ds.dir()
datastore_name object_count size date description
0 ds_pydata 3 26214 2019-05-18 21:04:06 python datasets
1 ds_pymodel 2 6370 2019-05-18 21:08:18 None
2 ds_wine_data 1 1410 2019-05-18 21:06:53 wine dataset
>>>
>>> # Show the Python objects in the ds_pydata datastore.
... oml.ds.describe(name='ds_pydata')
object_name class size length row_count col_count
0 oml_boston oml.DataFrame 1073 506 506 14
1 oml_diabetes oml.DataFrame 964 442 442 11
2 wine Bunch 24177 5 1 5
>>>
>>> # Delete some objects from a datastore.
... oml.ds.delete(name="ds_pydata", objs=["wine", "oml_boston"])
{'wine', 'oml_boston'}
>>>
>>> # Delete a datastore.
... oml.ds.delete(name="ds_pydata")
'ds_pydata'
>>>
>>> # Delete all datastores whose names match a pattern.
... oml.ds.delete(name="_pymodel", regex_match=True)
{'ds_pymodel'}
>>>
>>> # Show the existing datastores again.
... oml.ds.dir()
datastore_name object_count size date description
0 ds_wine_data 1 1410 2019-05-18 21:06:53 wine dataset
Parent topic: Save Python Objects in the Database