-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
28 lines (21 loc) · 1 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re
from typing import Union
import pytest
@pytest.fixture()
def fix_pyspark_show_change():
"""Spark changed the way nulls are displayed between versions 3.4 and 3.5
While nulls used to be written "null", they are now written "NULL".
This breaks many tests, especially doctests.
As a workaround, when testing against pyspark versions older than 3.5, we override the DataFrame.show() method
to replace all occurrences of "null" with "NULL".
This workaround can be removed when we stop supporting spark versions older than 3.5
"""
import pyspark
if pyspark.__version__ < "3.5.0":
from pyspark.sql import DataFrame
from spark_frame.utils import show_string
def show(this: DataFrame, n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False):
string = show_string(this, n, truncate, vertical)
pattern = re.compile(r"""(?<!._|: )null""")
print(re.sub(pattern, "NULL", string))
DataFrame.show = show