oocana 0.16.6__py3-none-any.whl → 0.16.7__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 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
 
@@ -276,12 +281,28 @@ class Context:
276
281
  data = df.to_dict(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
- data_columns = loads(df.head(5).to_json(orient='split'))
281
- columns = data_columns.get("columns", [])
282
- rows_head = data_columns.get("data", [])
283
- data_tail = loads(df.tail(5).to_json(orient='split'))
284
- rows_tail = data_tail.get("data", [])
290
+ need_add_index = not_default_index(df)
291
+ head_data = df.head(5).to_dict(orient='split')
292
+ columns = head_data.get("columns", [])
293
+
294
+ rows_head = head_data.get("data", [])
295
+ if need_add_index:
296
+ columns = ["", *columns]
297
+ head_index = head_data.get("index", [])
298
+ rows_head = [[head_index[i], *rows_head[i]] for i in range(len(rows_head))]
299
+
300
+ tail_data = df.tail(5).to_dict(orient='split')
301
+ rows_tail = tail_data.get("data", [])
302
+ if need_add_index:
303
+ tail_index = tail_data.get("index", [])
304
+ rows_tail = [[tail_index[i], *rows_tail[i]] for i in range(len(rows_tail))]
305
+
285
306
  rows_dots = [["..."] * len(columns)]
286
307
  rows = rows_head + rows_dots + rows_tail
287
308
  else:
oocana/preview.py CHANGED
@@ -3,20 +3,26 @@ 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
 
10
- def __dataframe__(self, *args: Any, **kwargs: Any) -> Any:
15
+ def __len__(self) -> int:
11
16
  ...
12
17
 
13
- def to_dict(self, *args: Any, **kwargs: Any) -> Any:
18
+ def __dataframe__(self, *args: Any, **kwargs: Any) -> Any:
14
19
  ...
15
20
 
16
- @runtime_checkable
17
- class JsonAble(Protocol):
21
+ @property
22
+ def index(self) -> DataFrameIndex:
23
+ ...
18
24
 
19
- def to_json(self, *args: Any, **kwargs: Any) -> Any:
25
+ def to_dict(self, orient: Literal["split"]) -> Any:
20
26
  ...
21
27
 
22
28
  @runtime_checkable
@@ -27,11 +33,11 @@ class ShapeDataFrame(DataFrame, Protocol):
27
33
  ...
28
34
 
29
35
  @runtime_checkable
30
- class PartialDataFrame(Protocol):
31
- def head(self, *args: Any, **kwargs: Any) -> JsonAble:
36
+ class PartialDataFrame(DataFrame, Protocol):
37
+ def head(self, count: int) -> DataFrame:
32
38
  ...
33
39
 
34
- def tail(self, *args: Any, **kwargs: Any) -> JsonAble:
40
+ def tail(self, count: int) -> DataFrame:
35
41
  ...
36
42
 
37
43
  class TablePreviewData(TypedDict):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oocana
3
- Version: 0.16.6
3
+ Version: 0.16.7
4
4
  Summary: python implement of oocana to give a context for oocana block
5
5
  License: MIT
6
6
  Requires-Python: >=3.9
@@ -1,13 +1,13 @@
1
- oocana-0.16.6.dist-info/METADATA,sha256=KveWTqPJWZn9CclgQxpwJ5bJr5AhXLWWwbksOeZKvS4,221
2
- oocana-0.16.6.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- oocana-0.16.6.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
1
+ oocana-0.16.7.dist-info/METADATA,sha256=0_TpqDCVlfykzajr-HwTAb9844PjjmtNY9SiL93krig,221
2
+ oocana-0.16.7.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ oocana-0.16.7.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
4
  oocana/__init__.py,sha256=zMrQ1asZoRE91-BShf1v2ibdThaMc07YtZt5iNbbxsg,281
5
- oocana/context.py,sha256=a8sap8qfXWGlu3JrUgj-rgQ5AdKp8yPuiF5IZCLZQQ0,13542
5
+ oocana/context.py,sha256=LyavX-bgqWGmQkLmE-_QNCd3aHWesShEJJToi4fc32U,14466
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=sAKcVUFmOMvrzYLrvqAxd26SppSvK1qJqRTHdAS-KDc,1959
9
+ oocana/preview.py,sha256=xTyVtf5mKMVlXRwz3JSB-n4e_6dlxalkE341nUDwtD4,2027
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.6.dist-info/RECORD,,
13
+ oocana-0.16.7.dist-info/RECORD,,