Skip to content

Commit 1c53aae

Browse files
author
Kaden McKeen
committed
Created date parsing and reconciliation systems for robust date handling.
1 parent 5c4ebb2 commit 1c53aae

File tree

10 files changed

+1958
-0
lines changed

10 files changed

+1958
-0
lines changed

cyclops/data/df/dates/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Processors for date handling."""

cyclops/data/df/dates/common.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from typing import Any, Dict, List, Optional, Set, Union
2+
3+
import numpy as np
4+
5+
6+
def to_list(obj: Any) -> List[Any]:
7+
"""Convert some object to a list of object(s) unless already one.
8+
9+
Parameters
10+
----------
11+
obj : any
12+
The object to convert to a list.
13+
14+
Returns
15+
-------
16+
list
17+
The processed object.
18+
19+
"""
20+
if isinstance(obj, list):
21+
return obj
22+
23+
if isinstance(obj, (np.ndarray, set, dict)):
24+
return list(obj)
25+
26+
return [obj]
27+
28+
29+
def to_list_optional(
30+
obj: Optional[Any], none_to_empty: bool = False
31+
) -> Union[List[Any], None]:
32+
"""Convert some object to a list of object(s) unless already None or a list.
33+
34+
Parameters
35+
----------
36+
obj : any
37+
The object to convert to a list.
38+
none_to_empty: bool, default = False
39+
If true, return a None obj as an empty list. Otherwise, return as None.
40+
41+
Returns
42+
-------
43+
list or None
44+
The processed object.
45+
46+
"""
47+
if obj is None:
48+
if none_to_empty:
49+
return []
50+
return None
51+
52+
return to_list(obj)

0 commit comments

Comments
 (0)