Skip to content

Commit 6064812

Browse files
committed
Always return an Int64 data frame
1 parent f61097c commit 6064812

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

pandas/core/arrays/datetimes.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1266,14 +1266,15 @@ def isocalendar(self):
12661266
1 1
12671267
2 1
12681268
3 1
1269-
Name: week, dtype: int32
1269+
Name: week, dtype: Int64
12701270
"""
12711271
from pandas import DataFrame
12721272

12731273
sarray = fields.build_isocalendar_sarray(self.asi8)
1274-
iso_calendar_df = DataFrame(sarray, columns=["year", "week", "day"])
1274+
iso_calendar_df = DataFrame(
1275+
sarray, columns=["year", "week", "day"], dtype="Int64"
1276+
)
12751277
if self._hasnans:
1276-
iso_calendar_df = iso_calendar_df.astype("Int64")
12771278
iso_calendar_df.iloc[self._isnan] = None
12781279
return iso_calendar_df
12791280

pandas/tests/series/test_datetime_values.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -669,21 +669,17 @@ def test_setitem_with_different_tz(self):
669669
tm.assert_series_equal(ser, expected)
670670

671671
@pytest.mark.parametrize(
672-
"input_series, expected_output, expected_type",
672+
"input_series, expected_output",
673673
[
674-
[["2020-01-01"], [[2020, 1, 3]], "int32"],
675-
[[pd.NaT], [[np.NaN, np.NaN, np.NaN]], "Int64"],
676-
[["2019-12-31", "2019-12-29"], [[2020, 1, 2], [2019, 52, 7]], "int32"],
677-
[
678-
["2010-01-01", pd.NaT],
679-
[[2009, 53, 5], [np.NaN, np.NaN, np.NaN]],
680-
"Int64",
681-
],
674+
[["2020-01-01"], [[2020, 1, 3]]],
675+
[[pd.NaT], [[np.NaN, np.NaN, np.NaN]]],
676+
[["2019-12-31", "2019-12-29"], [[2020, 1, 2], [2019, 52, 7]]],
677+
[["2010-01-01", pd.NaT], [[2009, 53, 5], [np.NaN, np.NaN, np.NaN]]],
682678
],
683679
)
684-
def test_isocalendar(self, input_series, expected_output, expected_type):
680+
def test_isocalendar(self, input_series, expected_output):
685681
result = pd.to_datetime(pd.Series(input_series)).dt.isocalendar
686682
expected_frame = pd.DataFrame(
687-
expected_output, columns=["year", "week", "day"]
688-
).astype(expected_type)
683+
expected_output, columns=["year", "week", "day"], dtype="Int64"
684+
)
689685
tm.assert_frame_equal(result, expected_frame)

0 commit comments

Comments
 (0)