-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Dataset.to_dataframe() dimension order is not alphabetically sorted by default #9653
Comments
this looks like a documentation bug: we can't really sort non-string names alphabetically, so instead we should remove that claim. PRs welcome! |
Makes sense, I was also a bit surprised to find this inconsistent behavior discussed in that issue comment. I suppose the correct wording would be something like "the dimensions are in the order in which they appear in the import xarray as xr
ds = xr.Dataset({
"foo": xr.DataArray(coords=[("x", [1, 2, 3]), ("y", [1, 2, 3])]),
"bar": xr.DataArray(coords=[("y", [1, 2, 3]), ("x", [1, 2, 3])]),
"baz": xr.DataArray(coords=[("x", [1, 2, 3])]),
"qux": xr.DataArray(coords=[("y", [1, 2, 3])]),
})
print(ds.to_dataframe()) |
We used to sort dimension names in So yes, this is definitely worthy of updating/fixing the documentation! |
I would say Dimensions appear in the same order as |
What happened?
Hi, I noticed that the documentation for
Dataset.to_dataframe()
says that "by default, dimensions are sorted alphabetically". This is contrast withDataArray.to_dataframe()
, where the order is given by the order of the dimensions in theDataArray
, which was discussed in this comment.However, it appears that
Dataset.to_dataframe()
doesn't in fact sort the orders alphabetically with this example on current main 8f6e45b:I get
What did you expect to happen?
The dimensions in the output should be sorted alphabetically, like this:
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
commit: None
python: 3.12.7 (main, Oct 1 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)]
python-bits: 64
OS: Linux
OS-release: 6.11.3-200.fc40.x86_64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None
xarray: 2024.9.1.dev73+g8f6e45ba
pandas: 2.2.3
numpy: 1.26.4
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 69.0.3
pip: 24.0
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None
The text was updated successfully, but these errors were encountered: