Skip to content

Commit 1c98206

Browse files
code sample for pandas-dev#40799
1 parent a3273b2 commit 1c98206

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

bisect/40799.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# BUG: behavior change in dataframe.shift(, freq=infer) when upgrading from
2+
# pandas 1.1.5 to 1.2.x #40799
3+
4+
import io
5+
6+
import numpy as np
7+
8+
import pandas as pd
9+
10+
print(pd.__version__)
11+
12+
# replicate the typical data I am reading with pd.rea_csv
13+
dates = np.arange(0, 600.1, 0.1)
14+
dateString = "time, count\n"
15+
for count, time in enumerate(dates):
16+
dateString = dateString + "{:0.3f}, {}\n".format(time, count)
17+
18+
19+
# create dataframe and convert 'time' as a datetime and put it to index.
20+
df = pd.read_csv(io.BytesIO(dateString.encode()), sep=",")
21+
df["date"] = pd.to_datetime(df.time, unit="s")
22+
df.set_index("date", inplace=True, drop=False)
23+
print(df)
24+
25+
df.shift(
26+
1, freq="infer"
27+
) # <-- this is working with pandas 1.1.5 but not any more with 1.2.0 and above
28+
print(df)

0 commit comments

Comments
 (0)