Skip to content

Commit

Permalink
feat: add global param max_data_length
Browse files Browse the repository at this point in the history
  • Loading branch information
longxiaofei committed May 14, 2024
1 parent 185229a commit e166451
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pygwalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pygwalker.services.global_var import GlobalVarManager
from pygwalker.services.kaggle import show_tips_user_kaggle as __show_tips_user_kaggle

__version__ = "0.4.8.3"
__version__ = "0.4.8.4"
__hash__ = __rand_str()

from pygwalker.api.jupyter import walk, render, table
Expand Down
10 changes: 4 additions & 6 deletions pygwalker/api/pygwalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
from pygwalker.errors import DataCountLimitError
from pygwalker import __version__

RESPONSE_MAX_DATA_LENGTH = 1 * 1000 * 1000


class PygWalker:
"""PygWalker"""
Expand Down Expand Up @@ -385,15 +383,15 @@ def upload_spec_to_cloud(data: Dict[str, Any]):
def _get_datas(data: Dict[str, Any]):
sql = data["sql"]
datas = self.data_parser.get_datas_by_sql(sql)
if len(datas) > RESPONSE_MAX_DATA_LENGTH:
if len(datas) > GlobalVarManager.max_data_length:
raise DataCountLimitError()
return {
"datas": datas
}

def _get_datas_by_payload(data: Dict[str, Any]):
datas = self.data_parser.get_datas_by_payload(data["payload"])
if len(datas) > RESPONSE_MAX_DATA_LENGTH:
if len(datas) > GlobalVarManager.max_data_length:
raise DataCountLimitError()
return {
"datas": datas
Expand All @@ -402,7 +400,7 @@ def _get_datas_by_payload(data: Dict[str, Any]):
def _batch_get_datas_by_sql(data: Dict[str, Any]):
result = self.data_parser.batch_get_datas_by_sql(data["queryList"])
for datas in result:
if len(datas) > RESPONSE_MAX_DATA_LENGTH:
if len(datas) > GlobalVarManager.max_data_length:
raise DataCountLimitError()
return {
"datas": result
Expand All @@ -411,7 +409,7 @@ def _batch_get_datas_by_sql(data: Dict[str, Any]):
def _batch_get_datas_by_payload(data: Dict[str, Any]):
result = self.data_parser.batch_get_datas_by_payload(data["queryList"])
for datas in result:
if len(datas) > RESPONSE_MAX_DATA_LENGTH:
if len(datas) > GlobalVarManager.max_data_length:
raise DataCountLimitError()
return {
"datas": result
Expand Down
5 changes: 5 additions & 0 deletions pygwalker/services/global_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GlobalVarManager:
kanaries_api_host = "https://api.kanaries.net"
kanaries_main_host = "https://kanaries.net"
last_exported_dataframe = None
max_data_length = 1000 * 1000

@classmethod
def set_env(cls, env: Literal['Jupyter', 'Streamlit']):
Expand Down Expand Up @@ -42,3 +43,7 @@ def set_privacy(cls, privacy: Literal['offline', 'update-only', 'events']):
@classmethod
def set_last_exported_dataframe(cls, df: DataFrame):
cls.last_exported_dataframe = df

@classmethod
def set_max_data_length(cls, length: int):
cls.max_data_length = length

0 comments on commit e166451

Please sign in to comment.