polars.SQLContext.unregister#

SQLContext.unregister(names: str | Collection[str]) Self[source]#

通过名称注销一个或多个急切/懒加载框架。

Parameters:
names

要取消注册的表的名称。

注释

你也可以通过使用SQLContext作为上下文管理器来控制表的注册生命周期;当需要这种控制时,这通常更有用:

>>> df0 = pl.DataFrame({"colx": [0, 1, 2]})
>>> df1 = pl.DataFrame({"colx": [1, 2, 3]})
>>> df2 = pl.DataFrame({"colx": [2, 3, 4]})

在作用域内注册的帧会在作用域退出时自动取消注册。请注意,在构造时注册的帧将在后续作用域中持续存在。

>>> # register one frame at construction time, and the other two in-scope
>>> with pl.SQLContext(tbl0=df0) as ctx:
...     ctx.register_many(tbl1=df1, tbl2=df2).tables()
['tbl0', 'tbl1', 'tbl2']

在作用域退出后,在作用域内注册的所有表都将不再保留:

>>> ctx.tables()
['tbl0']

示例

>>> df0 = pl.DataFrame({"ints": [9, 8, 7, 6, 5]})
>>> lf1 = pl.LazyFrame({"text": ["a", "b", "c"]})
>>> lf2 = pl.LazyFrame({"misc": ["testing1234"]})

使用SQLContext对象注册:

>>> ctx = pl.SQLContext(test1=df0, test2=lf1, test3=lf2)
>>> ctx.tables()
['test1', 'test2', 'test3']

注销一个或多个表:

>>> ctx.unregister(["test1", "test3"]).tables()
['test2']
>>> ctx.unregister("test2").tables()
[]