oocana 0.16.6__py3-none-any.whl → 0.16.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- oocana/context.py +28 -6
- oocana/preview.py +16 -7
- {oocana-0.16.6.dist-info → oocana-0.16.8.dist-info}/METADATA +1 -1
- {oocana-0.16.6.dist-info → oocana-0.16.8.dist-info}/RECORD +6 -6
- {oocana-0.16.6.dist-info → oocana-0.16.8.dist-info}/WHEEL +0 -0
- {oocana-0.16.6.dist-info → oocana-0.16.8.dist-info}/entry_points.txt +0 -0
oocana/context.py
CHANGED
@@ -265,6 +265,11 @@ class Context:
|
|
265
265
|
)
|
266
266
|
|
267
267
|
def __dataframe(self, payload: PreviewPayload) -> PreviewPayload:
|
268
|
+
def not_default_index(df: DataFrame) -> bool:
|
269
|
+
index = df.index.tolist()
|
270
|
+
default_index = list(range(len(df)))
|
271
|
+
return index != default_index
|
272
|
+
|
268
273
|
if isinstance(payload, DataFrame):
|
269
274
|
payload = { "type": "table", "data": payload }
|
270
275
|
|
@@ -273,15 +278,32 @@ class Context:
|
|
273
278
|
if isinstance(df, ShapeDataFrame):
|
274
279
|
row_count = df.shape[0]
|
275
280
|
if row_count <= 10:
|
276
|
-
data = df.
|
281
|
+
data = loads(df.to_json(orient='split'))
|
277
282
|
columns = data.get("columns", [])
|
278
283
|
rows = data.get("data", [])
|
284
|
+
if not_default_index(df):
|
285
|
+
index = df.index.tolist()
|
286
|
+
rows = [[index[i], *rows[i]] for i in range(len(rows))]
|
287
|
+
columns = ["", *columns]
|
288
|
+
|
279
289
|
elif isinstance(df, PartialDataFrame):
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
290
|
+
need_add_index = False # TODO: some index is not begin with 0, current just always hide index
|
291
|
+
# to_json will serialize some default json dumps not supported type like datetime, so we just use to_json for now.
|
292
|
+
head_data = loads(df.head(5).to_json(orient='split'))
|
293
|
+
columns = head_data.get("columns", [])
|
294
|
+
|
295
|
+
rows_head = head_data.get("data", [])
|
296
|
+
if need_add_index:
|
297
|
+
columns = ["", *columns]
|
298
|
+
head_index = head_data.get("index", [])
|
299
|
+
rows_head = [[head_index[i], *rows_head[i]] for i in range(len(rows_head))]
|
300
|
+
|
301
|
+
tail_data = loads(df.tail(5).to_json(orient='split'))
|
302
|
+
rows_tail = tail_data.get("data", [])
|
303
|
+
if need_add_index:
|
304
|
+
tail_index = tail_data.get("index", [])
|
305
|
+
rows_tail = [[tail_index[i], *rows_tail[i]] for i in range(len(rows_tail))]
|
306
|
+
|
285
307
|
rows_dots = [["..."] * len(columns)]
|
286
308
|
rows = rows_head + rows_dots + rows_tail
|
287
309
|
else:
|
oocana/preview.py
CHANGED
@@ -3,20 +3,29 @@ from typing import Any, TypedDict, List, Literal, TypeAlias, Union, Protocol, ru
|
|
3
3
|
|
4
4
|
__all__ = ["PreviewPayload", "TablePreviewPayload", "TextPreviewPayload", "JSONPreviewPayload", "ImagePreviewPayload", "MediaPreviewPayload", "PandasPreviewPayload", "DefaultPreviewPayload"]
|
5
5
|
|
6
|
+
@runtime_checkable
|
7
|
+
class DataFrameIndex(Protocol):
|
8
|
+
def tolist(self) -> Any:
|
9
|
+
...
|
10
|
+
|
6
11
|
# this class is for pandas.DataFrame
|
7
12
|
@runtime_checkable
|
8
13
|
class DataFrame(Protocol):
|
9
14
|
|
15
|
+
def __len__(self) -> int:
|
16
|
+
...
|
17
|
+
|
10
18
|
def __dataframe__(self, *args: Any, **kwargs: Any) -> Any:
|
11
19
|
...
|
12
20
|
|
13
|
-
|
21
|
+
@property
|
22
|
+
def index(self) -> DataFrameIndex:
|
14
23
|
...
|
15
24
|
|
16
|
-
|
17
|
-
|
25
|
+
def to_json(self, orient: Literal["split"]) -> str:
|
26
|
+
...
|
18
27
|
|
19
|
-
def
|
28
|
+
def to_dict(self, orient: Literal["split"]) -> Any:
|
20
29
|
...
|
21
30
|
|
22
31
|
@runtime_checkable
|
@@ -27,11 +36,11 @@ class ShapeDataFrame(DataFrame, Protocol):
|
|
27
36
|
...
|
28
37
|
|
29
38
|
@runtime_checkable
|
30
|
-
class PartialDataFrame(Protocol):
|
31
|
-
def head(self,
|
39
|
+
class PartialDataFrame(DataFrame, Protocol):
|
40
|
+
def head(self, count: int) -> DataFrame:
|
32
41
|
...
|
33
42
|
|
34
|
-
def tail(self,
|
43
|
+
def tail(self, count: int) -> DataFrame:
|
35
44
|
...
|
36
45
|
|
37
46
|
class TablePreviewData(TypedDict):
|
@@ -1,13 +1,13 @@
|
|
1
|
-
oocana-0.16.
|
2
|
-
oocana-0.16.
|
3
|
-
oocana-0.16.
|
1
|
+
oocana-0.16.8.dist-info/METADATA,sha256=xwQQfPU_78nZH0uFPbXC1tCV4090vdogSFtT1gQ3pWg,221
|
2
|
+
oocana-0.16.8.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
|
3
|
+
oocana-0.16.8.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
4
4
|
oocana/__init__.py,sha256=zMrQ1asZoRE91-BShf1v2ibdThaMc07YtZt5iNbbxsg,281
|
5
|
-
oocana/context.py,sha256=
|
5
|
+
oocana/context.py,sha256=5wWUZr4BjojizFH-9yeadWvIpiUt2v7wUN3b7y34CFc,14677
|
6
6
|
oocana/data.py,sha256=0KpJyckz_X5JbrncBRFbOaU00CxcDx2UYHk6xuH1Poc,2890
|
7
7
|
oocana/handle_data.py,sha256=p0iEvdsVV3BqcelM8rvq0a_VPI52SeahaGCszfhZ0TI,1927
|
8
8
|
oocana/mainframe.py,sha256=Jixk9PjvJh7PnYwPGqOR5viwcOHWfaPhEiQFNHxHCxw,5219
|
9
|
-
oocana/preview.py,sha256=
|
9
|
+
oocana/preview.py,sha256=qJEoBQWno0BkuU501vd16VwE0okTC3PydFc_jpkwc98,2096
|
10
10
|
oocana/schema.py,sha256=8LwMaW4eXa3EmKxR4kzyTOpZiClMRMMsMA6f9CXodW4,4332
|
11
11
|
oocana/service.py,sha256=dPCcScQfMBlEjIodFnKU17-HlbBzrQbQK6CNRw7SmOE,2442
|
12
12
|
oocana/throtter.py,sha256=xTldm2OZ5uYPiyC6Aatug4FJAoMylPjtXftxHvSr_50,1104
|
13
|
-
oocana-0.16.
|
13
|
+
oocana-0.16.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|