Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] FRED Release Table: Fix Date Parsing For Format Variation #6608

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions openbb_platform/providers/fred/openbb_fred/models/release_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,29 @@ async def get_one(URL):

if "line" in df.columns:
df["line"] = df.line.astype(int)

# Some dates are in the format 'Jan 2021' and others are '2021-01-01'.
try:
df["observation_date"] = to_datetime(
df["observation_date"], format="%b %Y"
).dt.date
except ValueError:
df["observation_date"] = to_datetime(
df["observation_date"], format="%Y-%m-%d"
).dt.date
def apply_date_format(x):
"""Apply the date format."""
x = x.replace(" ", "-")
if x.startswith("Q"):
new_x = x.split("-")[-1]
q_dict = {
"Q1": "-03-31",
"Q2": "-06-30",
"Q3": "-09-30",
"Q4": "-12-31",
}
return new_x + q_dict[x.split("-")[0]]
try:
return to_datetime(x).dt.date
except ValueError:
try:
return to_datetime(x, format="%b-%Y").dt.date
except ValueError:
return x

df["observation_date"] = df.observation_date.apply(apply_date_format)
children = (
df.groupby("parent_id")["element_id"]
.apply(lambda x: x.sort_values().unique().tolist())
Expand Down
Loading