Closed Flix6x closed 4 years ago
The issue is possibly around here
1090 # if we have the same frequency as our axis, then we are equal sampling
1091 if limit is None and to_offset(ax.inferred_freq) == self.freq:
1092 result = obj.copy()
-> 1093 result.index = res_index
1094 else:
1095 result = obj.reindex(
1096 res_index, method=method, limit=limit, fill_value=fill_value
1097 )
Do we also need a length check in that if condition? Can you investigate @Flix6x?
And given the discussion in https://github.com/pandas-dev/pandas/issues/35248, is this a duplicate or distinct?
Adding the length check and len(obj) == len(res_index)
to line 1091 indeed resolves the problem.
I would have actually expected the preceding offset comparison to fail:
>>> pd.offsets.Day(1) == pd.offsets.Hour(24)
True
To me, adding the length check remedies a symptom of maintaining this equality. Both date_range()
and resample()
treat pd.offsets.Day(1)
as a calendar day, in which case this equality shouldn't hold.
This issue is distinct from #35248, and both are symptoms of #22864. Your suggested fix would resolve this issue (which deals with offsets only), but not #35248 (which deals with pandas offsets versus datetime timedeltas).
Would you like me to make a pull request (with or without test)?
That'd be great (including a test).
Adding the length check
and len(obj) == len(res_index)
to line 1091 indeed resolves the problem.I would have actually expected the preceding offset comparison to fail:
>>> pd.offsets.Day(1) == pd.offsets.Hour(24) True
To me, adding the length check remedies a symptom of maintaining this equality. Both
date_range()
andresample()
treatpd.offsets.Day(1)
as a calendar day, in which case this equality shouldn't hold.This issue is distinct from #35248, and both are symptoms of #22864. Your suggested fix would resolve this issue (which deals with offsets only), but not #35248 (which deals with pandas offsets versus datetime timedeltas).
Would you like me to make a pull request (with or without test)?
yeah we had quite some discussion about #22864 and actually @mroeschke pushed a patch, but its too big of a change to do in a minor release; we would have to wait till 2.0 for this.
[x] I have checked that this issue has not already been reported.
[x] I have confirmed this bug exists on the latest version of pandas.
[x] (optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
In my first example, resampling from an offset of 1 day to an offset of 24 hours works as expected, but only when the start and end of the DatetimeIndex share the same timezone. In my second example the date range start and ends in a different timezone due to a daylight savings transition on 29 March 2020, for which resampling to 24 hours fails.
Possibly related issue:
35248
Expected Output
Output of
pd.show_versions()