html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/6124#issuecomment-1007836513,https://api.github.com/repos/pydata/xarray/issues/6124,1007836513,IC_kwDOAMm_X848El1h,2443309,2022-01-08T00:18:34Z,2022-01-08T00:18:34Z,MEMBER,"I'm also late to the party but I would say I fall squarely in the Dataset is a dict-like camp. If we remove `__bool__`, should we also remove `__len__`? Basically, everything @dopplershift aligns with my perspective here.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1007746645,https://api.github.com/repos/pydata/xarray/issues/6124,1007746645,IC_kwDOAMm_X848EP5V,221526,2022-01-07T21:16:20Z,2022-01-07T21:16:20Z,CONTRIBUTOR,"$0.02 from the peanut gallery is that my mental model of `Dataset` is that it's a dictionary on steroids, so following the `Mapping` protocol (including `__bool__`) makes sense to me. I put ""I don't know"" for @shoyer's poll, but if the question was ""should"" then I would have said ""number of variables"". While I'm not going to sit here and argue that `if ds:` is a common operation and important feature (I don't often open files that result in empty datasets), I'd personally want a truly compelling argument for breaking from the `Mapping` protocol. Right now it's ""`Dataset` works like `dict` *plus* some stuff"". It would change to be ""`Dataset` works like `dict` for all things except `__bool__`, plus some stuff"". The latter to me requires more mental effort since I'm no longer strictly supplementing past experience.","{""total_count"": 2, ""+1"": 2, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1005918218,https://api.github.com/repos/pydata/xarray/issues/6124,1005918218,IC_kwDOAMm_X8479RgK,1217238,2022-01-05T17:16:56Z,2022-01-05T17:16:56Z,MEMBER,"I made a Twitter poll, let's see what that says 😄 https://twitter.com/xarray_dev/status/1478776987925684224?s=20","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1005907803,https://api.github.com/repos/pydata/xarray/issues/6124,1005907803,IC_kwDOAMm_X8479O9b,1217238,2022-01-05T17:05:14Z,2022-01-05T17:05:14Z,MEMBER,"After discussing this a little more, I am on the fence about whether this change this is a good idea. If we can't come to concensus about expected behavior, then that is probably an indication that we should leave things the same to avoid churn.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1004751649,https://api.github.com/repos/pydata/xarray/issues/6124,1004751649,IC_kwDOAMm_X84740sh,14371165,2022-01-04T12:04:42Z,2022-01-04T12:04:42Z,MEMBER,"I do wonder at what point a mapping isn't a mapping anymore? For example DataFrames aren't considered mappings: ```python isinstance(df, collections.abc.Mapping) Out[4]: False ``` And if we are to follow pandas example maybe we should just remove the Mapping inheritance? https://github.com/pydata/xarray/blob/60754fdbc4ecd9eb3c0978e82635c6d43e8d485b/xarray/core/dataset.py#L584","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1004669545,https://api.github.com/repos/pydata/xarray/issues/6124,1004669545,IC_kwDOAMm_X8474gpp,5635139,2022-01-04T09:58:51Z,2022-01-04T09:58:51Z,MEMBER,"TBC, I am fine merging! I would lightly vote against it, but weigh my vote far below @shoyer 's. And more broadly let's not wait for everyone to agree on everything!","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1004476940,https://api.github.com/repos/pydata/xarray/issues/6124,1004476940,IC_kwDOAMm_X8473xoM,2448579,2022-01-04T02:09:11Z,2022-01-04T02:09:11Z,MEMBER,"Sorry! I thought we had consensus but perhaps not? Shall we revert? That said it's `PendingDeprecationWarning` so it should only be raised in tests, which seems OK?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1004474062,https://api.github.com/repos/pydata/xarray/issues/6124,1004474062,IC_kwDOAMm_X8473w7O,1217238,2022-01-04T01:59:46Z,2022-01-04T01:59:46Z,MEMBER,"@dcherian So I guess we decided to go for it? :) @max-sixty We can still inherit from Mapping and just explicitly raise `TypeError` inside `Dataset.__bool__` rather than using the default implementation. This is certainly a slight violation from the Mapping protocol, but `xarray.Dataset` is already a little inconsistent (e.g., we override `__eq__` inconsistently with the default mapping behavior). Overall I think it's probably a worthwhile the more user-friendly choice?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1003482768,https://api.github.com/repos/pydata/xarray/issues/6124,1003482768,IC_kwDOAMm_X847z-6Q,5635139,2022-01-01T01:50:07Z,2022-01-01T01:50:37Z,MEMBER,"Would this mean that `Dataset` doesn't inherit from `Mapping` (in the end-state, after deprecation)? Or that we inherit from `Mapping` but override `bool` to raise an error?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1002777049,https://api.github.com/repos/pydata/xarray/issues/6124,1002777049,IC_kwDOAMm_X847xSnZ,3698640,2021-12-29T21:09:12Z,2021-12-29T21:09:12Z,CONTRIBUTOR,"I realize this may be a larger discussion, but the implementation is so easy I went ahead and filed a PR that issues a PendingDeprecationWarning in `Dataset.__bool__`.","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 1, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1002746595,https://api.github.com/repos/pydata/xarray/issues/6124,1002746595,IC_kwDOAMm_X847xLLj,1217238,2021-12-29T19:30:29Z,2021-12-29T19:30:29Z,MEMBER,"The original intention here was definitely to honor the `Mapping` protocol exactly, but I agree that `bool()` is hard to use correctly on `Dataset` objects. I would support deprecating this.","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 1, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1002673070,https://api.github.com/repos/pydata/xarray/issues/6124,1002673070,IC_kwDOAMm_X847w5Ou,3698640,2021-12-29T16:22:10Z,2021-12-29T16:22:10Z,CONTRIBUTOR,"> If there's a synthesis of keeping the truthiness while reducing the chance of these mistakes, that would be very welcome. @max-sixty im not sure what this would look like. Do you mean a warning or are you hinting that the bar that would need to be met is a silver bullet that preserves bool(ds) but somehow isn’t confusing?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1002671461,https://api.github.com/repos/pydata/xarray/issues/6124,1002671461,IC_kwDOAMm_X847w41l,3698640,2021-12-29T16:18:35Z,2021-12-29T16:18:35Z,CONTRIBUTOR,"Yeah… I do understand how it’s currently working and why, and the behavior is certainly intuitive to those who appreciate the mapping inheritance. That said, I feel I have to make a last stand argument because this trips people up quite often (on my team and elsewhere). I haven’t yet come across an example of anyone using this correctly, but I see users misusing it all the time. The examples and behavior you’re showing @Illviljan seem to me like more the natural result of an implementation detail than a critical principle of the dataset design. While it’s obvious why `bool(ds)` resolves to True or False in the current implementation, I still think it’s not used and is out of step with how most users think of a dataset. The fact that nothing in the package requires a change in order to pass tests (the broken tests and the pathological case aside) reaffirms for me that this is not a useful feature. I don’t know much about the mapping protocol or how closely it must be followed. Is the idea here that packages building on xarray (or interoperability features in e.g. numpy or dask) depend on a strict adherence to the full spec? ","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1002534942,https://api.github.com/repos/pydata/xarray/issues/6124,1002534942,IC_kwDOAMm_X847wXge,5635139,2021-12-29T10:53:53Z,2021-12-29T10:53:53Z,MEMBER,"I definitely empathize with the tradeoff here. That you found xarray's test's were making this error is fairly damning. But the biggest impediment to changing this behavior is that `Dataset` follows the `Mapping` protocol, which has this behavior. One nice feature of xarray is that we follow python's protocols where possible, and that includes truthiness for dict-like / `Mapping` objects. Notably `pd.DataFrame` objects only partially implement the protocol, including `.values`. If there's a synthesis of keeping the truthiness while reducing the chance of these mistakes, that would be very welcome. I'm not sure this is an improvement, but in the example converting to a `DataArray` gets away from the truthiness issue: `(result.min(...) >= 1.5).to_array().all()` (I wrote this before seeing @Illviljan 's response, which is very similar)","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430 https://github.com/pydata/xarray/issues/6124#issuecomment-1002441911,https://api.github.com/repos/pydata/xarray/issues/6124,1002441911,IC_kwDOAMm_X847wAy3,14371165,2021-12-29T07:49:07Z,2021-12-29T07:49:07Z,MEMBER,"A `Dataset` is more similar to a `dict` or `pd.DataFrame`. DataFrame has a similar error, same cooks I suppose: ```python bool(pd.DataFrame()) *** ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). bool(pd.DataFrame([[0, 2], [0, 4]], columns=['A', 'B'])) *** ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). ``` `dict` works the same way as a dataset, if something exist in it is `True`: ```python bool({}) False bool({'a': False}) True ``` I see ""if not empty do x""-checks all the time with dicts in python code, Is it that strange to follow the behavior of `dict`?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1090229430