Skip to content

Commit

Permalink
fix for both black versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarthak authored and Sarthak committed Sep 2, 2020
1 parent 6fe1bb8 commit c63328d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
12 changes: 7 additions & 5 deletions pandas/io/sas/sas_xport.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"nifl",
"nifd",
"npos",
"_"
"_",
]


Expand Down Expand Up @@ -243,7 +243,9 @@ def _parse_float_vec(vec):
class XportReader(ReaderBase, abc.Iterator):
__doc__ = _xport_reader_doc

def __init__(self, filepath_or_buffer, index=None, encoding="ISO-8859-1", chunksize=None):
def __init__(
self, filepath_or_buffer, index=None, encoding="ISO-8859-1", chunksize=None
):

self._encoding = encoding
self._lines_read = 0
Expand All @@ -255,7 +257,7 @@ def __init__(self, filepath_or_buffer, index=None, encoding="ISO-8859-1", chunks
filepath_or_buffer,
encoding,
compression,
should_close
should_close,
) = get_filepath_or_buffer(filepath_or_buffer, encoding=encoding)

if isinstance(filepath_or_buffer, (str, bytes)):
Expand Down Expand Up @@ -313,7 +315,7 @@ def _read_header(self):
["version", 8],
["OS", 8],
["_", 24],
["created", 16]
["created", 16],
]
member_info = _split_line(self._get_row(), mem)
mem = [["modified", 16], ["_", 16], ["label", 40], ["type", 8]]
Expand All @@ -336,7 +338,7 @@ def _read_header(self):
# pull data for one field
field, fielddata = (
fielddata[:fieldnamelength],
fielddata[fieldnamelength:]
fielddata[fieldnamelength:],
)

# rest at end gets ignored, so if field is short, pad out
Expand Down
76 changes: 38 additions & 38 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Optional,
Sequence,
Tuple,
Union
Union,
)
import warnings

Expand All @@ -41,7 +41,7 @@
from pandas.core.dtypes.common import (
ensure_object,
is_categorical_dtype,
is_datetime64_dtype
is_datetime64_dtype,
)

from pandas import (
Expand All @@ -52,7 +52,7 @@
concat,
isna,
to_datetime,
to_timedelta
to_timedelta,
)
from pandas.core.frame import DataFrame
from pandas.core.indexes.base import Index
Expand All @@ -63,7 +63,7 @@
get_filepath_or_buffer,
get_handle,
infer_compression,
stringify_path
stringify_path,
)

_version_error = (
Expand Down Expand Up @@ -556,7 +556,7 @@ def _cast_to_stata_types(data: DataFrame) -> DataFrame:
(np.bool_, np.int8, np.int8),
(np.uint8, np.int8, np.int16),
(np.uint16, np.int16, np.int32),
(np.uint32, np.int32, np.int64)
(np.uint32, np.int32, np.int64),
)

float32_max = struct.unpack("<f", b"\xff\xff\xff\x7e")[0]
Expand Down Expand Up @@ -647,7 +647,7 @@ def __init__(self, catarray: Series, encoding: str = "latin-1"):
category = str(category)
warnings.warn(
value_label_mismatch_doc.format(catarray.name),
ValueLabelTypeMismatch
ValueLabelTypeMismatch,
)
category = category.encode(encoding)
self.off.append(self.text_len)
Expand Down Expand Up @@ -794,7 +794,7 @@ class StataMissingValue:
"int16": 32741,
"int32": 2147483621,
"float32": struct.unpack("<f", float32_base)[0],
"float64": struct.unpack("<d", float64_base)[0]
"float64": struct.unpack("<d", float64_base)[0],
}

def __init__(self, value: Union[int, float]):
Expand Down Expand Up @@ -882,7 +882,7 @@ def __init__(self):
(252, np.int16),
(253, np.int32),
(254, np.float32),
(255, np.float64)
(255, np.float64),
]
)
self.DTYPE_MAP_XML = dict(
Expand All @@ -892,7 +892,7 @@ def __init__(self):
(65527, np.float32),
(65528, np.int32),
(65529, np.int16),
(65530, np.int8)
(65530, np.int8),
]
)
self.TYPE_MAP = list(range(251)) + list("bhlfd")
Expand All @@ -904,7 +904,7 @@ def __init__(self):
(65527, "f"),
(65528, "l"),
(65529, "h"),
(65530, "b")
(65530, "b"),
]
)
# NOTE: technically, some of these are wrong. there are more numbers
Expand All @@ -920,12 +920,12 @@ def __init__(self):
"l": (-2147483647, 2147483620),
"f": (
np.float32(struct.unpack("<f", float32_min)[0]),
np.float32(struct.unpack("<f", float32_max)[0])
np.float32(struct.unpack("<f", float32_max)[0]),
),
"d": (
np.float64(struct.unpack("<d", float64_min)[0]),
np.float64(struct.unpack("<d", float64_max)[0])
)
np.float64(struct.unpack("<d", float64_max)[0]),
),
}

