@@ -3036,7 +3036,10 @@ def read_array(self, key: str, start: int | None = None, stop: int | None = None
3036
3036
if dtype and dtype .startswith ("datetime64" ):
3037
3037
# reconstruct a timezone if indicated
3038
3038
tz = getattr (attrs , "tz" , None )
3039
- ret = _set_tz (ret , tz )
3039
+ if dtype == "datetime64[s]" :
3040
+ ret = _set_tz (ret , tz , unit = "s" )
3041
+ else :
3042
+ ret = _set_tz (ret , tz ) # default unit is ns
3040
3043
3041
3044
elif dtype == "timedelta64" :
3042
3045
ret = np .asarray (ret , dtype = "m8[ns]" )
@@ -4964,19 +4967,22 @@ def _get_tz(tz: tzinfo) -> str | tzinfo:
4964
4967
return zone
4965
4968
4966
4969
4967
- def _set_tz (values : npt .NDArray [np .int64 ], tz : str | tzinfo | None ) -> DatetimeArray :
4970
+ def _set_tz (
4971
+ values : npt .NDArray [np .int64 ], tz : str | tzinfo | None , unit : str = "ns"
4972
+ ) -> DatetimeArray :
4968
4973
"""
4969
4974
Coerce the values to a DatetimeArray with appropriate tz.
4970
4975
4971
4976
Parameters
4972
4977
----------
4973
4978
values : ndarray[int64]
4974
4979
tz : str, tzinfo, or None
4980
+ unit : str. The default unit is ns. Needs to be specified otherwise.
4975
4981
"""
4976
4982
assert values .dtype == "i8" , values .dtype
4977
4983
# Argument "tz" to "tz_to_dtype" has incompatible type "str | tzinfo | None";
4978
4984
# expected "tzinfo"
4979
- dtype = tz_to_dtype (tz = tz , unit = "ns" ) # type: ignore[arg-type]
4985
+ dtype = tz_to_dtype (tz = tz , unit = unit ) # type: ignore[arg-type]
4980
4986
dta = DatetimeArray ._from_sequence (values , dtype = dtype )
4981
4987
return dta
4982
4988
0 commit comments