Skip to content

Commit 36a26a9

Browse files
committed
Lint
1 parent 798c1f2 commit 36a26a9

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

pandas/io/formats/csvs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Sequence,
1212
)
1313
import csv as csvlib
14+
import json
1415
import os
1516
from typing import (
1617
TYPE_CHECKING,
@@ -19,7 +20,6 @@
1920
)
2021

2122
import numpy as np
22-
import json
2323

2424
from pandas._libs import writers as libwriters
2525
from pandas._typing import SequenceNotStr
@@ -109,12 +109,11 @@ def __init__(
109109
self.obj[col] = self.obj[col].apply(
110110
lambda x: json.dumps(x.tolist())
111111
if isinstance(x, np.ndarray)
112-
else json.dumps(x) if isinstance(x, list)
112+
else json.dumps(x)
113+
if isinstance(x, list)
113114
else x
114115
)
115116

116-
117-
118117
@property
119118
def na_rep(self) -> str:
120119
return self.fmt.na_rep

pandas/io/parsers/readers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
defaultdict,
1212
)
1313
import csv
14+
import json
1415
import sys
1516
from textwrap import fill
1617
from typing import (
@@ -25,8 +26,6 @@
2526
import warnings
2627

2728
import numpy as np
28-
import pandas as pd
29-
import json
3029

3130
from pandas._libs import lib
3231
from pandas._libs.parsers import STR_NA_VALUES
@@ -49,6 +48,7 @@
4948
pandas_dtype,
5049
)
5150

51+
import pandas as pd
5252
from pandas import Series
5353
from pandas.core.frame import DataFrame
5454
from pandas.core.indexes.api import RangeIndex
@@ -866,6 +866,7 @@ def _restore_complex_arrays(df: DataFrame) -> None:
866866
Converted bracketed JSON strings in df back to NumPy arrays.
867867
eg. "[0.1, 0.2, 0.3]" --> parse into NumPy array.
868868
"""
869+
869870
def looks_like_json_array(x: str) -> bool:
870871
return x.startswith("[") and x.endswith("]")
871872

@@ -874,9 +875,13 @@ def looks_like_json_array(x: str) -> bool:
874875
nonnull = df[col].dropna()
875876
if (
876877
len(nonnull) > 0
877-
and nonnull.apply(lambda x: isinstance(x, str) and looks_like_json_array(x)).all()
878+
and nonnull.apply(
879+
lambda x: isinstance(x, str) and looks_like_json_array(x)
880+
).all()
878881
):
879-
df[col] = df[col].apply(lambda x: np.array(json.loads(x)) if pd.notnull(x) else x)
882+
df[col] = df[col].apply(
883+
lambda x: np.array(json.loads(x)) if pd.notnull(x) else x
884+
)
880885

881886

882887
@overload

scripts/tests/test_csv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pandas as pd
2+
23
print(pd.__file__)
34
print(pd.__version__)
45

56
import numpy as np
6-
import os
77

88
# # Create a DataFrame with NumPy arrays
99
# df = pd.DataFrame({
@@ -35,8 +35,8 @@
3535
# TEST2
3636
# Create a DataFrame with NumPy arrays
3737
df = pd.DataFrame({
38-
'id': [1, 2],
39-
'embedding': [np.array([0.1, 0.2, 0.3]), np.array([0.4, 0.5, 0.6])]
38+
"id": [1, 2],
39+
"embedding": [np.array([0.1, 0.2, 0.3]), np.array([0.4, 0.5, 0.6])]
4040
})
4141

4242
# Save to CSV

0 commit comments

Comments
 (0)