OpenBB icon indicating copy to clipboard operation
OpenBB copied to clipboard

[Bug] `econometrics\load macrodata` Cannot format dates properly to set the index.

Open deeleeramone opened this issue 2 years ago • 8 comments

If you load one of the sample data sets in the Econometrics menu, for this example it is macrodata, the column for year is formatted as an abbreviated integer in thousands.

Screenshot 2023-04-07 at 12 35 09 PM

type macrodata.year --format date then converts them all to 0.000. Screenshot 2023-04-07 at 12 36 22 PM

It would be a reasonable argument to make that type --format date is not sufficient for converting these values. This should convert to a DatetimeIndex and allow for the desired formatting of the date and time.

With the inability to correct this, you can't set the index and it essentially becomes impossible to do any meaningful analysis or calculations. Furthermore, upon loading any data set, it should automatically find the column titled, date or year/month and format the DataFrame appropriately.

deeleeramone avatar Apr 07 '23 19:04 deeleeramone

I am trying to fix it by adding the following code in helper_funcs.py:

for col in df_outgoing.columns:
      if col == "":
          df_outgoing = df_outgoing.rename(columns={col: "  "})
      # My code starts here
      if col.lower() == "year":
          df_outgoing[col] = df_outgoing[col].astype(int)
      if col.lower() in ("period", "date"):
          df_outgoing[col] = pd.to_datetime(
              df_outgoing[col], format="%Y-%m-%d"
          )

This work when I use console.print(df_outgoing) to output the resulting dataframe image

However there is no change in the output window image

Any clue about this behavior of the print_rich_table function?

dot-agi avatar Apr 11 '23 08:04 dot-agi

change type to string on year column

tehcoderer avatar Apr 12 '23 00:04 tehcoderer

@tehcoderer changing year to str will show 1960.0 instead of our desired output 1960.

dot-agi avatar Apr 12 '23 01:04 dot-agi

Issue extends to the datetime type index

image

dot-agi avatar Apr 12 '23 03:04 dot-agi

@tehcoderer changing year to str will show 1960.0 instead of our desired output 1960.

Convert the date to a string. An integer does not have a decimal, so you must have converted to a float first.

deeleeramone avatar Apr 12 '23 15:04 deeleeramone

@tehcoderer changing year to str will show 1960.0 instead of our desired output 1960.

Convert the date to a string. An integer does not have a decimal, so you must have converted to a float first.

The dataset was loaded with float64 dtype by default. I tried this approach but found a more direct and suitable way to fix it. Please feel free to review the commit (#4742). It works as intended on my end.

If you find any more issues, please ping me and I will fix them as soon as I can.

dot-agi avatar Apr 12 '23 15:04 dot-agi

Fixed in #4848 👍

tehcoderer avatar Apr 20 '23 21:04 tehcoderer

@tehcoderer changing year to str will show 1960.0 instead of our desired output 1960.

yeah had to convert to int then str for it to work when I tested today lol.

tehcoderer avatar Apr 20 '23 21:04 tehcoderer

Fixed in #4848

deeleeramone avatar Apr 26 '23 02:04 deeleeramone