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

xarray Dataset.dims FutureWarning #246

Closed
nannau opened this issue Jul 9, 2024 · 0 comments · Fixed by #247
Closed

xarray Dataset.dims FutureWarning #246

nannau opened this issue Jul 9, 2024 · 0 comments · Fixed by #247
Labels
bug Something isn't working

Comments

@nannau
Copy link

nannau commented Jul 9, 2024

Hi there! New ncompare user here. I'm finding it quite useful so far. Many thanks to the developers for providing a great project. "Bug" isn't the best label here, but I wouldn't consider this an enhancement or feature request.

This issue is quite easy to fix, but its output is a bit annoying, especially when comparing lots of files like I am currently doing. Plus, it looks like this change will need to be made anyway. As far as I can tell, there are no functional issues related to this warning (yet).

Expected Behavior

I expect no warnings to be issued.

Actual Behavior

A FutureWarning is displayed related to the attribute dims vs sizes of an xarray dataset. It is raised every time ncompare is used. This does not appear to be related to usage of ncompare, rather, a hardcoded assumption related to an xarray object attribute in ncompare.
E.g.:

FutureWarning: The return type of `Dataset.dims` will be changed to return a set of dimension names in future, in order to be more consistent with `DataArray.dims`.
To access a mapping from dimension names to lengths, please use `Dataset.sizes`.

Steps to Reproduce the Problem

  1. Install latest ncompare with pip following: https://github.com/nannau/ncompare/tree/main?tab=readme-ov-file#option-b-using-pip
  2. I am running ncompare from a Python subprocess.call with:
      subprocess.call(
          [
              "ncompare",
              "--column-widths",
              "33",
              "26",
              "26",
              control_path,
              experiment_path,
              "--only-diffs",
              "--file-text",
              f"{output_path}/{control_filename}_diffs.txt",
          ],
      )
  1. The error obviously persists if run manually from terminal, e.g.:
ncompare --column-widths 33 26 26 /path/to/control.nc /path/to/experiment.nc --only-diffs --file-text diffs.txt

Proposed solution

In this line of core.py we simply adopt the suggested change to be:

return list(dataset.sizes.items())

I have a fork with this change implemented that I am planning on submitting a PR with.

This change looks like it was introduced in xarray version v2023.12.0 (2023 Dec 08) so I would recommend changing related requirements to avoid backward compatibility issues.

Specifications

  • Version: Latest installed from source following these instructions
  • Xarray version: 2024.6.0
  • Platform: Linux
@nannau nannau added the bug Something isn't working label Jul 9, 2024
@nannau nannau changed the title xarray FutureWarning xarray Dataset.dims FutureWarning Jul 9, 2024
@danielfromearth danielfromearth linked a pull request Jul 10, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants