-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathdataframe.py
More file actions
35 lines (27 loc) · 1.02 KB
/
dataframe.py
File metadata and controls
35 lines (27 loc) · 1.02 KB
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
29
30
31
32
33
34
35
import importlib
from typing import Any
import pandas as pd
from ydata_profiling.config import Settings
from ydata_profiling.model.pandas.dataframe_pandas import pandas_preprocess
spec = importlib.util.find_spec("pyspark")
if spec is None:
from typing import TypeVar
sparkDataFrame = TypeVar("sparkDataFrame")
else:
from pyspark.sql import DataFrame as sparkDataFrame # type: ignore
from ydata_profiling.model.spark.dataframe_spark import spark_preprocess
def preprocess(config: Settings, df: Any) -> Any:
"""
Search for invalid columns datatypes as well as ensures column names follow the expected rules
Args:
config: ydataprofiling Settings class
df: a pandas or spark dataframe
Returns: a pandas or spark dataframe
"""
if isinstance(df, pd.DataFrame):
df = pandas_preprocess(config=config, df=df)
elif isinstance(df, sparkDataFrame): # type: ignore
df = spark_preprocess(config=config, df=df)
else:
return NotImplementedError()
return df