Skip to content

Fix UxDataset.to_array() missing args/kwargs dim and name#1521

Open
Sevans711 wants to merge 2 commits into
UXARRAY:mainfrom
Sevans711:dataset_to_array_with_args
Open

Fix UxDataset.to_array() missing args/kwargs dim and name#1521
Sevans711 wants to merge 2 commits into
UXARRAY:mainfrom
Sevans711:dataset_to_array_with_args

Conversation

@Sevans711

Copy link
Copy Markdown

Closes #1520

Overview

UxDataset.to_array() did not allow args/kwargs, even though Dataset.to_array() allows to input dim and name. This commit allows UxDataset.to_array() to accept dim and name (they are simply passed through to super().to_array()), and also adds a corresponding test in test_dataset.py.

Expected Usage

import uxarray as ux

grid_path = "/path/to/grid.nc"
data_path = "/path/to/data.nc"

uxds = ux.open_dataset(grid_path, data_path)

example1 = uxds.to_array(dim="custom_dim_name")  # instead of the default, dim="variable"
assert "custom_dim_name" in example1.dims

example2 = uxds.to_array(name="custom_arr_name")  # instead of the default, name = None
assert example2.name == "custom_arr_name"

PR Checklist

General

  • An issue is linked created and linked
  • Add appropriate labels
  • Filled out Overview and Expected Usage (if applicable) sections

Testing

  • Adequate tests are created if there is new functionality
  • Tests cover all possible logical paths in your function
  • Tests are not too basic (such as simply calling a function and nothing else)

Documentation

  • [N/A] Docstrings have been added to all new functions
  • Docstrings have updated with any function changes
  • [N/A] Internal functions have a preceding underscore (_) and have been added to docs/internal_api/index.rst
  • [N/A] User functions have been added to docs/user_api/index.rst

Sevans711 added 2 commits June 9, 2026 13:17
UxDataset.to_array() did not allow args/kwargs, even though Dataset.to_array() allows to input `dim` and `name`. This commit allows UxDataset.to_array() to accept dim and name (they are simply passed through to super().to_array()), and also adds a corresponding test in test_dataset.py.
Forgot to pre-commit run --all-files before committing 8e1a83f
@rajeeja

rajeeja commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @Sevans711 for the contribution! Clean fix and good test coverage. We'd love to know what use case prompted this — always helpful to understand how people are using UXarray in practice. Please keep the issues and PRs coming!

@rajeeja rajeeja self-requested a review June 9, 2026 23:43

@rajeeja rajeeja left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean fix, good test coverage.

@Sevans711

Copy link
Copy Markdown
Author

Sweet! I don't yet have a full science use case for this, I was just taking a closer look at UXarray and how it works! In addition to using UXarray's builtin plotting routines I also tried applying some of my plotting routines from my previous xarray experience to try to understand the raw data (from my package PlasmaCalcs which relies heavily on xarray). Many of those routines try to be extremely flexible about inputs, such as automatically converting Dataset to DataArray but with a custom method that first checks the resulting array won't be "unexpectedly way too big" due to combining data_vars with unrelated dimensions. That method takes an optional "dim" kwarg (set to dim='variable' by default) for the conversion, which caused me to notice the crash when supplying a UxDataset instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UxDataset.to_array() missing args/kwargs dim and name

2 participants