Skip to content

Commit 74f31f2

Browse files
committed
CLN: assorted cleanups
1 parent 17fa54b commit 74f31f2

File tree

8 files changed

+53
-50
lines changed

8 files changed

+53
-50
lines changed

pandas/core/indexes/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,12 @@ def __new__(
331331

332332
# extension dtype
333333
elif is_extension_array_dtype(data) or is_extension_array_dtype(dtype):
334-
data = np.asarray(data)
335334
if not (dtype is None or is_object_dtype(dtype)):
336335
# coerce to the provided dtype
337336
ea_cls = dtype.construct_array_type()
338337
data = ea_cls._from_sequence(data, dtype=dtype, copy=False)
338+
else:
339+
data = np.asarray(data, dtype=object)
339340

340341
# coerce to the object dtype
341342
data = data.astype(object)

pandas/core/strings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ def cat_core(list_of_columns: List, sep: str):
7474
"""
7575
if sep == "":
7676
# no need to interleave sep if it is empty
77-
return np.sum(list_of_columns, axis=0)
77+
arr_of_cols = np.asarray(list_of_columns, dtype=object)
78+
return np.sum(arr_of_cols, axis=0)
7879
list_with_sep = [sep] * (2 * len(list_of_columns) - 1)
7980
list_with_sep[::2] = list_of_columns
80-
return np.sum(list_with_sep, axis=0)
81+
arr_with_sep = np.asarray(list_with_sep)
82+
return np.sum(arr_with_sep, axis=0)
8183

8284

8385
def cat_safe(list_of_columns: List, sep: str):

pandas/io/pytables.py

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ def create_table_index(
13141314
optlevel : int or None, default None
13151315
Optimization level, if None, pytables defaults to 6.
13161316
kind : str or None, default None
1317-
Kind of index, if None, pytables defaults to "medium"
1317+
Kind of index, if None, pytables defaults to "medium".
13181318
13191319
Raises
13201320
------
@@ -1741,24 +1741,24 @@ def _read_group(self, group: "Node"):
17411741

17421742

17431743
class TableIterator:
1744-
""" define the iteration interface on a table
1745-
1746-
Parameters
1747-
----------
1744+
"""
1745+
Define the iteration interface on a table
17481746
1749-
store : the reference store
1750-
s : the referred storer
1751-
func : the function to execute the query
1752-
where : the where of the query
1753-
nrows : the rows to iterate on
1754-
start : the passed start value (default is None)
1755-
stop : the passed stop value (default is None)
1756-
iterator : bool, default False
1757-
Whether to use the default iterator.
1758-
chunksize : the passed chunking value (default is 100000)
1759-
auto_close : boolean, automatically close the store at the end of
1760-
iteration, default is False
1761-
"""
1747+
Parameters
1748+
----------
1749+
store : HDFStore
1750+
s : the referred storer
1751+
func : the function to execute the query
1752+
where : the where of the query
1753+
nrows : the rows to iterate on
1754+
start : the passed start value (default is None)
1755+
stop : the passed stop value (default is None)
1756+
iterator : bool, default False
1757+
Whether to use the default iterator.
1758+
chunksize : the passed chunking value (default is 100000)
1759+
auto_close : bool, default False
1760+
Whether to automatically close the store at the end of iteration.
1761+
"""
17621762

17631763
chunksize: Optional[int]
17641764
store: HDFStore
@@ -2540,10 +2540,6 @@ def copy(self):
25402540
new_self = copy.copy(self)
25412541
return new_self
25422542

2543-
@property
2544-
def storage_obj_type(self):
2545-
return self.obj_type
2546-
25472543
@property
25482544
def shape(self):
25492545
return self.nrows
@@ -2568,10 +2564,6 @@ def _complevel(self) -> int:
25682564
def _fletcher32(self) -> bool:
25692565
return self.parent._fletcher32
25702566

2571-
@property
2572-
def _complib(self):
2573-
return self.parent._complib
2574-
25752567
@property
25762568
def attrs(self):
25772569
return self.group._v_attrs
@@ -3298,12 +3290,12 @@ def data_orientation(self):
32983290
def queryables(self) -> Dict[str, Any]:
32993291
""" return a dict of the kinds allowable columns for this object """
33003292

3293+
# mypy doesnt recognize DataFrame._AXIS_NAMES, so we re-write it here
3294+
axis_names = {0: "index", 1: "columns"}
3295+
33013296
# compute the values_axes queryables
33023297
d1 = [(a.cname, a) for a in self.index_axes]
3303-
d2 = [
3304-
(self.storage_obj_type._AXIS_NAMES[axis], None)
3305-
for axis, values in self.non_index_axes
3306-
]
3298+
d2 = [(axis_names[axis], None) for axis, values in self.non_index_axes]
33073299
d3 = [
33083300
(v.cname, v) for v in self.values_axes if v.name in set(self.data_columns)
33093301
]
@@ -3482,9 +3474,7 @@ def f(i, c):
34823474

34833475
def create_index(self, columns=None, optlevel=None, kind: Optional[str] = None):
34843476
"""
3485-
Create a pytables index on the specified columns
3486-
note: cannot index Time64Col() or ComplexCol currently;
3487-
PyTables must be >= 3.0
3477+
Create a pytables index on the specified columns.
34883478
34893479
Parameters
34903480
----------
@@ -3499,12 +3489,16 @@ def create_index(self, columns=None, optlevel=None, kind: Optional[str] = None):
34993489
optlevel : int or None, default None
35003490
Optimization level, if None, pytables defaults to 6.
35013491
kind : str or None, default None
3502-
Kind of index, if None, pytables defaults to "medium"
3492+
Kind of index, if None, pytables defaults to "medium".
35033493
35043494
Raises
35053495
------
3506-
raises if the node is not a table
3496+
TypeError if trying to create an index on a complex-type column.
35073497
3498+
Notes
3499+
-----
3500+
Cannot index Time64Col or ComplexCol.
3501+
Pytables must be >= 3.0.
35083502
"""
35093503

35103504
if not self.infer_axes():
@@ -4404,7 +4398,6 @@ class AppendableSeriesTable(AppendableFrameTable):
44044398
table_type = "appendable_series"
44054399
ndim = 2
44064400
obj_type = Series
4407-
storage_obj_type = DataFrame
44084401

44094402
@property
44104403
def is_transposed(self) -> bool:
@@ -4792,7 +4785,8 @@ def _convert_string_array(data: np.ndarray, encoding: str, errors: str) -> np.nd
47924785
----------
47934786
data : np.ndarray[object]
47944787
encoding : str
4795-
errors : handler for encoding errors
4788+
errors : str
4789+
Handler for encoding errors.
47964790
47974791
Returns
47984792
-------
@@ -4813,13 +4807,15 @@ def _convert_string_array(data: np.ndarray, encoding: str, errors: str) -> np.nd
48134807
return data
48144808

48154809

4816-
def _unconvert_string_array(data, nan_rep, encoding: str, errors: str) -> np.ndarray:
4810+
def _unconvert_string_array(
4811+
data: np.ndarray, nan_rep, encoding: str, errors: str
4812+
) -> np.ndarray:
48174813
"""
4818-
inverse of _convert_string_array
4814+
Inverse of _convert_string_array.
48194815
48204816
Parameters
48214817
----------
4822-
data : fixed length string dtyped array
4818+
data : np.ndarray[fixed-length-string]
48234819
nan_rep : the storage repr of NaN
48244820
encoding : str
48254821
errors : str

pandas/tests/dtypes/test_inference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def test_scientific_no_exponent(self):
449449
def test_convert_non_hashable(self):
450450
# GH13324
451451
# make sure that we are handing non-hashables
452-
arr = np.array([[10.0, 2], 1.0, "apple"])
452+
arr = np.array([[10.0, 2], 1.0, "apple"], dtype=object)
453453
result = lib.maybe_convert_numeric(arr, set(), False, True)
454454
tm.assert_numpy_array_equal(result, np.array([np.nan, 1.0, np.nan]))
455455

pandas/tests/io/json/test_ujson.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,9 @@ def test_array_list(self):
761761
["a", "b"],
762762
{"key": "val"},
763763
]
764-
arr = np.array(arr_list)
765-
tm.assert_numpy_array_equal(np.array(ujson.decode(ujson.encode(arr))), arr)
764+
arr = np.array(arr_list, dtype=object)
765+
result = np.array(ujson.decode(ujson.encode(arr)), dtype=object)
766+
tm.assert_numpy_array_equal(result, arr)
766767

