|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
18 | | -import pyarrow |
| 18 | +import pyarrow as pa |
19 | 19 | import pytest |
20 | 20 | from datafusion import SessionContext, col |
21 | 21 | from datafusion.expr import ( |
@@ -125,8 +125,8 @@ def test_sort(test_ctx): |
125 | 125 | def test_relational_expr(test_ctx): |
126 | 126 | ctx = SessionContext() |
127 | 127 |
|
128 | | - batch = pyarrow.RecordBatch.from_arrays( |
129 | | - [pyarrow.array([1, 2, 3]), pyarrow.array(["alpha", "beta", "gamma"])], |
| 128 | + batch = pa.RecordBatch.from_arrays( |
| 129 | + [pa.array([1, 2, 3]), pa.array(["alpha", "beta", "gamma"])], |
130 | 130 | names=["a", "b"], |
131 | 131 | ) |
132 | 132 | df = ctx.create_dataframe([[batch]], name="batch_array") |
@@ -216,3 +216,30 @@ def test_display_name_deprecation(): |
216 | 216 | # returns appropriate result |
217 | 217 | assert name == expr.schema_name() |
218 | 218 | assert name == "foo" |
| 219 | + |
| 220 | + |
| 221 | +@pytest.fixture |
| 222 | +def df(): |
| 223 | + ctx = SessionContext() |
| 224 | + |
| 225 | + # create a RecordBatch and a new DataFrame from it |
| 226 | + batch = pa.RecordBatch.from_arrays( |
| 227 | + [pa.array([1, 2, None]), pa.array([4, None, 6]), pa.array([None, None, 8])], |
| 228 | + names=["a", "b", "c"], |
| 229 | + ) |
| 230 | + |
| 231 | + return ctx.from_arrow(batch) |
| 232 | + |
| 233 | + |
| 234 | +def test_fill_null(df): |
| 235 | + df = df.select( |
| 236 | + col("a").fill_null(100).alias("a"), |
| 237 | + col("b").fill_null(25).alias("b"), |
| 238 | + col("c").fill_null(1234).alias("c"), |
| 239 | + ) |
| 240 | + df.show() |
| 241 | + result = df.collect()[0] |
| 242 | + |
| 243 | + assert result.column(0) == pa.array([1, 2, 100]) |
| 244 | + assert result.column(1) == pa.array([4, 25, 6]) |
| 245 | + assert result.column(2) == pa.array([1234, 1234, 8]) |
0 commit comments