Skip to content

Commit

Permalink
[fix] Updating parse_human_timedelta typing (apache#8436)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Oct 23, 2019
1 parent 08c6b61 commit 786d770
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions superset/common/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def __init__(
)
self.is_timeseries = is_timeseries
self.time_range = time_range
self.time_shift = (
utils.parse_human_timedelta(time_shift) if time_shift else None
)
self.time_shift = utils.parse_human_timedelta(time_shift)
self.groupby = groupby or []

# Temporal solution for backward compatability issue
Expand Down
2 changes: 1 addition & 1 deletion superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def default(self, o):
return json.JSONEncoder(sort_keys=True).default(self, o)


def parse_human_timedelta(s: str) -> timedelta:
def parse_human_timedelta(s: Optional[str]) -> timedelta:
"""
Returns ``datetime.datetime`` from natural language time deltas
Expand Down
1 change: 1 addition & 0 deletions tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_parse_human_timedelta(self, mock_datetime):
self.assertEqual(parse_human_timedelta("now"), timedelta(0))
self.assertEqual(parse_human_timedelta("1 year"), timedelta(366))
self.assertEqual(parse_human_timedelta("-1 year"), timedelta(-365))
self.assertEqual(parse_human_timedelta(None), timedelta(0))

@patch("superset.utils.core.datetime")
def test_parse_past_timedelta(self, mock_datetime):
Expand Down

0 comments on commit 786d770

Please sign in to comment.