767768
def test_array_float(self):
768769
dtype = np.float32

pandas/tests/io/test_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_same_ordering(datapath):
8787
@pytest.mark.parametrize(
8888
"flavor",
8989
[
90-
pytest.param("bs4", marks=td.skip_if_no("lxml")),
90+
pytest.param("bs4", marks=td.skip_if_no("bs4")),
9191
pytest.param("lxml", marks=td.skip_if_no("lxml")),
9292
],
9393
scope="class",

pandas/tests/test_multilevel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def test_append_index(self):
120120
(1.2, tz.localize(datetime.datetime(2011, 1, 2)), "B"),
121121
(1.3, tz.localize(datetime.datetime(2011, 1, 3)), "C"),
122122
]
123-
+ expected_tuples
123+
+ expected_tuples,
124+
dtype=object,
124125
),
125126
None,
126127
)

pandas/tests/test_strings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,7 +2857,8 @@ def test_partition_index(self):
28572857
result = values.str.partition("_", expand=False)
28582858
exp = Index(
28592859
np.array(
2860-
[("a", "_", "b_c"), ("c", "_", "d_e"), ("f", "_", "g_h"), np.nan, None]
2860+
[("a", "_", "b_c"), ("c", "_", "d_e"), ("f", "_", "g_h"), np.nan, None],
2861+
dtype=object,
28612862
)
28622863
)
28632864
tm.assert_index_equal(result, exp)
@@ -2866,7 +2867,8 @@ def test_partition_index(self):
28662867
result = values.str.rpartition("_", expand=False)
28672868
exp = Index(
28682869
np.array(
2869-
[("a_b", "_", "c"), ("c_d", "_", "e"), ("f_g", "_", "h"), np.nan, None]
2870+
[("a_b", "_", "c"), ("c_d", "_", "e"), ("f_g", "_", "h"), np.nan, None],
2871+
dtype=object,
28702872
)
28712873
)
28722874
tm.assert_index_equal(result, exp)

0 commit comments

Comments
 (0)