Skip to content

Commit

Permalink
Update tools.py
Browse files Browse the repository at this point in the history
* refactoring functions
  • Loading branch information
jzsmoreno committed Nov 28, 2023
1 parent b9a4b55 commit 8db5ac0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
25 changes: 3 additions & 22 deletions pydbsmgr/lightest.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
import concurrent.futures
from collections import Counter

from pydbsmgr.main import *
from pydbsmgr.utils.tools import coerce_datetime
from functools import partial


def most_repeated_item(items: list) -> str:
# Use Counter to count occurrences of each item in the list
counter = Counter(items)

# Find the two most common items and its count
most_common = counter.most_common(2)

if len(most_common) == 2:
item1, _ = most_common[0]
item2, _ = most_common[1]
return item1, item2
else:
item, _ = most_common[0]
return item, None
from pydbsmgr.main import *
from pydbsmgr.utils.tools import coerce_datetime, most_repeated_item


def process_dates(x: str, format_type: str, auxiliary_type: str) -> str:
Expand All @@ -39,7 +22,7 @@ def process_dates(x: str, format_type: str, auxiliary_type: str) -> str:
x = str(x)
x = x.replace("/", "")
x = x.replace("-", "")
print(format_type, auxiliary_type)

if len(x) == 8:
try:
x = str(pd.to_datetime(x, format=format_type, errors="raise"))[:10]
Expand Down Expand Up @@ -84,7 +67,6 @@ def clean_frame(self, sample_frac: float = 0.1, fast_execution: bool = True) ->
)
)
)
print(format_type, auxiliary_type)
with concurrent.futures.ThreadPoolExecutor() as executor:
partial_dates = partial(
process_dates,
Expand All @@ -94,7 +76,6 @@ def clean_frame(self, sample_frac: float = 0.1, fast_execution: bool = True) ->
table[cols[column_index]] = list(
executor.map(partial_dates, table[cols[column_index]])
)
print(table[cols[column_index]])
table[cols[column_index]] = list(
executor.map(coerce_datetime, table[cols[column_index]])
)
Expand Down
17 changes: 17 additions & 0 deletions pydbsmgr/utils/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import random
import re
from collections import Counter
from typing import List

import numpy as np
Expand All @@ -20,6 +21,22 @@
from pydbsmgr.utils.config import load_config, parse_config


def most_repeated_item(items: list) -> str:
# Use Counter to count occurrences of each item in the list
counter = Counter(items)

# Find the two most common items and its count
most_common = counter.most_common(2)

if len(most_common) == 2:
item1, _ = most_common[0]
item2, _ = most_common[1]
return item1, item2
else:
item, _ = most_common[0]
return item, None


def generate_secure_password(pass_len: int = 24) -> str:
"""
Generate a secure password with the length specified
Expand Down

0 comments on commit 8db5ac0

Please sign in to comment.