Skip to content

Commit e66e307

Browse files
committed
Fixed hooks
1 parent 3b977ab commit e66e307

File tree

9 files changed

+38
-35
lines changed

9 files changed

+38
-35
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ doc/source/savefig/
140140

141141
# Ignore virtual environments
142142
pandas-env/
143-
*.pyc
143+
*.pyc

pandas/core/arrays/string_arrow.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from typing import (
66
TYPE_CHECKING,
77
Union,
8-
KeysView,
98
)
9+
from collections.abc import KeysView
1010
import warnings
1111

1212
import numpy as np
@@ -193,13 +193,12 @@ def _from_sequence(
193193
# handle explicit dtype "string" or "str"
194194
if dtype:
195195
if isinstance(dtype, str) and dtype == "str":
196-
# Use StringDtype with Python storage explicitly
196+
# Use StringDtype with Python storage explicitly
197197
dtype = StringDtype(storage="python")
198198
else:
199199
dtype = pandas_dtype(dtype)
200200
assert isinstance(dtype, StringDtype) and dtype.storage == "pyarrow"
201201

202-
203202
if isinstance(scalars, BaseMaskedArray):
204203
# avoid costly conversion to object dtype in ensure_string_array and
205204
# numerical issues with Float32Dtype
@@ -210,9 +209,8 @@ def _from_sequence(
210209
elif isinstance(scalars, (pa.Array, pa.ChunkedArray)):
211210
return cls(pc.cast(scalars, pa.large_string()))
212211

213-
214-
elif isinstance(scalars, KeysView):
215-
#Convert dict_keys to a NumPy array
212+
elif isinstance(scalars, KeysView):
213+
# Convert dict_keys to a NumPy array
216214
scalars = list(scalars)
217215

218216
# convert non-na-likes to str

pandas/core/construction.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
TYPE_CHECKING,
1212
cast,
1313
overload,
14-
KeysView,
1514
)
15+
from collections.abc import KeysView
1616

1717
import numpy as np
1818
from numpy import ma
@@ -664,13 +664,14 @@ def sanitize_array(
664664
# at this point we should have dtype be None or subarr.dtype == dtype
665665
dtype = cast(np.dtype, dtype)
666666
subarr = _sanitize_str_dtypes(subarr, data, dtype, copy)
667-
667+
668668
from pandas.core.arrays.string_ import StringDtype
669-
if dtype == "str":
669+
670+
if dtype == "str":
670671
# Use StringDtype explicitly when dtype="str"
671672
dtype = StringDtype(storage="python")
672-
673-
if isinstance(data, KeysView):
673+
674+
if isinstance(data, KeysView):
674675
# Convert dict_keys to a list for processing
675676
data = list(data)
676677

pandas/core/dtypes/common.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ def is_object_dtype(arr_or_dtype) -> bool:
180180
False
181181
"""
182182
from pandas.core.arrays.string_ import StringDtype
183-
return isinstance(arr_or_dtype, np.dtype) and arr_or_dtype == "object" or isinstance(arr_or_dtype, StringDtype)
184183

184+
return (
185+
isinstance(arr_or_dtype, np.dtype)
186+
and arr_or_dtype == "object"
187+
or isinstance(arr_or_dtype, StringDtype)
188+
)
185189

186190

187191
def is_sparse(arr) -> bool:

pandas/core/indexers/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
)
1111

1212
import numpy as np
13-
import pandas as pd
14-
1513

1614
from pandas._libs import lib
1715

@@ -28,6 +26,8 @@
2826
ABCSeries,
2927
)
3028

29+
import pandas as pd
30+
3131
if TYPE_CHECKING:
3232
from pandas._typing import AnyArrayLike
3333

@@ -536,7 +536,7 @@ def check_array_indexer(array: AnyArrayLike, indexer: Any) -> Any:
536536
indexer = indexer.to_numpy(dtype=bool, na_value=False)
537537
else:
538538
indexer = np.asarray(indexer, dtype=bool)
539-
539+
540540
# Allow empty boolean indexer for StringArray (string[python] dtype)
541541
if len(indexer) == 0 and isinstance(array, pd.arrays.StringArray):
542542
return indexer

pandas/core/indexes/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,16 +482,16 @@ def __new__(
482482
name=None,
483483
tupleize_cols: bool = True,
484484
) -> Self:
485+
from pandas.core.arrays.string_ import StringDtype
485486
from pandas.core.indexes.range import RangeIndex
486-
from pandas.core.arrays.string_ import StringDtype
487487

488488
name = maybe_extract_name(name, data, cls)
489489

490490
if dtype is not None:
491-
if dtype == "str":
491+
if dtype == "str":
492492
dtype = StringDtype(storage="python")
493493
dtype = pandas_dtype(dtype)
494-
494+
495495
data_dtype = getattr(data, "dtype", None)
496496

497497
refs = None
@@ -569,7 +569,7 @@ def __new__(
569569

570570
try:
571571
arr = sanitize_array(data, None, dtype=dtype, copy=copy)
572-
#print(f"sanitize_array received dtype: {dtype}")
572+
# print(f"sanitize_array received dtype: {dtype}")
573573
except ValueError as err:
574574
if "index must be specified when data is not list-like" in str(err):
575575
raise cls._raise_scalar_data_error(data) from err

pandas/tests/indexes/categorical/test_formats.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_string_categorical_index_repr(self):
5454
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
5555
'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
5656
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
57-
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
57+
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')"""egory')""" # noqa: E501
5858
5959
assert repr(idx) == expected
6060
@@ -63,15 +63,15 @@ def test_string_categorical_index_repr(self):
6363
expected = """CategoricalIndex(['あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ',
6464
...
6565
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
66-
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa: E501
66+
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)"""length=300)""" # noqa: E501
6767

6868
assert repr(idx) == expected
6969

7070
# larger categories
7171
idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
7272
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ', 'さ', 'し',
7373
'す', 'せ', 'そ'],
74-
categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""" # noqa: E501
74+
categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')"""ory')""" # noqa: E501
7575
7676
assert repr(idx) == expected
7777
@@ -88,7 +88,7 @@ def test_string_categorical_index_repr(self):
8888
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
8989
'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい',
9090
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう'],
91-
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')""" # noqa: E501
91+
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category')"""ory')""" # noqa: E501
9292

9393
assert repr(idx) == expected
9494

@@ -99,14 +99,14 @@ def test_string_categorical_index_repr(self):
9999
...
100100
'ううう', 'あ', 'いい', 'ううう', 'あ', 'いい', 'ううう',
101101
'あ', 'いい', 'ううう'],
102-
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)""" # noqa: E501
102+
categories=['あ', 'いい', 'ううう'], ordered=False, dtype='category', length=300)"""ength=300)""" # noqa: E501
103103
104104
assert repr(idx) == expected
105105
106106
# larger categories
107107
idx = CategoricalIndex(list("あいうえおかきくけこさしすせそ"))
108108
expected = """CategoricalIndex(['あ', 'い', 'う', 'え', 'お', 'か', 'き', 'く', 'け', 'こ',
109109
'さ', 'し', 'す', 'せ', 'そ'],
110-
categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""" # noqa: E501
110+
categories=['あ', 'い', 'う', 'え', ..., 'し', 'す', 'せ', 'そ'], ordered=False, dtype='category')""")""" # noqa: E501
111111

