|
11 | 11 | ) |
12 | 12 | import warnings |
13 | 13 |
|
| 14 | + |
14 | 15 | import numpy as np |
15 | 16 |
|
| 17 | + |
| 18 | + |
16 | 19 | from pandas._libs import lib |
17 | 20 | from pandas.util._exceptions import find_stack_level |
18 | 21 |
|
@@ -108,7 +111,7 @@ def _delegate_property_get(self, name: str): |
108 | 111 | else: |
109 | 112 | index = self._parent.index |
110 | 113 | # return the result as a Series |
111 | | - return Series(result, index=index, name=self.name).__finalize__(self._parent) |
| 114 | + return Series(result, index=index, name=self.name, dtype=result.dtype).__finalize__(self._parent) |
112 | 115 |
|
113 | 116 | def _delegate_property_set(self, name: str, value, *args, **kwargs) -> NoReturn: |
114 | 117 | raise ValueError( |
@@ -396,53 +399,6 @@ def freq(self): |
396 | 399 | '2YS-JAN' |
397 | 400 | """ |
398 | 401 | return self._get_values().inferred_freq |
399 | | - |
400 | | - @property |
401 | | - def date(self): |
402 | | - """ |
403 | | - Return the date component (year, month, day) of each datetime in the Series. |
404 | | -
|
405 | | - This property returns a Series of Python datetime.date objects corresponding to |
406 | | - the date portion of each datetime64[ns] value in the Series. For missing values |
407 | | - (NaT), the result will be NaT. |
408 | | -
|
409 | | - Returns |
410 | | - ------- |
411 | | - Series |
412 | | - A Series of datetime.date objects or NaT, with dtype object. |
413 | | -
|
414 | | - Notes |
415 | | - ----- |
416 | | - - The result is always returned with object dtype. |
417 | | - - This ensures comparisons with Python datetime.date values (e.g. using <=) |
418 | | - work even when the Series contains only missing values (NaT). |
419 | | -
|
420 | | - Examples |
421 | | - -------- |
422 | | - >>> s = pd.Series(pd.to_datetime(["2020-01-01", pd.NaT])) |
423 | | - >>> s.dt.date |
424 | | - 0 2020-01-01 |
425 | | - 1 NaT |
426 | | - dtype: object |
427 | | -
|
428 | | - >>> s.dt.date <= datetime.date(2024, 1, 1) |
429 | | - 0 True |
430 | | - 1 False |
431 | | - dtype: bool |
432 | | - """ |
433 | | - |
434 | | - from pandas import Series |
435 | | - import datetime |
436 | | - |
437 | | - values = self._get_values() |
438 | | - as_dates = values.to_pydatetime() |
439 | | - |
440 | | - def extract_date(x): |
441 | | - return x.date() if isinstance(x, datetime.datetime) else pd.NaT |
442 | | - |
443 | | - result = [extract_date(v) for v in as_dates] |
444 | | - |
445 | | - return Series(result, index=self._parent.index, name=self._parent.name, dtype=object).__finalize__(self._parent) |
446 | 402 |
|
447 | 403 | def isocalendar(self) -> DataFrame: |
448 | 404 | """ |
|
0 commit comments