Skip to content

Commit c63328d

Browse files
SarthakSarthak
Sarthak
authored and
Sarthak
committed
fix for both black versions
1 parent 6fe1bb8 commit c63328d

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

pandas/io/sas/sas_xport.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"nifl",
5353
"nifd",
5454
"npos",
55-
"_"
55+
"_",
5656
]
5757

5858

@@ -243,7 +243,9 @@ def _parse_float_vec(vec):
243243
class XportReader(ReaderBase, abc.Iterator):
244244
__doc__ = _xport_reader_doc
245245

246-
def __init__(self, filepath_or_buffer, index=None, encoding="ISO-8859-1", chunksize=None):
246+
def __init__(
247+
self, filepath_or_buffer, index=None, encoding="ISO-8859-1", chunksize=None
248+
):
247249

248250
self._encoding = encoding
249251
self._lines_read = 0
@@ -255,7 +257,7 @@ def __init__(self, filepath_or_buffer, index=None, encoding="ISO-8859-1", chunks
255257
filepath_or_buffer,
256258
encoding,
257259
compression,
258-
should_close
260+
should_close,
259261
) = get_filepath_or_buffer(filepath_or_buffer, encoding=encoding)
260262

261263
if isinstance(filepath_or_buffer, (str, bytes)):
@@ -313,7 +315,7 @@ def _read_header(self):
313315
["version", 8],
314316
["OS", 8],
315317
["_", 24],
316-
["created", 16]
318+
["created", 16],
317319
]
318320
member_info = _split_line(self._get_row(), mem)
319321
mem = [["modified", 16], ["_", 16], ["label", 40], ["type", 8]]
@@ -336,7 +338,7 @@ def _read_header(self):
336338
# pull data for one field
337339
field, fielddata = (
338340
fielddata[:fieldnamelength],
339-
fielddata[fieldnamelength:]
341+
fielddata[fieldnamelength:],
340342
)
341343

342344
# rest at end gets ignored, so if field is short, pad out

pandas/io/stata.py

+38-38
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Optional,
2727
Sequence,
2828
Tuple,
29-
Union
29+
Union,
3030
)
3131
import warnings
3232

@@ -41,7 +41,7 @@
4141
from pandas.core.dtypes.common import (
4242
ensure_object,
4343
is_categorical_dtype,
44-
is_datetime64_dtype
44+
is_datetime64_dtype,
4545
)
4646

4747
from pandas import (
@@ -52,7 +52,7 @@
5252
concat,
5353
isna,
5454
to_datetime,
55-
to_timedelta
55+
to_timedelta,
5656
)
5757
from pandas.core.frame import DataFrame
5858
from pandas.core.indexes.base import Index
@@ -63,7 +63,7 @@
6363
get_filepath_or_buffer,
6464
get_handle,
6565
infer_compression,
66-
stringify_path
66+
stringify_path,
6767
)
6868

6969
_version_error = (
@@ -556,7 +556,7 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame:
556556
(np.bool_, np.int8, np.int8),
557557
(np.uint8, np.int8, np.int16),
558558
(np.uint16, np.int16, np.int32),
559-
(np.uint32, np.int32, np.int64)
559+
(np.uint32, np.int32, np.int64),
560560
)
561561

562562
float32_max = struct.unpack("<f", b"\xff\xff\xff\x7e")[0]
@@ -647,7 +647,7 @@ def __init__(self, catarray: Series, encoding: str = "latin-1"):
647647
category = str(category)
648648
warnings.warn(
649649
value_label_mismatch_doc.format(catarray.name),
650-
ValueLabelTypeMismatch
650+
ValueLabelTypeMismatch,
651651
)
652652
category = category.encode(encoding)
653653
self.off.append(self.text_len)
@@ -794,7 +794,7 @@ class StataMissingValue:
794794
"int16": 32741,
795795
"int32": 2147483621,
796796
"float32": struct.unpack("<f", float32_base)[0],
797-
"float64": struct.unpack("<d", float64_base)[0]
797+
"float64": struct.unpack("<d", float64_base)[0],
798798
}
799799

800800
def __init__(self, value: Union[int, float]):
@@ -882,7 +882,7 @@ def __init__(self):
882882
(252, np.int16),
883883
(253, np.int32),
884884
(254, np.float32),
885-
(255, np.float64)
885+
(255, np.float64),
886886
]
887887
)
888888
self.DTYPE_MAP_XML = dict(
@@ -892,7 +892,7 @@ def __init__(self):
892892
(65527, np.float32),
893893
(65528, np.int32),
894894
(65529, np.int16),
895-
(65530, np.int8)
895+
(65530, np.int8),
896896
]
897897
)
898898
self.TYPE_MAP = list(range(251)) + list("bhlfd")
@@ -904,7 +904,7 @@ def __init__(self):
904904
(65527, "f"),
905905
(65528, "l"),
906906
(65529, "h"),
907-
(65530, "b")
907+
(65530, "b"),
908908
]
909909
)
910910
# NOTE: technically, some of these are wrong. there are more numbers
@@ -920,12 +920,12 @@ def __init__(self):
920920
"l": (-2147483647, 2147483620),
921921
"f": (
922922
np.float32(struct.unpack("<f", float32_min)[0]),
923-
np.float32(struct.unpack("<f", float32_max)[0])
923+
np.float32(struct.unpack("<f", float32_max)[0]),
924924
),
925925
"d": (
926926
np.float64(struct.unpack("<d", float64_min)[0]),
927-
np.float64(struct.unpack("<d", float64_max)[0])
928-
)
927+
np.float64(struct.unpack("<d", float64_max)[0]),
928+
),
929929
}
930930