112112
assert repr(idx) == expected

pandas/tests/indexes/test_base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,14 @@ def test_constructor_casting(self, index):
6969
arr = np.array(index)
7070
new_index = Index(arr)
7171
tm.assert_contains_all(arr, new_index)
72-
72+
7373
if index.dtype.name == "string":
74-
# Allow conversion to object when casting back through NumPy array
74+
# Allow conversion to object when casting back through NumPy array
7575
assert new_index.dtype.name == "object"
7676
tm.assert_index_equal(index.astype("object"), new_index)
7777
else:
7878
tm.assert_index_equal(index, new_index)
7979

80-
8180
def test_constructor_copy(self, using_infer_string):
8281
index = Index(list("abc"), name="name")
8382
arr = np.array(index)
@@ -486,7 +485,6 @@ def test_empty_fancy(self, index, dtype, request, using_infer_string):
486485

487486
assert index[[]].identical(empty_index)
488487
if dtype == np.bool_:
489-
490488
if index.dtype.name == "string":
491489
# `string[python]` allows empty boolean indexing
492490
assert index[empty_arr].identical(empty_index)
@@ -692,17 +690,18 @@ def test_is_numeric(self, index, expected):
692690
def test_is_object(self, index, expected, using_infer_string):
693691
if using_infer_string and index.dtype == "string" and expected:
694692
expected = False
695-
#Bug fix
693+
# Bug fix
696694
if index.dtype.name == "string":
697695
assert not is_object_dtype(index) # string[python] is not an object dtype
698696
elif index.dtype.name == "object":
699697
# Ensure object dtype behaves as expected
700-
assert index.dtype.name == "object", "Index with dtype='object' should be recognized as such"
698+
assert (
699+
index.dtype.name == "object"
700+
), "Index with dtype='object' should be recognized as such"
701701
else:
702702
# For other dtypes, use the expected value
703703
assert is_object_dtype(index) is expected
704704

705-
706705
def test_summary(self, index):
707706
index._summary()
708707

@@ -1743,7 +1742,8 @@ def test_is_monotonic_pyarrow_list_type():
17431742
assert not idx.is_monotonic_increasing
17441743
assert not idx.is_monotonic_decreasing
17451744

1746-
def test_index_from_dict_keys_with_dtype():
1745+
1746+
def test_index_from_dict_keys_with_dtype():
17471747
d = {"a": 1, "b": 2}
17481748

17491749
# Test without dtype (default inference)

pandas/tests/io/parser/usecols/test_strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_usecols_with_multi_byte_characters(all_parsers):
7979
data = """あああ,いい,ううう,ええええ
8080
0.056674973,8,True,a
8181
2.613230982,2,False,b
82-
3.568935038,7,False,a"""
82+
3.568935038,7,False,a"""e,a"""
8383
parser = all_parsers
8484

8585
exp_data = {

0 commit comments

Comments
 (0)