Skip to content

Commit

Permalink
refact: rename EditableDataframe into EditableDataFrame
Browse files Browse the repository at this point in the history
chore: change other places
  • Loading branch information
FabienArcellier committed Dec 17, 2024
1 parent efb70ea commit 3093c36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
32 changes: 16 additions & 16 deletions src/writer/core_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pyarrow # type: ignore

from .core import MutableValue, import_failure
from .ss_types import DataframeRecordAdded, DataframeRecordRemoved, DataframeRecordUpdated
from .ss_types import DataFrameRecordAdded, DataFrameRecordRemoved, DataFrameRecordUpdated

if TYPE_CHECKING:
import pandas
Expand Down Expand Up @@ -44,7 +44,7 @@ def record(df: Any, record_index: int) -> dict:
raise NotImplementedError

@staticmethod
def record_add(df: Any, payload: DataframeRecordAdded) -> Any:
def record_add(df: Any, payload: DataFrameRecordAdded) -> Any:
"""
signature of the methods to be implemented to process wf-dataframe-add event
Expand All @@ -54,7 +54,7 @@ def record_add(df: Any, payload: DataframeRecordAdded) -> Any:
raise NotImplementedError

@staticmethod
def record_update(df: Any, payload: DataframeRecordUpdated) -> Any:
def record_update(df: Any, payload: DataFrameRecordUpdated) -> Any:
"""
signature of the methods to be implemented to process wf-dataframe-update event
Expand All @@ -64,7 +64,7 @@ def record_update(df: Any, payload: DataframeRecordUpdated) -> Any:
raise NotImplementedError

@staticmethod
def record_remove(df: Any, payload: DataframeRecordRemoved) -> Any:
def record_remove(df: Any, payload: DataFrameRecordRemoved) -> Any:
"""
signature of the methods to be implemented to process wf-dataframe-action event
Expand Down Expand Up @@ -118,7 +118,7 @@ def record(df: 'pandas.DataFrame', record_index: int) -> dict:
return dict(record)

@staticmethod
def record_add(df: 'pandas.DataFrame', payload: DataframeRecordAdded) -> 'pandas.DataFrame':
def record_add(df: 'pandas.DataFrame', payload: DataFrameRecordAdded) -> 'pandas.DataFrame':
"""
>>> edf = EditableDataFrame(df)
>>> edf.record_add({"record": {"a": 1, "b": 2}})
Expand All @@ -137,7 +137,7 @@ def record_add(df: 'pandas.DataFrame', payload: DataframeRecordAdded) -> 'pandas
return pandas.concat([df, new_df])

@staticmethod
def record_update(df: 'pandas.DataFrame', payload: DataframeRecordUpdated) -> 'pandas.DataFrame':
def record_update(df: 'pandas.DataFrame', payload: DataFrameRecordUpdated) -> 'pandas.DataFrame':
"""
>>> edf = EditableDataFrame(df)
>>> edf.record_update({"record_index": 12, "record": {"a": 1, "b": 2}})
Expand All @@ -162,7 +162,7 @@ def record_update(df: 'pandas.DataFrame', payload: DataframeRecordUpdated) -> 'p
return df

@staticmethod
def record_remove(df: 'pandas.DataFrame', payload: DataframeRecordRemoved) -> 'pandas.DataFrame':
def record_remove(df: 'pandas.DataFrame', payload: DataFrameRecordRemoved) -> 'pandas.DataFrame':
"""
>>> edf = EditableDataFrame(df)
>>> edf.record_remove({"record_index": 12})
Expand Down Expand Up @@ -213,15 +213,15 @@ def record(df: 'polars.DataFrame', record_index: int) -> dict:


@staticmethod
def record_add(df: 'polars.DataFrame', payload: DataframeRecordAdded) -> 'polars.DataFrame':
def record_add(df: 'polars.DataFrame', payload: DataFrameRecordAdded) -> 'polars.DataFrame':
_assert_record_match_polar_df(df, payload['record'])

import polars
new_df = polars.DataFrame([payload['record']])
return polars.concat([df, new_df])

