Skip to content

Commit

Permalink
Add integration tests and dependencies to read and write xslx
Browse files Browse the repository at this point in the history
  • Loading branch information
pvk-developer committed Apr 29, 2024
1 parent d7a8108 commit 3318b12
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,5 @@ release-major: check-release bumpversion-major release

.PHONY: check-deps
check-deps:
$(eval allow_list='cloudpickle=|graphviz=|numpy=|pandas=|tqdm=|copulas=|ctgan=|deepecho=|rdt=|sdmetrics=|platformdirs=')
$(eval allow_list='cloudpickle=|graphviz=|numpy=|pandas=|tqdm=|copulas=|ctgan=|deepecho=|rdt=|sdmetrics=|platformdirs=|openpyxl=|xlsxwriter=')
pip freeze | grep -v "SDV.git" | grep -E $(allow_list) | sort > $(OUTPUT_FILEPATH)
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ dependencies = [
'deepecho>=0.6.0',
'rdt>=1.12.0',
'sdmetrics>=0.14.0',
'platformdirs>=4.0'
'platformdirs>=4.0',
'xlsxwriter>=3.1.0',
'openpyxl>=3.1.0'
]

[project.urls]
Expand Down
5 changes: 3 additions & 2 deletions sdv/io/local/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Local I/O module."""

from sdv.io.local.local import BaseLocalHandler, CSVHandler
from sdv.io.local.local import BaseLocalHandler, CSVHandler, ExcelHandler

__all__ = (
'BaseLocalHandler',
'CSVHandler'
'CSVHandler',
'ExcelHandler'
)
34 changes: 31 additions & 3 deletions tests/integration/io/local/test_local.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pandas as pd

from sdv.io.local import CSVHandler
from sdv.io.local import CSVHandler, ExcelHandler
from sdv.metadata import MultiTableMetadata


class TestCSVHandler:

def test_integration_read_write(self, tmpdir):
"""Test end to end the read and write methods of ``CSVHandler``."""
def test_integration_write_and_read(self, tmpdir):
"""Test end to end the write and read methods of ``CSVHandler``."""
# Prepare synthetic data
synthetic_data = {
'table1': pd.DataFrame({'col1': [1, 2, 3], 'col2': ['a', 'b', 'c']}),
Expand All @@ -30,3 +30,31 @@ def test_integration_read_write(self, tmpdir):
# Check if the dataframes match the original synthetic data
pd.testing.assert_frame_equal(data['table1'], synthetic_data['table1'])
pd.testing.assert_frame_equal(data['table2'], synthetic_data['table2'])


class TestExcelHandler:

def test_integration_write_and_read(self, tmpdir):
"""Test end to end the write and read methods of ``ExcelHandler``."""
# Prepare synthetic data
synthetic_data = {
'table1': pd.DataFrame({'col1': [1, 2, 3], 'col2': ['a', 'b', 'c']}),
'table2': pd.DataFrame({'col3': [4, 5, 6], 'col4': ['d', 'e', 'f']})
}

# Write synthetic data to xslx files
handler = ExcelHandler()
handler.write(synthetic_data, tmpdir / 'excel.xslx')

# Read data from xslx file
data, metadata = handler.read(tmpdir / 'excel.xslx')

# Check if data was read correctly
assert len(data) == 2
assert 'table1' in data
assert 'table2' in data
assert isinstance(metadata, MultiTableMetadata) is True

# Check if the dataframes match the original synthetic data
pd.testing.assert_frame_equal(data['table1'], synthetic_data['table1'])
pd.testing.assert_frame_equal(data['table2'], synthetic_data['table2'])

0 comments on commit 3318b12

Please sign in to comment.