Pushing polar dataframe to redis

huangapple go评论59阅读模式
英文:

Pushing polar dataframe to redis

问题

将polars dataframe推送到Redis的最佳方法是什么?

目前,我正在尝试读取由write_ipc返回的_io.BytesIO缓冲区

redis_instance.set("key", df.write_ipc(file=None, compression="lz4").read())

这似乎不起作用,因为Redis中的键为空。

英文:

What is the best way to push a polars dataframe to redis ?

Currently I am trying to read the _io.BytesIO buffer returned by write_ipc

redis_instance.set("key",df.write_ipc(file = None, compression="lz4").read())

This doesn't seem to work as the key in redis is empty

答案1

得分: 1

write_ipc 返回一个 BytesIO 对象。由于它刚刚写入,位置在流的末尾。BytesIO.read() 将从该位置开始读取,根据你的代码,在定义中它是空的。

你可以使用 getvalue 替代,它将始终读取所有内容。另请参阅此 Stackoverflow 问题关于 BytesIO。或者,你可以通过调用 seek(0) 方法来重置位置,然后再调用 read()

英文:

write_ipc returns a BytesIO object. As it has just written, the position is at the end of the stream. BytesIO.read() will start reading from the position onwards, which is in your code empty by definition.

You can instead use getvalue, which will always read all contents. See also this Stackoverflow question on BytesIO Alternatively, you can reset the position by calling the method seek(0) prior to callling read().

huangapple
  • 本文由 发表于 2023年5月17日 16:19:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269948.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定