Skip to content

Commit b305323

Browse files
SNOW-2409065: Add support for Series.dt properties (#3887)
1 parent ce295e4 commit b305323

File tree

3 files changed

+365
-0
lines changed

3 files changed

+365
-0
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
- `st_ymax`
5151
- `st_ymin`
5252

53+
5354
#### Bug Fixes
5455

5556
- Fixed a bug that `DataFrameReader.xml` fails to parse XML files with undeclared namespaces when `ignoreNamespace` is `True`.
@@ -82,6 +83,26 @@
8283
- `str.startswith`
8384
- `str.endswith`
8485
- `str.slice`
86+
- `dt.date`
87+
- `dt.time`
88+
- `dt.hour`
89+
- `dt.minute`
90+
- `dt.second`
91+
- `dt.microsecond`
92+
- `dt.nanosecond`
93+
- `dt.year`
94+
- `dt.month`
95+
- `dt.day`
96+
- `dt.quarter`
97+
- `dt.is_month_start`
98+
- `dt.is_month_end`
99+
- `dt.is_quarter_start`
100+
- `dt.is_quarter_end`
101+
- `dt.is_year_start`
102+
- `dt.is_year_end`
103+
- `dt.is_leap_year`
104+
- `dt.days_in_month`
105+
- `dt.daysinmonth`
85106
- `sort_values`
86107
- `to_datetime`
87108
- Reuse row count from the relaxed query compiler in `get_axis_len`.

src/snowflake/snowpark/modin/plugin/compiler/snowflake_query_compiler.py

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13158,42 +13158,180 @@ def columnarize(self) -> "SnowflakeQueryCompiler":
1315813158
return self
1315913159

1316013160
def dt_date(self) -> "SnowflakeQueryCompiler":
13161+
"""
13162+
Wrapper around _dt_date_internal to be supported in faster pandas.
13163+
"""
13164+
relaxed_query_compiler = None
13165+
if self._relaxed_query_compiler is not None:
13166+
relaxed_query_compiler = self._relaxed_query_compiler._dt_date_internal()
13167+
qc = self._dt_date_internal()
13168+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13169+
13170+
def _dt_date_internal(self) -> "SnowflakeQueryCompiler":
1316113171
return self.dt_property("date")
1316213172

1316313173
def dt_time(self) -> "SnowflakeQueryCompiler":
13174+
"""
13175+
Wrapper around _dt_time_internal to be supported in faster pandas.
13176+
"""
13177+
relaxed_query_compiler = None
13178+
if self._relaxed_query_compiler is not None:
13179+
relaxed_query_compiler = self._relaxed_query_compiler._dt_time_internal()
13180+
qc = self._dt_time_internal()
13181+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13182+
13183+
def _dt_time_internal(self) -> "SnowflakeQueryCompiler":
1316413184
return self.dt_property("time")
1316513185

1316613186
def dt_timetz(self) -> "SnowflakeQueryCompiler":
13187+
"""
13188+
Wrapper around _dt_timetz_internal to be supported in faster pandas.
13189+
"""
13190+
relaxed_query_compiler = None
13191+
if self._relaxed_query_compiler is not None:
13192+
relaxed_query_compiler = self._relaxed_query_compiler._dt_timetz_internal()
13193+
qc = self._dt_timetz_internal()
13194+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13195+
13196+
def _dt_timetz_internal(self) -> "SnowflakeQueryCompiler":
1316713197
return self.dt_property("timetz")
1316813198

1316913199
def dt_year(self) -> "SnowflakeQueryCompiler":
13200+
"""
13201+
Wrapper around _dt_year_internal to be supported in faster pandas.
13202+
"""
13203+
relaxed_query_compiler = None
13204+
if self._relaxed_query_compiler is not None:
13205+
relaxed_query_compiler = self._relaxed_query_compiler._dt_year_internal()
13206+
qc = self._dt_year_internal()
13207+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13208+
13209+
def _dt_year_internal(self) -> "SnowflakeQueryCompiler":
1317013210
return self.dt_property("year")
1317113211

1317213212
def dt_month(self) -> "SnowflakeQueryCompiler":
13213+
"""
13214+
Wrapper around _dt_month_internal to be supported in faster pandas.
13215+
"""
13216+
relaxed_query_compiler = None
13217+
if self._relaxed_query_compiler is not None:
13218+
relaxed_query_compiler = self._relaxed_query_compiler._dt_month_internal()
13219+
qc = self._dt_month_internal()
13220+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13221+
13222+
def _dt_month_internal(self) -> "SnowflakeQueryCompiler":
1317313223
return self.dt_property("month")
1317413224

1317513225
def dt_day(self) -> "SnowflakeQueryCompiler":
13226+
"""
13227+
Wrapper around _dt_day_internal to be supported in faster pandas.
13228+
"""
13229+
relaxed_query_compiler = None
13230+
if self._relaxed_query_compiler is not None:
13231+
relaxed_query_compiler = self._relaxed_query_compiler._dt_day_internal()
13232+
qc = self._dt_day_internal()
13233+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13234+
13235+
def _dt_day_internal(self) -> "SnowflakeQueryCompiler":
1317613236
return self.dt_property("day")
1317713237

1317813238
def dt_hour(self) -> "SnowflakeQueryCompiler":
13239+
"""
13240+
Wrapper around _dt_hour_internal to be supported in faster pandas.
13241+
"""
13242+
relaxed_query_compiler = None
13243+
if self._relaxed_query_compiler is not None:
13244+
relaxed_query_compiler = self._relaxed_query_compiler._dt_hour_internal()
13245+
qc = self._dt_hour_internal()
13246+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13247+
13248+
def _dt_hour_internal(self) -> "SnowflakeQueryCompiler":
1317913249
return self.dt_property("hour")
1318013250

1318113251
def dt_minute(self) -> "SnowflakeQueryCompiler":
13252+
"""
13253+
Wrapper around _dt_minute_internal to be supported in faster pandas.
13254+
"""
13255+
relaxed_query_compiler = None
13256+
if self._relaxed_query_compiler is not None:
13257+
relaxed_query_compiler = self._relaxed_query_compiler._dt_minute_internal()
13258+
qc = self._dt_minute_internal()
13259+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13260+
13261+
def _dt_minute_internal(self) -> "SnowflakeQueryCompiler":
1318213262
return self.dt_property("minute")
1318313263

1318413264
def dt_second(self) -> "SnowflakeQueryCompiler":
13265+
"""
13266+
Wrapper around _dt_second_internal to be supported in faster pandas.
13267+
"""
13268+
relaxed_query_compiler = None
13269+
if self._relaxed_query_compiler is not None:
13270+
relaxed_query_compiler = self._relaxed_query_compiler._dt_second_internal()
13271+
qc = self._dt_second_internal()
13272+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13273+
13274+
def _dt_second_internal(self) -> "SnowflakeQueryCompiler":
1318513275
return self.dt_property("second")
1318613276

1318713277
def dt_microsecond(self) -> "SnowflakeQueryCompiler":
13278+
"""
13279+
Wrapper around _dt_microsecond_internal to be supported in faster pandas.
13280+
"""
13281+
relaxed_query_compiler = None
13282+
if self._relaxed_query_compiler is not None:
13283+
relaxed_query_compiler = (
13284+
self._relaxed_query_compiler._dt_microsecond_internal()
13285+
)
13286+
qc = self._dt_microsecond_internal()
13287+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13288+
13289+
def _dt_microsecond_internal(self) -> "SnowflakeQueryCompiler":
1318813290
return self.dt_property("microsecond")
1318913291

1319013292
def dt_nanosecond(self) -> "SnowflakeQueryCompiler":
13293+
"""
13294+
Wrapper around _dt_nanosecond_internal to be supported in faster pandas.
13295+
"""
13296+
relaxed_query_compiler = None
13297+
if self._relaxed_query_compiler is not None:
13298+
relaxed_query_compiler = (
13299+
self._relaxed_query_compiler._dt_nanosecond_internal()
13300+
)
13301+
qc = self._dt_nanosecond_internal()
13302+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13303+
13304+
def _dt_nanosecond_internal(self) -> "SnowflakeQueryCompiler":
1319113305
return self.dt_property("nanosecond")
1319213306

1319313307
def dt_dayofweek(self) -> "SnowflakeQueryCompiler":
13308+
"""
13309+
Wrapper around _dt_dayofweek_internal to be supported in faster pandas.
13310+
"""
13311+
relaxed_query_compiler = None
13312+
if self._relaxed_query_compiler is not None:
13313+
relaxed_query_compiler = (
13314+
self._relaxed_query_compiler._dt_dayofweek_internal()
13315+
)
13316+
qc = self._dt_dayofweek_internal()
13317+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13318+
13319+
def _dt_dayofweek_internal(self) -> "SnowflakeQueryCompiler":
1319413320
return self.dt_property("dayofweek")
1319513321

1319613322
def dt_isocalendar(self) -> "SnowflakeQueryCompiler":
13323+
"""
13324+
Wrapper around _dt_isocalendar_internal to be supported in faster pandas.
13325+
"""
13326+
relaxed_query_compiler = None
13327+
if self._relaxed_query_compiler is not None:
13328+
relaxed_query_compiler = (
13329+
self._relaxed_query_compiler._dt_isocalendar_internal()
13330+
)
13331+
qc = self._dt_isocalendar_internal()
13332+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13333+
13334+
def _dt_isocalendar_internal(self) -> "SnowflakeQueryCompiler":
1319713335
col_name = self.columns[0]
1319813336
year_col = self.dt_property("yearofweekiso").rename(
1319913337
columns_renamer={col_name: "year"}
@@ -13207,39 +13345,179 @@ def dt_isocalendar(self) -> "SnowflakeQueryCompiler":
1320713345
return year_col.concat(axis=1, other=[week_col, day_col])
1320813346

1320913347
def dt_weekday(self) -> "SnowflakeQueryCompiler":
13348+
"""
13349+
Wrapper around _dt_weekday_internal to be supported in faster pandas.
13350+
"""
13351+
relaxed_query_compiler = None
13352+
if self._relaxed_query_compiler is not None:
13353+
relaxed_query_compiler = self._relaxed_query_compiler._dt_weekday_internal()
13354+
qc = self._dt_weekday_internal()
13355+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13356+
13357+
def _dt_weekday_internal(self) -> "SnowflakeQueryCompiler":
1321013358
return self.dt_property("weekday")
1321113359

1321213360
def dt_dayofyear(self) -> "SnowflakeQueryCompiler":
13361+
"""
13362+
Wrapper around _dt_dayofyear_internal to be supported in faster pandas.
13363+
"""
13364+
relaxed_query_compiler = None
13365+
if self._relaxed_query_compiler is not None:
13366+
relaxed_query_compiler = (
13367+
self._relaxed_query_compiler._dt_dayofyear_internal()
13368+
)
13369+
qc = self._dt_dayofyear_internal()
13370+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13371+
13372+
def _dt_dayofyear_internal(self) -> "SnowflakeQueryCompiler":
1321313373
return self.dt_property("dayofyear")
1321413374

1321513375
def dt_quarter(self) -> "SnowflakeQueryCompiler":
13376+
"""
13377+
Wrapper around _dt_quarter_internal to be supported in faster pandas.
13378+
"""
13379+
relaxed_query_compiler = None
13380+
if self._relaxed_query_compiler is not None:
13381+
relaxed_query_compiler = self._relaxed_query_compiler._dt_quarter_internal()
13382+
qc = self._dt_quarter_internal()
13383+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13384+
13385+
def _dt_quarter_internal(self) -> "SnowflakeQueryCompiler":
1321613386
return self.dt_property("quarter")
1321713387

1321813388
def dt_is_month_start(self) -> "SnowflakeQueryCompiler":
13389+
"""
13390+
Wrapper around _dt_is_month_start_internal to be supported in faster pandas.
13391+
"""
13392+
relaxed_query_compiler = None
13393+
if self._relaxed_query_compiler is not None:
13394+
relaxed_query_compiler = (
13395+
self._relaxed_query_compiler._dt_is_month_start_internal()
13396+
)
13397+
qc = self._dt_is_month_start_internal()
13398+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13399+
13400+
def _dt_is_month_start_internal(self) -> "SnowflakeQueryCompiler":
1321913401
return self.dt_property("is_month_start")
1322013402

1322113403
def dt_is_month_end(self) -> "SnowflakeQueryCompiler":
13404+
"""
13405+
Wrapper around _dt_is_month_end_internal to be supported in faster pandas.
13406+
"""
13407+
relaxed_query_compiler = None
13408+
if self._relaxed_query_compiler is not None:
13409+
relaxed_query_compiler = (
13410+
self._relaxed_query_compiler._dt_is_month_end_internal()
13411+
)
13412+
qc = self._dt_is_month_end_internal()
13413+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13414+
13415+
def _dt_is_month_end_internal(self) -> "SnowflakeQueryCompiler":
1322213416
return self.dt_property("is_month_end")
1322313417

1322413418
def dt_is_quarter_start(self) -> "SnowflakeQueryCompiler":
13419+
"""
13420+
Wrapper around _dt_is_quarter_start_internal to be supported in faster pandas.
13421+
"""
13422+
relaxed_query_compiler = None
13423+
if self._relaxed_query_compiler is not None:
13424+
relaxed_query_compiler = (
13425+
self._relaxed_query_compiler._dt_is_quarter_start_internal()
13426+
)
13427+
qc = self._dt_is_quarter_start_internal()
13428+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13429+
13430+
def _dt_is_quarter_start_internal(self) -> "SnowflakeQueryCompiler":
1322513431
return self.dt_property("is_quarter_start")
1322613432

1322713433
def dt_is_quarter_end(self) -> "SnowflakeQueryCompiler":
13434+
"""
13435+
Wrapper around _dt_is_quarter_end_internal to be supported in faster pandas.
13436+
"""
13437+
relaxed_query_compiler = None
13438+
if self._relaxed_query_compiler is not None:
13439+
relaxed_query_compiler = (
13440+
self._relaxed_query_compiler._dt_is_quarter_end_internal()
13441+
)
13442+
qc = self._dt_is_quarter_end_internal()
13443+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13444+
13445+
def _dt_is_quarter_end_internal(self) -> "SnowflakeQueryCompiler":
1322813446
return self.dt_property("is_quarter_end")
1322913447

1323013448
def dt_is_year_start(self) -> "SnowflakeQueryCompiler":
13449+
"""
13450+
Wrapper around _dt_is_year_start_internal to be supported in faster pandas.
13451+
"""
13452+
relaxed_query_compiler = None
13453+
if self._relaxed_query_compiler is not None:
13454+
relaxed_query_compiler = (
13455+
self._relaxed_query_compiler._dt_is_year_start_internal()
13456+
)
13457+
qc = self._dt_is_year_start_internal()
13458+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13459+
13460+
def _dt_is_year_start_internal(self) -> "SnowflakeQueryCompiler":
1323113461
return self.dt_property("is_year_start")
1323213462

1323313463
def dt_is_year_end(self) -> "SnowflakeQueryCompiler":
13464+
"""
13465+
Wrapper around _dt_is_year_end_internal to be supported in faster pandas.
13466+
"""
13467+
relaxed_query_compiler = None
13468+
if self._relaxed_query_compiler is not None:
13469+
relaxed_query_compiler = (
13470+
self._relaxed_query_compiler._dt_is_year_end_internal()
13471+
)
13472+
qc = self._dt_is_year_end_internal()
13473+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13474+
13475+
def _dt_is_year_end_internal(self) -> "SnowflakeQueryCompiler":
1323413476
return self.dt_property("is_year_end")
1323513477

1323613478
def dt_is_leap_year(self) -> "SnowflakeQueryCompiler":
13479+
"""
13480+
Wrapper around _dt_is_leap_year_internal to be supported in faster pandas.
13481+
"""
13482+
relaxed_query_compiler = None
13483+
if self._relaxed_query_compiler is not None:
13484+
relaxed_query_compiler = (
13485+
self._relaxed_query_compiler._dt_is_leap_year_internal()
13486+
)
13487+
qc = self._dt_is_leap_year_internal()
13488+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13489+
13490+
def _dt_is_leap_year_internal(self) -> "SnowflakeQueryCompiler":
1323713491
return self.dt_property("is_leap_year")
1323813492

1323913493
def dt_daysinmonth(self) -> "SnowflakeQueryCompiler":
13494+
"""
13495+
Wrapper around _dt_daysinmonth_internal to be supported in faster pandas.
13496+
"""
13497+
relaxed_query_compiler = None
13498+
if self._relaxed_query_compiler is not None:
13499+
relaxed_query_compiler = (
13500+
self._relaxed_query_compiler._dt_daysinmonth_internal()
13501+
)
13502+
qc = self._dt_daysinmonth_internal()
13503+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13504+
13505+
def _dt_daysinmonth_internal(self) -> "SnowflakeQueryCompiler":
1324013506
return self.dt_property("days_in_month")
1324113507

1324213508
def dt_days_in_month(self) -> "SnowflakeQueryCompiler":
13509+
"""
13510+
Wrapper around _dt_days_in_month_internal to be supported in faster pandas.
13511+
"""
13512+
relaxed_query_compiler = None
13513+
if self._relaxed_query_compiler is not None:
13514+
relaxed_query_compiler = (
13515+
self._relaxed_query_compiler._dt_days_in_month_internal()
13516+
)
13517+
qc = self._dt_days_in_month_internal()
13518+
return self._maybe_set_relaxed_qc(qc, relaxed_query_compiler)
13519+
13520+
def _dt_days_in_month_internal(self) -> "SnowflakeQueryCompiler":
1324313521
return self.dt_property("days_in_month")
1324413522

1324513523
def dt_freq(self) -> "SnowflakeQueryCompiler":

0 commit comments

Comments
 (0)