我想要一个 pyplot 图形的上下文管理器,基本上像这样:
from contextlib import contextmanager
import matplotlib.pyplot as plt
@contextmanager
def subplots():
(fig, ax) = plt.subplots()
try:
yield (fig, ax)
finally:
plt.close(fig)
Run Code Online (Sandbox Code Playgroud)
是否可以对返回的元组实现类型提示?天真的
import typing
def subplots() -> typing.Tuple[plt.Figure, plt.Axes]
Run Code Online (Sandbox Code Playgroud)
不起作用。
我有一个查询,例如
User.objects.annotate(
x=Value(False, output_field=BooleanField()),
y=Value(True, output_field=BooleanField())
).annotate(
z=F('x').bitor(F('y')) # HOW TO DO THIS?
).values('z')
Run Code Online (Sandbox Code Playgroud)
它适用于 SQLite,但不适用于 PostgreSQL。错误是
LINE 1: SELECT (false | true) AS "z" FROM "auth_user" LIMIT 21
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)
我应该如何在带注释的字段上实现一致的逻辑或?
谢谢。
有没有更简单的实施方法
select (case when ((a is null) or (b is null)) then null else (case when
(a = b) then true else false end) end) from ...
Run Code Online (Sandbox Code Playgroud)
在PostgreSQL或其他主要的RDBMS中呢?