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

Add missing DataArray.dt.total_seconds() method #8435

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

maresb
Copy link
Contributor

@maresb maresb commented Nov 9, 2023

Add .total_seconds() to match the Pandas API.

@maresb
Copy link
Contributor Author

maresb commented Nov 9, 2023

Ugh:

AssertionError: Left and right DataArray objects are not identical

https://github.com/pydata/xarray/actions/runs/6816167406/job/18536890731?pr=8435#step:9:297

I don't understand why not. It passes locally. Anyone have any ideas?

@maresb
Copy link
Contributor Author

maresb commented Nov 9, 2023

Interesting. I installed the xarray-tests bare-minimum environment, and actual - expected is:

<xarray.DataArray 'total_seconds' (time: 100)>
array([ 0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
       -1.45519152e-11, -1.45519152e-11, -1.45519152e-11, -1.45519152e-11,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00, -7.27595761e-12, -7.27595761e-12,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00, -3.63797881e-12,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  3.63797881e-12,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  7.27595761e-12,  7.27595761e-12,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  1.45519152e-11,  1.45519152e-11,  1.45519152e-11,
        1.45519152e-11,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,
        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00])
Coordinates:
  * time     (time) datetime64[ns] 2000-01-01 ... 2000-01-05T03:00:00

name="total_seconds",
coords=[self.data.time],
)
assert_identical(expected, actual)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we switch to assert_allclose?

Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

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

Looks good! And I think the test is an easy fix

@maresb
Copy link
Contributor Author

maresb commented Nov 9, 2023

Ya, will do. Just bisected the problem to Pandas <1.5

@maresb
Copy link
Contributor Author

maresb commented Nov 9, 2023

Cool, looks like the only tests currently failing are those that were previously failing.

@max-sixty
Copy link
Collaborator

Nice, thanks @maresb !

@max-sixty max-sixty merged commit 0ba2eb0 into pydata:main Nov 10, 2023
20 of 28 checks passed
@maresb maresb deleted the total-seconds branch November 10, 2023 07:13
dcherian added a commit to rabernat/xarray that referenced this pull request Nov 29, 2023
* main:
  [skip-ci] dev whats-new (pydata#8467)
  2023.11.0 Whats-new (pydata#8461)
  migrate the other CI to python 3.11 (pydata#8416)
  preserve vlen string dtypes, allow vlen string fill_values (pydata#7869)
  Pin mypy < 1.7 (pydata#8458)
  Fix typos found by codespell (pydata#8457)
  [skip-ci] Small updates to IO docs. (pydata#8452)
  Deprecate certain cftime frequency strings following pandas (pydata#8415)
  Added driver parameter for h5netcdf (pydata#8360)
  Raise exception in to_dataset if resulting variable is also the name of a coordinate (pydata#8433)
  Automatic region detection and transpose for `to_zarr()` (pydata#8434)
  remove `cdms2` (pydata#8441)
  Remove PseudoNetCDF (pydata#8446)
  Pin pint to >=0.22 (pydata#8445)
  Remove keep_attrs from resample signature (pydata#8444)
  Rename `to_array` to `to_dataarray` (pydata#8438)
  Add missing DataArray.dt.total_seconds() method (pydata#8435)
  Declare Dataset, DataArray, Variable, GroupBy unhashable (pydata#8392)
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.

DataArray.dt.seconds returns incorrect value for negative timedelta64[ns]
2 participants