Skip to content

Commit 4caafd4

Browse files
authored
CLN: Update files (as per #36450) to Python 3.7+ syntax (#36457)
1 parent 56eb167 commit 4caafd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+94
-108
lines changed

pandas/_config/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def detect_console_encoding() -> str:
2222
encoding = None
2323
try:
2424
encoding = sys.stdout.encoding or sys.stdin.encoding
25-
except (AttributeError, IOError):
25+
except (AttributeError, OSError):
2626
pass
2727

2828
# try again for something better

pandas/_testing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,8 +1960,7 @@ def index_subclass_makers_generator():
19601960
makeCategoricalIndex,
19611961
makeMultiIndex,
19621962
]
1963-
for make_index_func in make_index_funcs:
1964-
yield make_index_func
1963+
yield from make_index_funcs
19651964

19661965

19671966
def all_timeseries_index_generator(k=10):

pandas/_vendored/typing_extensions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def __repr__(self):
409409

410410
def __getitem__(self, parameters):
411411
item = typing._type_check(
412-
parameters, "{} accepts only single type".format(self._name)
412+
parameters, f"{self._name} accepts only single type"
413413
)
414414
return _GenericAlias(self, (item,))
415415

@@ -1671,7 +1671,7 @@ def __class_getitem__(cls, params):
16711671
params = (params,)
16721672
if not params and cls is not Tuple:
16731673
raise TypeError(
1674-
"Parameter list to {}[...] cannot be empty".format(cls.__qualname__)
1674+
f"Parameter list to {cls.__qualname__}[...] cannot be empty"
16751675
)
16761676
msg = "Parameters to generic types must be types."
16771677
params = tuple(_type_check(p, msg) for p in params)
@@ -2113,7 +2113,7 @@ def __class_getitem__(cls, params):
21132113
return _AnnotatedAlias(origin, metadata)
21142114

21152115
def __init_subclass__(cls, *args, **kwargs):
2116-
raise TypeError("Cannot subclass {}.Annotated".format(cls.__module__))
2116+
raise TypeError(f"Cannot subclass {cls.__module__}.Annotated")
21172117

21182118
def _strip_annotations(t):
21192119
"""Strips the annotations from a given type.
@@ -2195,7 +2195,7 @@ def _tree_repr(self, tree):
21952195
else:
21962196
tp_repr = origin[0]._tree_repr(origin)
21972197
metadata_reprs = ", ".join(repr(arg) for arg in metadata)
2198-
return "%s[%s, %s]" % (cls, tp_repr, metadata_reprs)
2198+
return f"{cls}[{tp_repr}, {metadata_reprs}]"
21992199

22002200
def _subs_tree(self, tvars=None, args=None): # noqa
22012201
if self is Annotated:
@@ -2382,7 +2382,7 @@ def TypeAlias(self, parameters):
23822382
23832383
It's invalid when used anywhere except as in the example above.
23842384
"""
2385-
raise TypeError("{} is not subscriptable".format(self))
2385+
raise TypeError(f"{self} is not subscriptable")
23862386

23872387

23882388
elif sys.version_info[:2] >= (3, 7):

pandas/_version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
7474
stderr=(subprocess.PIPE if hide_stderr else None),
7575
)
7676
break
77-
except EnvironmentError:
77+
except OSError:
7878
e = sys.exc_info()[1]
7979
if e.errno == errno.ENOENT:
8080
continue
@@ -121,7 +121,7 @@ def git_get_keywords(versionfile_abs):
121121
# _version.py.
122122
keywords = {}
123123
try:
124-
f = open(versionfile_abs, "r")
124+
f = open(versionfile_abs)
125125
for line in f.readlines():
126126
if line.strip().startswith("git_refnames ="):
127127
mo = re.search(r'=\s*"(.*)"', line)
@@ -132,7 +132,7 @@ def git_get_keywords(versionfile_abs):
132132
if mo:
133133
keywords["full"] = mo.group(1)
134134
f.close()
135-
except EnvironmentError:
135+
except OSError:
136136
pass
137137
return keywords
138138

pandas/io/clipboard/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def copy_dev_clipboard(text):
274274
fo.write(text)
275275

276276
def paste_dev_clipboard() -> str:
277-
with open("/dev/clipboard", "rt") as fo:
277+
with open("/dev/clipboard") as fo:
278278
content = fo.read()
279279
return content
280280

@@ -521,7 +521,7 @@ def determine_clipboard():
521521
return init_windows_clipboard()
522522

523523
if platform.system() == "Linux":
524-
with open("/proc/version", "r") as f:
524+
with open("/proc/version") as f:
525525
if "Microsoft" in f.read():
526526
return init_wsl_clipboard()
527527

pandas/io/formats/excel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,7 @@ def _format_regular_rows(self):
587587
else:
588588
coloffset = 0
589589

590-
for cell in self._generate_body(coloffset):
591-
yield cell
590+
yield from self._generate_body(coloffset)
592591

593592
def _format_hierarchical_rows(self):
594593
has_aliases = isinstance(self.header, (tuple, list, np.ndarray, ABCIndex))
@@ -664,8 +663,7 @@ def _format_hierarchical_rows(self):
664663
)
665664
gcolidx += 1
666665

667-
for cell in self._generate_body(gcolidx):
668-
yield cell
666+
yield from self._generate_body(gcolidx)
669667

670668
def _generate_body(self, coloffset: int):
671669
if self.styler is None:

pandas/io/html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def _build_doc(self):
719719
r = r.getroot()
720720
except AttributeError:
721721
pass
722-
except (UnicodeDecodeError, IOError) as e:
722+
except (UnicodeDecodeError, OSError) as e:
723723
# if the input is a blob of html goop
724724
if not is_url(self.io):
725725
r = fromstring(self.io, parser=parser)

pandas/io/json/_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def close(self):
821821
if self.should_close:
822822
try:
823823
self.open_stream.close()
824-
except (IOError, AttributeError):
824+
except (OSError, AttributeError):
825825
pass
826826
for file_handle in self.file_handles:
827827
file_handle.close()

pandas/io/pytables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def read_hdf(
364364

365365
if isinstance(path_or_buf, HDFStore):
366366
if not path_or_buf.is_open:
367-
raise IOError("The HDFStore must be open for reading.")
367+
raise OSError("The HDFStore must be open for reading.")
368368

369369
store = path_or_buf
370370
auto_close = False
@@ -693,7 +693,7 @@ def open(self, mode: str = "a", **kwargs):
693693

694694
try:
695695
self._handle = tables.open_file(self._path, self._mode, **kwargs)
696-
except IOError as err: # pragma: no cover
696+
except OSError as err: # pragma: no cover
697697
if "can not be written" in str(err):
698698
print(f"Opening {self._path} in read-only mode")
699699
self._handle = tables.open_file(self._path, "r", **kwargs)
@@ -724,7 +724,7 @@ def open(self, mode: str = "a", **kwargs):
724724
# trying to read from a non-existent file causes an error which
725725
# is not part of IOError, make it one
726726
if self._mode == "r" and "Unable to open/create file" in str(err):
727-
raise IOError(str(err)) from err
727+
raise OSError(str(err)) from err
728728
raise
729729

730730
def close(self):

pandas/io/stata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def close(self) -> None:
10771077
""" close the handle if its open """
10781078
try:
10791079
self.path_or_buf.close()
1080-
except IOError:
1080+
except OSError:
10811081
pass
10821082

10831083
def _set_encoding(self) -> None:

0 commit comments

Comments
 (0)