@@ -64,6 +64,25 @@ class FExpr_FillNA : public FExpr_Func {
6464
6565
6666 template <bool REVERSE>
67+ static RowIndex fill_rowindex (Column& col, const Groupby& gby) {
68+ switch (col.stype ()) {
69+ case SType::BOOL:
70+ case SType::INT8: return fill_rowindex<int8_t , REVERSE>(col, gby);
71+ case SType::INT16: return fill_rowindex<int16_t , REVERSE>(col, gby);
72+ case SType::DATE32:
73+ case SType::INT32: return fill_rowindex<int32_t , REVERSE>(col, gby);
74+ case SType::TIME64:
75+ case SType::INT64: return fill_rowindex<int64_t , REVERSE>(col, gby);
76+ case SType::FLOAT32: return fill_rowindex<float , REVERSE>(col, gby);
77+ case SType::FLOAT64: return fill_rowindex<double , REVERSE>(col, gby);
78+ case SType::STR32:
79+ case SType::STR64: return fill_rowindex<CString, REVERSE>(col, gby);
80+ default : throw RuntimeError ();
81+ }
82+ }
83+
84+
85+ template <typename T, bool REVERSE>
6786 static RowIndex fill_rowindex (Column& col, const Groupby& gby) {
6887 Buffer buf = Buffer::mem (col.nrows () * sizeof (int32_t ));
6988 auto indices = static_cast <int32_t *>(buf.xptr ());
@@ -75,16 +94,18 @@ class FExpr_FillNA : public FExpr_Func {
7594 size_t i1, i2;
7695 gby.get_group (gi, &i1, &i2);
7796 size_t fill_id = REVERSE? i2 - 1 : i1;
97+ T value;
98+ bool is_valid;
7899
79100 if (REVERSE) {
80101 for (size_t i = i2; i-- > i1;) {
81- size_t is_valid = col.get_element_isvalid (i );
102+ is_valid = col.get_element (i, &value );
82103 fill_id = is_valid? i : fill_id;
83104 indices[i] = static_cast <int32_t >(fill_id);
84105 }
85106 } else {
86107 for (size_t i = i1; i < i2; ++i) {
87- size_t is_valid = col.get_element_isvalid (i );
108+ is_valid = col.get_element (i, &value );
88109 fill_id = is_valid? i : fill_id;
89110 indices[i] = static_cast <int32_t >(fill_id);
90111 }
@@ -136,18 +157,14 @@ class FExpr_FillNA : public FExpr_Func {
136157 } else {
137158 // Fill with the previous/subsequent non-missing values
138159 Groupby gby = ctx.get_groupby ();
139- if (!gby) {
140- gby = Groupby::single_group (wf.nrows ());
141- } else {
142- wf.increase_grouping_mode (Grouping::GtoALL);
143- }
160+ wf.increase_grouping_mode (Grouping::GtoALL);
144161
145162 for (size_t i = 0 ; i < wf.ncols (); ++i) {
146163 bool is_grouped = ctx.has_group_column (
147164 wf.get_frame_id (i),
148165 wf.get_column_id (i)
149166 );
150- if (is_grouped) continue ;
167+ if (is_grouped || wf. get_column (i). stype () == SType::VOID ) continue ;
151168
152169 Column coli = wf.retrieve_column (i);
153170 auto stats = coli.get_stats_if_exist ();
@@ -160,7 +177,6 @@ class FExpr_FillNA : public FExpr_Func {
160177 : fill_rowindex<false >(coli, gby);
161178 coli.apply_rowindex (ri);
162179 }
163-
164180 wf.replace_column (i, std::move (coli));
165181 }
166182 }
0 commit comments