Testing wrapping frames in proxy wrappers
()
| 4992 | |
| 4993 | |
| 4994 | def test_use_of_weakref_proxy(): |
| 4995 | """Testing wrapping frames in proxy wrappers""" |
| 4996 | df = pd.DataFrame({"data": [1, 2, 3]}) |
| 4997 | df_pxy = weakref.proxy(df) |
| 4998 | ser = pd.Series({"data": [1, 2, 3]}) |
| 4999 | ser_pxy = weakref.proxy(ser) |
| 5000 | |
| 5001 | assert is_dataframe_like(df_pxy) |
| 5002 | assert is_series_like(ser_pxy) |
| 5003 | |
| 5004 | assert dask.dataframe.groupby._cov_chunk(df_pxy, "data") |
| 5005 | assert isinstance( |
| 5006 | dask.dataframe.groupby._groupby_apply_funcs(df_pxy, "data", funcs=[]), |
| 5007 | pd.DataFrame, |
| 5008 | ) |
| 5009 | |
| 5010 | # Test wrapping each Dask dataframe chunk in a proxy |
| 5011 | l = [] |
| 5012 | |
| 5013 | def f(x): |
| 5014 | l.append(x) # Keep `x` alive |
| 5015 | return weakref.proxy(x) |
| 5016 | |
| 5017 | d = pd.DataFrame({"g": [0, 0, 1] * 3, "b": [1, 2, 3] * 3}) |
| 5018 | a = dd.from_pandas(d, npartitions=1) |
| 5019 | a = a.map_partitions(f, meta=a._meta) |
| 5020 | pxy = weakref.proxy(a) |
| 5021 | res = pxy["b"].groupby(pxy["g"]).sum() |
| 5022 | isinstance(res.compute(), pd.Series) |
| 5023 | |
| 5024 | |
| 5025 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected