Comparing against datetime.datetime and pd.Timestamp
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
Not sure if exactly bug and what performance implications there are but it'd be more user friendly if supported:
1.) comparing against datetime
import datetime
import pandas as pd
import xarray as xr
ds = xr.Dataset(coords={'int': [0, 1, 2]})
ds['data'] = ('int', [0, 5, 6])
ds.coords['time'] = ('int', pd.date_range('2017-02-01', '2017-02-03'))
ds = ds.where(ds['time'] > datetime.datetime(2017, 2, 2))
ds
TypeError: '>' not supported between instances of 'int' and 'datetime.datetime'
2.) pd.Timestamp
import datetime
import pandas as pd
import xarray as xr
ds = xr.Dataset(coords={'int': [0, 1, 2]})
ds['data'] = ('int', [0, 5, 6])
ds.coords['time'] = ('int', pd.date_range('2017-02-01', '2017-02-03'))
ds = ds.where(ds['time'] > pd.to_datetime('2017-02-02'))
ds
This works though when converting to np.datetime64
import datetime
import pandas as pd
import xarray as xr
ds = xr.Dataset(coords={'int': [0, 1, 2]})
ds['data'] = ('int', [0, 5, 6])
ds.coords['time'] = ('int', pd.date_range('2017-02-01', '2017-02-03'))
ds = ds.where(ds['time'] > pd.to_datetime(['2017-02-02']).values)
ds
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the two datetime comparison examples and the working np.datetime64 example from the issue. Trace the comparison and where-clause path used by ds['time'] > the scalar values. Done means datetime.datetime and pd.Timestamp comparisons work as shown without breaking the existing np.datetime64 behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100