Skip to content

Commit

Permalink
Merge pull request #39 from ohadmata/fix-non-string-input-to-strftime
Browse files Browse the repository at this point in the history
Fix cases when there is no match on a string value for strftime
  • Loading branch information
ohadmata authored Jan 15, 2024
2 parents 4785df0 + 73584a8 commit 297294d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/shmessy/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@


def validate_strptime_pattern(data: ndarray, pattern: str) -> bool:
validated: bool = False
for value in data:
try:
if isinstance(value, str):
if isinstance(value, str): # For security reasons & skip nan values
datetime.strptime(value, pattern)
validated = True
except ValueError:
return False
return True
return validated
17 changes: 17 additions & 0 deletions tests/intg/test_fix_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,20 @@ def test_fix_column_names(df_data, fix_column_names, expected_result):
assert [column for column in df] == expected_result
assert [column.field_name for column in fixed_schema.columns] == expected_result


@Parametrization.autodetect_parameters()
@Parametrization.case(
name="Regular data",
df_data={
"name": ["Guy", "Yaron", "Mish", "Moyiz"],
"degree": ["MBA", "BCA", "M.Tech", "MBA"],
"score": [90, 40, 80, 98]
},
fix_column_names=False,
expected_result=["name", "degree", "score"]
)
def test_issue_input_columns_as_object(df_data, fix_column_names, expected_result):
df = pd.DataFrame(df_data).astype(object)
df = Shmessy().fix_schema(df=df, fix_column_names=fix_column_names)
assert [column for column in df] == expected_result

0 comments on commit 297294d

Please sign in to comment.