931931
self.OLD_TYPE_MAPPING = {
@@ -945,15 +945,15 @@ def __init__(self):
945945
"f": np.float32(struct.unpack("<f", b"\x00\x00\x00\x7f")[0]),
946946
"d": np.float64(
947947
struct.unpack("<d", b"\x00\x00\x00\x00\x00\x00\xe0\x7f")[0]
948-
)
948+
),
949949
}
950950
self.NUMPY_TYPE_MAP = {
951951
"b": "i1",
952952
"h": "i2",
953953
"l": "i4",
954954
"f": "f4",
955955
"d": "f8",
956-
"Q": "u8"
956+
"Q": "u8",
957957
}
958958

959959
# Reserved words cannot be used as variable names
@@ -1017,7 +1017,7 @@ def __init__(self):
10171017
"_cons",
10181018
"_se",
10191019
"with",
1020-
"_n"
1020+
"_n",
10211021
)
10221022

10231023

@@ -1035,7 +1035,7 @@ def __init__(
10351035
columns: Optional[Sequence[str]] = None,
10361036
order_categoricals: bool = True,
10371037
chunksize: Optional[int] = None,
1038-
storage_options: StorageOptions = None
1038+
storage_options: StorageOptions = None,
10391039
):
10401040
super().__init__()
10411041
self.col_sizes: List[int] = []
@@ -1184,7 +1184,7 @@ def _read_new_header(self) -> None:
11841184
self.path_or_buf.seek(self._seek_sortlist)
11851185
self.srtlist = struct.unpack(
11861186
self.byteorder + ("h" * (self.nvar + 1)),
1187-
self.path_or_buf.read(2 * (self.nvar + 1))
1187+
self.path_or_buf.read(2 * (self.nvar + 1)),
11881188
)[:-1]
11891189

11901190
self.path_or_buf.seek(self._seek_formats)
@@ -1366,7 +1366,7 @@ def _read_old_header(self, first_char: bytes) -> None:
13661366
]
13671367
self.srtlist = struct.unpack(
13681368
self.byteorder + ("h" * (self.nvar + 1)),
1369-
self.path_or_buf.read(2 * (self.nvar + 1))
1369+
self.path_or_buf.read(2 * (self.nvar + 1)),
13701370
)[:-1]
13711371

