PitterPatterPython / qgrid

A Clone of QGrid to Make Small Changes to keep it working with JupyterLab 3.0 and beyond
Apache License 2.0
16 stars 3 forks source link

pandas version 140: "Error displaying widget" for dataframe with null data #5

Open GaryScottMartin opened 2 years ago

GaryScottMartin commented 2 years ago

Upgrade to pandas 1.4.0 resulted in "Error displaying widget" for pandas dateframe containing dummy data, but not for dataframe containing valid data. Both sets of code below worked properly prior to upgrade to 1.4.0. Problem resolved by going back to pandas 1.3.5. Pandas 1.4.0 works properly for me with a pandas dataframe with valid data, but not with dummy data (valid dates but null numeric and datetime values meant to be replaced from qgrid.

This code still works in pandas 1.4.0 `

Import libraries

import pandas as pd pd.options.plotting.backend = "matplotlib" import datetime as dt import numpy as np import qgrid as qg %load_ext sql

%sql sqlite:///NightlySleepDurations.sqlite3 result = %sql SELECT * from SLEEP_DURATIONS; df = result.DataFrame() df["sleep_date"] = pd.to_datetime(df["sleep_date"]) df_qg = qg.show_grid(df, show_toolbar = True)`

df_qg

This code produces "Error displaying widget:"

'

Import libraries

import pandas as pd pd.options.plotting.backend = "matplotlib" import datetime as dt import numpy as np import qgrid as qg %load_ext sql

def td_to_str(x): ts = x.total_seconds() hours, remainder = divmod(ts, 3600) minutes, seconds = divmod(remainder, 60) return ('{:02d}:{:02d}').format(int(hours), int(minutes))

def td_to_hrs(x): return x.total_seconds()/3600

adtnl_rows = None %sql sqlite:///NightlySleepDurations.sqlite3 result = %sql SELECT * from SLEEP_DURATIONS; df = result.DataFrame() len_in = df.shape[0] df["sleep_date"] = pd.to_datetime(df["sleep_date"]) last_date_in = df.loc[len_in-1,"sleep_date"] days_to_add = (dt.datetime.now() - last_date_in).days if days_to_add > 0: day_to_add_first = last_date_in + dt.timedelta(days=1) day_to_add_last = last_date_in + dt.timedelta(days=days_to_add) dummy_index = np.arange(1,days_to_add+1,1) dti = pd.date_range(start = day_to_add_first, end = day_to_add_last, freq='D') dummy_td = pd.Series(np.nan,index=dummy_index,dtype='float64') dummy_tdhm = pd.Series(np.nan,index=dummy_index,dtype='string') adtnl_rows = pd.DataFrame({ 'sleep_date': dti, \ 'total_duration': dummy_td, \ 'total_duration_hm': dummy_tdhm \ }) df_qg=qg.show_grid(adtnl_rows, show_toolbar=True) '

'df_qg' "Error displaying widget:"

================================ While repeating the install process the following are warnings produced by npm in the setyup.py step. (Not sure this is significant, but I don't remember seeing these warnings previously.)

`Installing build dependencies with npm. This may take a while... npm WARN deprecated crypto@1.0.1: This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in. npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142 npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead. npm WARN deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated request@2.88.0: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

`

JohnOmernik commented 6 months ago

Highly recommend people check out https://github.com/zhihanyue/qgridnext