Skip to content

Commit 846b2b5

Browse files
committed
Refinements
1 parent 0851ea8 commit 846b2b5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pandas/io/pytables.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,11 @@ def read(
32973297
index = self.read_index("index", start=start, stop=stop)
32983298
values = self.read_array("values", start=start, stop=stop)
32993299
result = Series(values, index=index, name=self.name, copy=False)
3300-
if using_string_dtype() and is_string_array(values, skipna=True):
3300+
if (
3301+
using_string_dtype()
3302+
and isinstance(values, np.ndarray)
3303+
and is_string_array(values, skipna=True)
3304+
):
33013305
result = result.astype(StringDtype(na_value=np.nan))
33023306
return result
33033307

pandas/tests/io/pytables/test_put.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,24 @@ def test_put_compression_blosc(setup_path):
200200
tm.assert_frame_equal(result, expected)
201201

202202

203+
def test_put_datetime_ser(setup_path, performance_warning, using_infer_string):
204+
# https://github.com/pandas-dev/pandas/pull/60625
205+
ser = Series(3 * [Timestamp("20010102").as_unit("ns")])
206+
with ensure_clean_store(setup_path) as store:
207+
store.put("ser", ser)
208+
expected = ser.copy()
209+
result = store.get("ser")
210+
tm.assert_frame_equal(result, expected)
211+
212+
203213
def test_put_mixed_type(setup_path, performance_warning, using_infer_string):
204214
df = DataFrame(
205215
np.random.default_rng(2).standard_normal((10, 4)),
206216
columns=Index(list("ABCD")),
207217
index=date_range("2000-01-01", periods=10, freq="B"),
208218
)
209219
df["obj1"] = "foo"
210-
df["obj2"] = [pd.NA] + 9 * ["bar"]
211-
df["obj2"] = df["obj2"].astype("string")
220+
df["obj2"] = pd.array([pd.NA] + 9 * ["bar"], dtype="string")
212221
df["bool1"] = df["A"] > 0
213222
df["bool2"] = df["B"] > 0
214223
df["bool3"] = True
@@ -274,6 +283,7 @@ def test_column_multiindex(setup_path, using_infer_string):
274283

275284
with ensure_clean_store(setup_path) as store:
276285
if using_infer_string:
286+
# TODO(infer_string) make this work for string dtype
277287
msg = "Saving a MultiIndex with an extension dtype is not supported."
278288
with pytest.raises(NotImplementedError, match=msg):
279289
store.put("df", df)

0 commit comments

Comments
 (0)