Skip to content

Commit ac22c7a

Browse files
committed
skeleton for uinvert
1 parent 323b185 commit ac22c7a

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

src/core/expr/funary/uinvert.cc

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//------------------------------------------------------------------------------
2+
// Copyright 2023 H2O.ai
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a
5+
// copy of this software and associated documentation files (the "Software"),
6+
// to deal in the Software without restriction, including without limitation
7+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
// and/or sell copies of the Software, and to permit persons to whom the
9+
// Software is furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20+
// IN THE SOFTWARE.
21+
//------------------------------------------------------------------------------
22+
#include "column/const.h"
23+
#include "documentation.h"
24+
#include "expr/fexpr_column.h"
25+
#include "expr/funary/umaker.h"
26+
#include "expr/eval_context.h"
27+
#include "expr/workframe.h"
28+
#include "python/xargs.h"
29+
namespace dt
30+
{
31+
namespace expr
32+
{
33+
34+
FExpr_UINVERT::FExpr_UINVERT(ptrExpr &&arg) : arg_(std::move(arg))
35+
{}
36+
37+
std::string FExpr_UINVERT::repr() const
38+
{
39+
std::string out = "uinvert";
40+
out += '(';
41+
out += arg_->repr();
42+
out += ')';
43+
return out;
44+
}
45+
46+
static Column make_isna_col(Column &&col)
47+
{
48+
switch (stype) {
49+
case SType::VOID: return umaker_ptr(new umaker_copy());
50+
case SType::BOOL: return umaker1<int8_t, int8_t>::make(op_invert_bool, SType::AUTO, SType::BOOL);
51+
case SType::INT8: return _uinvert<int8_t>();
52+
case SType::INT16: return _uinvert<int16_t>();
53+
case SType::INT32: return _uinvert<int32_t>();
54+
case SType::INT64: return _uinvert<int64_t>();
55+
default:
56+
throw TypeError() << "Cannot apply unary `operator ~` to a column with "
57+
"stype `" << stype << "`";
58+
}
59+
}
60+
61+
Workframe FExpr_UINVERT::evaluate_n(EvalContext &ctx) const
62+
{
63+
Workframe wf = arg_->evaluate_n(ctx);
64+
65+
for (size_t i = 0; i < wf.ncols(); ++i)
66+
{
67+
Column coli = make_isna_col(wf.retrieve_column(i));
68+
wf.replace_column(i, std::move(coli));
69+
}
70+
71+
return wf;
72+
}
73+
74+
static py::oobj pyfn_isna(const py::XArgs &args)
75+
{
76+
auto uinvert = args[0].to_oobj();
77+
return PyFExpr::make(new FExpr_ISNA(as_fexpr(uinvert)));
78+
}
79+
80+
DECLARE_PYFN(&pyfn_isna)
81+
->name("uinvert")
82+
->docs(doc_math_isna)
83+
->arg_names({"cols"})
84+
->n_positional_args(1)
85+
->n_required_args(1);
86+
87+
}
88+
} // dt::expr

0 commit comments

Comments
 (0)