@staticmethod
def record_update(df: 'polars.DataFrame', payload: DataframeRecordUpdated) -> 'polars.DataFrame':
def record_update(df: 'polars.DataFrame', payload: DataFrameRecordUpdated) -> 'polars.DataFrame':
# This implementation works but is not optimal.
# I didn't find a better way to update a record in polars
#
Expand All @@ -236,7 +236,7 @@ def record_update(df: 'polars.DataFrame', payload: DataframeRecordUpdated) -> 'p
return df

@staticmethod
def record_remove(df: 'polars.DataFrame', payload: DataframeRecordRemoved) -> 'polars.DataFrame':
def record_remove(df: 'polars.DataFrame', payload: DataFrameRecordRemoved) -> 'polars.DataFrame':
import polars

record_index: int = payload['record_index']
Expand Down Expand Up @@ -277,13 +277,13 @@ def record(df: List[Dict[str, Any]], record_index: int) -> dict:
return copy.copy(r)

@staticmethod
def record_add(df: List[Dict[str, Any]], payload: DataframeRecordAdded) -> List[Dict[str, Any]]:
def record_add(df: List[Dict[str, Any]], payload: DataFrameRecordAdded) -> List[Dict[str, Any]]:
_assert_record_match_list_of_records(df, payload['record'])
df.append(payload['record'])
return df

@staticmethod
def record_update(df: List[Dict[str, Any]], payload: DataframeRecordUpdated) -> List[Dict[str, Any]]:
def record_update(df: List[Dict[str, Any]], payload: DataFrameRecordUpdated) -> List[Dict[str, Any]]:
_assert_record_match_list_of_records(df, payload['record'])

record_index = payload['record_index']
Expand All @@ -293,7 +293,7 @@ def record_update(df: List[Dict[str, Any]], payload: DataframeRecordUpdated) ->
return df

@staticmethod
def record_remove(df: List[Dict[str, Any]], payload: DataframeRecordRemoved) -> List[Dict[str, Any]]:
def record_remove(df: List[Dict[str, Any]], payload: DataFrameRecordRemoved) -> List[Dict[str, Any]]:
del(df[payload['record_index']])
return df

Expand Down Expand Up @@ -348,7 +348,7 @@ def df(self, value: Union['pandas.DataFrame', 'polars.DataFrame', List[dict]]) -
self._df = value
self.mutate()

def record_add(self, payload: DataframeRecordAdded) -> None:
def record_add(self, payload: DataFrameRecordAdded) -> None:
"""
Adds a record to the dataframe
Expand All @@ -361,7 +361,7 @@ def record_add(self, payload: DataframeRecordAdded) -> None:
self._df = self.processor.record_add(self.df, payload)
self.mutate()

def record_update(self, payload: DataframeRecordUpdated) -> None:
def record_update(self, payload: DataFrameRecordUpdated) -> None:
"""
Updates a record in the dataframe
Expand All @@ -377,7 +377,7 @@ def record_update(self, payload: DataframeRecordUpdated) -> None:
self._df = self.processor.record_update(self.df, payload)
self.mutate()

def record_remove(self, payload: DataframeRecordRemoved) -> None:
def record_remove(self, payload: DataFrameRecordRemoved) -> None:
"""
Removes a record from the dataframe
Expand Down
8 changes: 4 additions & 4 deletions src/writer/ss_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ class HashRequestResponse(AppProcessServerRequest):
AppProcessServerResponsePacket = Tuple[int, Optional[str], AppProcessServerResponse]


class DataframeRecordAdded(TypedDict):
class DataFrameRecordAdded(TypedDict):
record: Dict[str, Any]

class DataframeRecordUpdated(TypedDict):
class DataFrameRecordUpdated(TypedDict):
record_index: int
record: Dict[str, Any]

class DataframeRecordRemoved(TypedDict):
class DataFrameRecordRemoved(TypedDict):
record_index: int

class WriterEventResult(TypedDict):
Expand Down Expand Up @@ -230,4 +230,4 @@ class WorkflowExecutionLog(BaseModel):


class WriterConfigurationError(ValueError):
pass
pass
2 changes: 1 addition & 1 deletion tests/backend/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ def session_verifier_2(headers: Dict[str, str]) -> None:
assert s_invalid is None


class TestEditableDataframe:
class TestEditableDataFrame:

def test_editable_dataframe_expose_pandas_dataframe_as_df_property(self) -> None:
df = pandas.DataFrame({
Expand Down

0 comments on commit 3093c36

Please sign in to comment.