Skip to content

Commit

Permalink
Add mypy
Browse files Browse the repository at this point in the history
Signed-off-by: Vasilis Themelis <vdthemelis@gmail.com>
  • Loading branch information
vthemelis authored and martinRenou committed Aug 24, 2023
1 parent 4760025 commit f8742cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ repos:
- flake8-unused-arguments==0.0.9
- flake8-noqa==1.2.1
- pep8-naming==0.12.1
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
exclude: ui-tests-ipw[78]\/.*
additional_dependencies:
- "pandas-stubs"
- "types-Pygments"
- "types-colorama"
- "types-setuptools"
30 changes: 15 additions & 15 deletions ipydatagrid/datagrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@ def data(self):
final_df = final_df[final_df.columns[:-1]]
return final_df

@data.setter
def data(self, dataframe):
# Reference for the original frame column and index names
# This is used to when returning the view data model
self.__dataframe_reference_index_names = dataframe.index.names
self.__dataframe_reference_columns = dataframe.columns
dataframe = dataframe.copy()

# Primary key used
index_key = self.get_dataframe_index(dataframe)

self._data = self.generate_data_object(
dataframe, "ipydguuid", index_key
)

@staticmethod
def generate_data_object(dataframe, guid_key="ipydguuid", index_name="key"):
dataframe[guid_key] = pd.RangeIndex(0, dataframe.shape[0])
Expand Down Expand Up @@ -480,21 +495,6 @@ def generate_data_object(dataframe, guid_key="ipydguuid", index_name="key"):
"fields": [{field["name"]: None} for field in schema["fields"]],
}

@data.setter
def data(self, dataframe):
# Reference for the original frame column and index names
# This is used to when returning the view data model
self.__dataframe_reference_index_names = dataframe.index.names
self.__dataframe_reference_columns = dataframe.columns
dataframe = dataframe.copy()

# Primary key used
index_key = self.get_dataframe_index(dataframe)

self._data = self.generate_data_object(
dataframe, "ipydguuid", index_key
)

def get_dataframe_index(self, dataframe):
"""Returns a primary key to be used in ipydatagrid's
view of the passed DataFrame"""
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
ignore_missing_imports = True
exclude = ui-tests-ipw[78]/.*

0 comments on commit f8742cb

Please sign in to comment.