Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
* Add `columns_check_with_data`
  • Loading branch information
jzsmoreno committed Apr 10, 2024
1 parent 80fe8b3 commit ae05cb0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pydbsmgr/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.2
0.9.3
7 changes: 4 additions & 3 deletions pydbsmgr/utils/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class ColumnsCheck:
def __init__(self, df: DataFrame):
self.df = df

def get_frame(self) -> DataFrame:
self.df = self._process_columns()
def get_frame(self, **kwargs) -> DataFrame:
self.df = self._process_columns(**kwargs)
return self.df

def _process_columns(self, surrounding: bool = True) -> DataFrame:
Expand All @@ -102,7 +102,8 @@ def _process_columns(self, surrounding: bool = True) -> DataFrame:
df.columns = df.columns.str.replace(r"[^a-zA-Z0-9ñáéíóú_]", "_", regex=True)

df.columns = df.columns.str.replace("_+", "_", regex=True)
df.columns = df.columns.str.strip().strip("_")
df.columns = df.columns.str.strip()
df.columns = df.columns.str.strip("_")
if surrounding:
df.columns = [f"[{col}]" for col in df.columns]

Expand Down
23 changes: 22 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydbsmgr.lightest import LightCleaner
from pydbsmgr.main import *
from pydbsmgr.utils.tools import ColumnsDtypes, get_extraction_date
from pydbsmgr.utils.tools import ColumnsCheck, ColumnsDtypes, get_extraction_date


@pytest.fixture()
Expand Down Expand Up @@ -80,3 +80,24 @@ def lightest_with_data() -> Callable:
df["another_date"].astype(str).to_list(),
df["third_date"].astype(str).to_list(),
)


@pytest.fixture()
def columns_check_with_data() -> Callable:
"""
Fixture that returns an instance of the class ColumnsCheck with data for testing
"""
df = pd.DataFrame(
{
"index": ["0", "1", "2", "3"],
"Raw Data!": ["10", "06", "18", "25"],
"First Data #": ["09", "01", "01", "08"],
"First Data 2": ["9", "1", "1", "8"],
"Another Data?": ["10", "6", "18", "25"],
}
)

handler = ColumnsCheck(df)
df = handler.get_frame(surrounding=False)

return df.columns.to_list()
9 changes: 9 additions & 0 deletions test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ def test_lightest(lightest_with_data):
assert third_date == comparison


def test_columnscheck(columns_check_with_data):
cols = columns_check_with_data
assert cols[0] == "index"
assert cols[1] == "raw_data"
assert cols[2] == "first_data"
assert cols[3] == "first_data_2"
assert cols[4] == "another_data"


def test_get_extraction_date(_get_extraction_date):
assert _get_extraction_date("filename_2023-11-17") == "2023-11-17"
assert _get_extraction_date(["filename_2023-11-17"]) == ["2023-11-17"]

0 comments on commit ae05cb0

Please sign in to comment.