self.OLD_TYPE_MAPPING = {
Expand All @@ -945,15 +945,15 @@ def __init__(self):
"f": np.float32(struct.unpack("<f", b"\x00\x00\x00\x7f")[0]),
"d": np.float64(
struct.unpack("<d", b"\x00\x00\x00\x00\x00\x00\xe0\x7f")[0]
)
),
}
self.NUMPY_TYPE_MAP = {
"b": "i1",
"h": "i2",
"l": "i4",
"f": "f4",
"d": "f8",
"Q": "u8"
"Q": "u8",
}

# Reserved words cannot be used as variable names
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def __init__(self):
"_cons",
"_se",
"with",
"_n"
"_n",
)


Expand All @@ -1035,7 +1035,7 @@ def __init__(
columns: Optional[Sequence[str]] = None,
order_categoricals: bool = True,
chunksize: Optional[int] = None,
storage_options: StorageOptions = None
storage_options: StorageOptions = None,
):
super().__init__()
self.col_sizes: List[int] = []
Expand Down Expand Up @@ -1184,7 +1184,7 @@ def _read_new_header(self) -> None:
self.path_or_buf.seek(self._seek_sortlist)
self.srtlist = struct.unpack(
self.byteorder + ("h" * (self.nvar + 1)),
self.path_or_buf.read(2 * (self.nvar + 1))
self.path_or_buf.read(2 * (self.nvar + 1)),
)[:-1]

self.path_or_buf.seek(self._seek_formats)
Expand Down Expand Up @@ -1366,7 +1366,7 @@ def _read_old_header(self, first_char: bytes) -> None:
]
self.srtlist = struct.unpack(
self.byteorder + ("h" * (self.nvar + 1)),
self.path_or_buf.read(2 * (self.nvar + 1))
self.path_or_buf.read(2 * (self.nvar + 1)),
)[:-1]

