Skip to content

Commit d6bd359

Browse files
committed
Fix lint issues
1 parent 39a4cad commit d6bd359

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/datacustomcode/io/reader/query_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Union,
2222
)
2323

24+
import pandas.api.types as pd_types
2425
from pyspark.sql.types import (
2526
BooleanType,
2627
DoubleType,
@@ -34,7 +35,6 @@
3435

3536
from datacustomcode.credentials import Credentials
3637
from datacustomcode.io.reader.base import BaseDataCloudReader
37-
import pandas.api.types as pd_types
3838

3939
if TYPE_CHECKING:
4040
import pandas
@@ -58,6 +58,7 @@ def _pandas_to_spark_schema(
5858
) -> StructType:
5959
fields = []
6060
for column, dtype in pandas_df.dtypes.items():
61+
spark_type: AtomicType
6162
if pd_types.is_datetime64_any_dtype(dtype):
6263
spark_type = TimestampType()
6364
else:

tests/io/reader/test_query_api.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,23 @@ def test_pandas_to_spark_schema_nullable(self):
6262

6363
def test_pandas_to_spark_schema_datetime_types(self):
6464
"""Test conversion of pandas datetime types to Spark TimestampType."""
65-
import numpy as np
6665

6766
# Create test data with different datetime types
6867
data = {
69-
"datetime_ns": pd.to_datetime(["2023-01-01 10:00:00", "2023-01-02 11:00:00"]),
70-
"datetime_ns_utc": pd.to_datetime(["2023-01-01 10:00:00", "2023-01-02 11:00:00"], utc=True),
71-
"datetime_ms": pd.to_datetime(["2023-01-01 10:00:00", "2023-01-02 11:00:00"]).astype("datetime64[ms]"),
72-
"datetime_ms_utc": pd.to_datetime(["2023-01-01 10:00:00", "2023-01-02 11:00:00"], utc=True).tz_localize(None).astype("datetime64[ms]"),
68+
"datetime_ns": pd.to_datetime(
69+
["2023-01-01 10:00:00", "2023-01-02 11:00:00"]
70+
),
71+
"datetime_ns_utc": pd.to_datetime(
72+
["2023-01-01 10:00:00", "2023-01-02 11:00:00"], utc=True
73+
),
74+
"datetime_ms": pd.to_datetime(
75+
["2023-01-01 10:00:00", "2023-01-02 11:00:00"]
76+
).astype("datetime64[ms]"),
77+
"datetime_ms_utc": pd.to_datetime(
78+
["2023-01-01 10:00:00", "2023-01-02 11:00:00"], utc=True
79+
)
80+
.tz_localize(None)
81+
.astype("datetime64[ms]"),
7382
}
7483
df = pd.DataFrame(data)
7584

@@ -82,9 +91,16 @@ def test_pandas_to_spark_schema_datetime_types(self):
8291

8392
# Check that all datetime columns map to TimestampType
8493
field_dict = {field.name: field for field in schema.fields}
85-
for field_name in ["datetime_ns", "datetime_ns_utc", "datetime_ms", "datetime_ms_utc"]:
86-
assert isinstance(field_dict[field_name].dataType, TimestampType), \
87-
f"Field {field_name} should be TimestampType, got {type(field_dict[field_name].dataType)}"
94+
for field_name in [
95+
"datetime_ns",
96+
"datetime_ns_utc",
97+
"datetime_ms",
98+
"datetime_ms_utc",
99+
]:
100+
assert isinstance(field_dict[field_name].dataType, TimestampType), (
101+
f"Field {field_name} should be TimestampType, "
102+
f"got {type(field_dict[field_name].dataType)}"
103+
)
88104
assert field_dict[field_name].nullable
89105

90106
# Verify the actual pandas dtypes to ensure our test data has the expected types

0 commit comments

Comments
 (0)