From pandas integraton with pyarrow here
import pyarrow as pa
from datetime import date
df2 = pd.Series({'date':[date(2022,4,7)]})
df2_dat32 = pa.array(df2)
print("dataframe:", df2)
print("value of dataframe:", df2_dat32[0])
print("datatype:", df2_dat32.type)
Output
dataframe: date [2022-04-07]
dtype: object
value of dataframe: [datetime.date(2022, 4, 7)]
datatype: list<item: date32[day]>
Edit: If you have entire column of dates, you will need to first convert datetime to date and then use same method as above. See example below:
import pyarrow as pa
from datetime import date
#create pandas DataFrame with one column with five
#datetime values through a dictionary
datetime_df = pd.DataFrame({'DateTime': ['2021-01-15 20:02:11',
'1989-05-24 20:34:11',
'2020-01-18 14:43:24',
'2021-01-15 20:02:10',
'1999-04-04 20:34:11']})
datetime_df['Date'] = pd.to_datetime(datetime_df['DateTime']).dt.date
date_series = pd.Series(datetime_df['Date'])
print(date_series)
Output:
0 2021-01-15
1 1989-05-24
2 2020-01-18
3 2021-01-15
4 1999-04-04
Name: Date, dtype: object
Then use pyarrow for conversion:
df2_dat32 = pa.array(date_series)
print("datatype of values in the dataframe with dates:", type(date_series[0]))
print("value of dataframe after converting using pyarrow:", df2_dat32[0])
print("datatype after converting using pyarrow :", df2_dat32.type)
Output:
datatype of values in the dataframe with dates: <class 'datetime.date'>
value of dataframe after converting using pyarrow: 2021-01-15
datatype after converting using pyarrow : date32[day]