self.fmtlist = self._get_fmtlist()
Expand Down Expand Up @@ -1556,7 +1556,7 @@ def read(
convert_missing: Optional[bool] = None,
preserve_dtypes: Optional[bool] = None,
columns: Optional[Sequence[str]] = None,
order_categoricals: Optional[bool] = None
order_categoricals: Optional[bool] = None,
) -> DataFrame:
# Handle empty file or chunk. If reading incrementally raise
# StopIteration. If reading the whole thing return an empty
Expand Down Expand Up @@ -1796,7 +1796,7 @@ def _do_convert_categoricals(
data: DataFrame,
value_label_dict: Dict[str, Dict[Union[float, int], str]],
lbllist: Sequence[str],
order_categoricals: bool
order_categoricals: bool,
) -> DataFrame:
"""
Converts categorical columns to Categorical type.
Expand Down Expand Up @@ -1910,7 +1910,7 @@ def read_stata(
order_categoricals: bool = True,
chunksize: Optional[int] = None,
iterator: bool = False,
storage_options: StorageOptions = None
storage_options: StorageOptions = None,
) -> Union[DataFrame, StataReader]:

reader = StataReader(
Expand All @@ -1923,7 +1923,7 @@ def read_stata(
columns=columns,
order_categoricals=order_categoricals,
chunksize=chunksize,
storage_options=storage_options
storage_options=storage_options,
)

if iterator or chunksize:
Expand All @@ -1939,7 +1939,7 @@ def read_stata(
def _open_file_binary_write(
fname: FilePathOrBuffer,
compression: CompressionOptions,
storage_options: StorageOptions = None
storage_options: StorageOptions = None,
) -> Tuple[BinaryIO, bool, CompressionOptions]:
"""
Open a binary file or no-op if file-like.
Expand Down Expand Up @@ -2024,7 +2024,7 @@ def _convert_datetime_to_stata_type(fmt: str) -> np.dtype:
"th",
"%th",
"ty",
"%ty"
"%ty",
]:
return np.float64 # Stata expects doubles for SIFs
else:
Expand Down Expand Up @@ -2231,7 +2231,7 @@ def __init__(
data_label: Optional[str] = None,
variable_labels: Optional[Dict[Label, str]] = None,
compression: Union[str, Mapping[str, str], None] = "infer",
storage_options: StorageOptions = None
storage_options: StorageOptions = None,
):
super().__init__()
self._convert_dates = {} if convert_dates is None else convert_dates
Expand Down Expand Up @@ -2563,7 +2563,7 @@ def write_file(self) -> None:
warnings.warn(
f"This save was not successful but {self._fname} could not "
"be deleted. This file is not valid.",
ResourceWarning
ResourceWarning,
)
raise exc
else:
Expand Down Expand Up @@ -2620,7 +2620,7 @@ def _write_value_labels(self) -> None:
def _write_header(
self,
data_label: Optional[str] = None,
time_stamp: Optional[datetime.datetime] = None
time_stamp: Optional[datetime.datetime] = None,
) -> None:
byteorder = self._byteorder
# ds_format - just use 114
Expand Down Expand Up @@ -2662,7 +2662,7 @@ def _write_header(
"Sep",
"Oct",
"Nov",
"Dec"
"Dec",
]
month_lookup = {i + 1: month for i, month in enumerate(months)}
ts = (
Expand Down Expand Up @@ -2863,7 +2863,7 @@ def __init__(
df: DataFrame,
columns: Sequence[str],
version: int = 117,
byteorder: Optional[str] = None
byteorder: Optional[str] = None,
):
if version not in (117, 118, 119):
raise ValueError("Only dta versions 117, 118 and 119 supported")
Expand Down Expand Up @@ -3114,7 +3114,7 @@ def __init__(
variable_labels: Optional[Dict[Label, str]] = None,
convert_strl: Optional[Sequence[Label]] = None,
compression: Union[str, Mapping[str, str], None] = "infer",
storage_options: StorageOptions = None
storage_options: StorageOptions = None,
):
# Copy to new list since convert_strl might be modified later
self._convert_strl: List[Label] = []
Expand All @@ -3131,7 +3131,7 @@ def __init__(
data_label=data_label,
variable_labels=variable_labels,
compression=compression,
storage_options=storage_options
storage_options=storage_options,
)
self._map: Dict[str, int] = {}
self._strl_blob = b""
Expand All @@ -3151,7 +3151,7 @@ def _update_map(self, tag: str) -> None:
def _write_header(
self,
data_label: Optional[str] = None,
time_stamp: Optional[datetime.datetime] = None
time_stamp: Optional[datetime.datetime] = None,
) -> None:
"""Write the file header"""
byteorder = self._byteorder
Expand Down Expand Up @@ -3193,7 +3193,7 @@ def _write_header(
"Sep",
"Oct",
"Nov",
"Dec"
"Dec",
]
month_lookup = {i + 1: month for i, month in enumerate(months)}
ts = (
Expand Down Expand Up @@ -3230,7 +3230,7 @@ def _write_map(self) -> None:
("strls", 0),
("value_labels", 0),
("stata_data_close", 0),
("end-of-file", 0)
("end-of-file", 0),
)
)
# Move to start of map
Expand Down Expand Up @@ -3396,7 +3396,7 @@ def _set_formats_and_types(self, dtypes: Series) -> None:
dtype,
self.data[col],
dta_version=self._dta_version,
force_strl=force_strl
force_strl=force_strl,
)
self.fmtlist.append(fmt)
self.typlist.append(
Expand Down Expand Up @@ -3519,7 +3519,7 @@ def __init__(
convert_strl: Optional[Sequence[Label]] = None,
version: Optional[int] = None,
compression: Union[str, Mapping[str, str], None] = "infer",
storage_options: StorageOptions = None
storage_options: StorageOptions = None,
):
if version is None:
version = 118 if data.shape[1] <= 32767 else 119
Expand All @@ -3542,7 +3542,7 @@ def __init__(
variable_labels=variable_labels,
convert_strl=convert_strl,
compression=compression,
storage_options=storage_options
storage_options=storage_options,
)
# Override version set in StataWriter117 init
self._dta_version = version
Expand Down

0 comments on commit c63328d

Please sign in to comment.