13721372
self.fmtlist = self._get_fmtlist()
@@ -1556,7 +1556,7 @@ def read(
15561556
convert_missing: Optional[bool] = None,
15571557
preserve_dtypes: Optional[bool] = None,
15581558
columns: Optional[Sequence[str]] = None,
1559-
order_categoricals: Optional[bool] = None
1559+
order_categoricals: Optional[bool] = None,
15601560
) -> DataFrame:
15611561
# Handle empty file or chunk. If reading incrementally raise
15621562
# StopIteration. If reading the whole thing return an empty
@@ -1796,7 +1796,7 @@ def _do_convert_categoricals(
17961796
data: DataFrame,
17971797
value_label_dict: Dict[str, Dict[Union[float, int], str]],
17981798
lbllist: Sequence[str],
1799-
order_categoricals: bool
1799+
order_categoricals: bool,
18001800
) -> DataFrame:
18011801
"""
18021802
Converts categorical columns to Categorical type.
@@ -1910,7 +1910,7 @@ def read_stata(
19101910
order_categoricals: bool = True,
19111911
chunksize: Optional[int] = None,
19121912
iterator: bool = False,
1913-
storage_options: StorageOptions = None
1913+
storage_options: StorageOptions = None,
19141914
) -> Union[DataFrame, StataReader]:
19151915

19161916
reader = StataReader(
@@ -1923,7 +1923,7 @@ def read_stata(
19231923
columns=columns,
19241924
order_categoricals=order_categoricals,
19251925
chunksize=chunksize,
1926-
storage_options=storage_options
1926+
storage_options=storage_options,
19271927
)
19281928

19291929
if iterator or chunksize:
@@ -1939,7 +1939,7 @@ def read_stata(
19391939
def _open_file_binary_write(
19401940
fname: FilePathOrBuffer,
19411941
compression: CompressionOptions,
1942-
storage_options: StorageOptions = None
1942+
storage_options: StorageOptions = None,
19431943
) -> Tuple[BinaryIO, bool, CompressionOptions]:
19441944
"""
19451945
Open a binary file or no-op if file-like.
@@ -2024,7 +2024,7 @@ def _convert_datetime_to_stata_type(fmt: str) -> np.dtype:
20242024
"th",
20252025
"%th",
20262026
"ty",
2027-
"%ty"
2027+
"%ty",
20282028
]:
20292029
return np.float64 # Stata expects doubles for SIFs
20302030
else:
@@ -2231,7 +2231,7 @@ def __init__(
22312231
data_label: Optional[str] = None,
22322232
variable_labels: Optional[Dict[Label, str]] = None,
22332233
compression: Union[str, Mapping[str, str], None] = "infer",
2234-
storage_options: StorageOptions = None
2234+
storage_options: StorageOptions = None,
22352235
):
22362236
super().__init__()
22372237
self._convert_dates = {} if convert_dates is None else convert_dates
@@ -2563,7 +2563,7 @@ def write_file(self) -> None:
25632563
warnings.warn(
25642564
f"This save was not successful but {self._fname} could not "
25652565
"be deleted. This file is not valid.",
2566-
ResourceWarning
2566+
ResourceWarning,
25672567
)
25682568
raise exc
25692569
else:
@@ -2620,7 +2620,7 @@ def _write_value_labels(self) -> None:
26202620
def _write_header(
26212621
self,
26222622
data_label: Optional[str] = None,
2623-
time_stamp: Optional[datetime.datetime] = None
2623+
time_stamp: Optional[datetime.datetime] = None,
26242624
) -> None:
26252625
byteorder = self._byteorder
26262626
# ds_format - just use 114
@@ -2662,7 +2662,7 @@ def _write_header(
26622662
"Sep",
26632663
"Oct",
26642664
"Nov",
2665-
"Dec"
2665+
"Dec",
26662666
]
26672667
month_lookup = {i + 1: month for i, month in enumerate(months)}
26682668
ts = (
@@ -2863,7 +2863,7 @@ def __init__(
28632863
df: DataFrame,
28642864
columns: Sequence[str],
28652865
version: int = 117,
2866-
byteorder: Optional[str] = None
2866+
byteorder: Optional[str] = None,
28672867
):
28682868
if version not in (117, 118, 119):
28692869
raise ValueError("Only dta versions 117, 118 and 119 supported")
@@ -3114,7 +3114,7 @@ def __init__(
31143114
variable_labels: Optional[Dict[Label, str]] = None,
31153115
convert_strl: Optional[Sequence[Label]] = None,
31163116
compression: Union[str, Mapping[str, str], None] = "infer",
3117-
storage_options: StorageOptions = None
3117+
storage_options: StorageOptions = None,
31183118
):
31193119
# Copy to new list since convert_strl might be modified later
31203120
self._convert_strl: List[Label] = []
@@ -3131,7 +3131,7 @@ def __init__(
31313131
data_label=data_label,
31323132
variable_labels=variable_labels,
31333133
compression=compression,
3134-
storage_options=storage_options
3134+
storage_options=storage_options,
31353135
)
31363136
self._map: Dict[str, int] = {}
31373137
self._strl_blob = b""
@@ -3151,7 +3151,7 @@ def _update_map(self, tag: str) -> None:
31513151
def _write_header(
31523152
self,
31533153
data_label: Optional[str] = None,
3154-
time_stamp: Optional[datetime.datetime] = None
3154+
time_stamp: Optional[datetime.datetime] = None,
31553155
) -> None:
31563156
"""Write the file header"""
31573157
byteorder = self._byteorder
@@ -3193,7 +3193,7 @@ def _write_header(
31933193
"Sep",
31943194
"Oct",
31953195
"Nov",
3196-
"Dec"
3196+
"Dec",
31973197
]
31983198
month_lookup = {i + 1: month for i, month in enumerate(months)}
31993199
ts = (
@@ -3230,7 +3230,7 @@ def _write_map(self) -> None:
32303230
("strls", 0),
32313231
("value_labels", 0),
32323232
("stata_data_close", 0),
3233-
("end-of-file", 0)
3233+
("end-of-file", 0),
32343234
)
32353235
)
32363236
# Move to start of map
@@ -3396,7 +3396,7 @@ def _set_formats_and_types(self, dtypes: Series) -> None:
33963396
dtype,
33973397
self.data[col],
33983398
dta_version=self._dta_version,
3399-
force_strl=force_strl
3399+
force_strl=force_strl,
34003400
)
34013401
self.fmtlist.append(fmt)
34023402
self.typlist.append(
@@ -3519,7 +3519,7 @@ def __init__(
35193519
convert_strl: Optional[Sequence[Label]] = None,
35203520
version: Optional[int] = None,
35213521
compression: Union[str, Mapping[str, str], None] = "infer",
3522-
storage_options: StorageOptions = None
3522+
storage_options: StorageOptions = None,
35233523
):
35243524
if version is None:
35253525
version = 118 if data.shape[1] <= 32767 else 119
@@ -3542,7 +3542,7 @@ def __init__(
35423542
variable_labels=variable_labels,
35433543
convert_strl=convert_strl,
35443544
compression=compression,
3545-
storage_options=storage_options
3545+
storage_options=storage_options,
35463546
)
35473547
# Override version set in StataWriter117 init
35483548
self._dta_version = version

0 commit comments

Comments
 (0)