Skip to content

CLN: remove unused in tools.datetimes #55652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pandas/_libs/tslibs/parsing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ def try_parse_dates(
values: npt.NDArray[np.object_], # object[:]
parser,
) -> npt.NDArray[np.object_]: ...
def try_parse_year_month_day(
years: npt.NDArray[np.object_], # object[:]
months: npt.NDArray[np.object_], # object[:]
days: npt.NDArray[np.object_], # object[:]
) -> npt.NDArray[np.object_]: ...
def guess_datetime_format(
dt_str,
dayfirst: bool | None = ...,
Expand Down
19 changes: 0 additions & 19 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -766,25 +766,6 @@ def try_parse_dates(object[:] values, parser) -> np.ndarray:
return result.base # .base to access underlying ndarray


def try_parse_year_month_day(
object[:] years, object[:] months, object[:] days
) -> np.ndarray:
cdef:
Py_ssize_t i, n
object[::1] result

n = len(years)
# TODO(cython3): Use len instead of `shape[0]`
if months.shape[0] != n or days.shape[0] != n:
raise ValueError("Length of years/months/days must all be equal")
result = np.empty(n, dtype="O")

for i in range(n):
result[i] = datetime(int(years[i]), int(months[i]), int(days[i]))

return result.base # .base to access underlying ndarray


# ----------------------------------------------------------------------
# Miscellaneous

Expand Down
57 changes: 0 additions & 57 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
get_unit_from_dtype,
iNaT,
is_supported_unit,
nat_strings,
parsing,
timezones as libtimezones,
)
from pandas._libs.tslibs.conversion import precision_from_unit
Expand All @@ -42,7 +40,6 @@
AnyArrayLike,
ArrayLike,
DateTimeErrorChoices,
npt,
)
from pandas.util._exceptions import find_stack_level

Expand All @@ -62,14 +59,12 @@
ABCDataFrame,
ABCSeries,
)
from pandas.core.dtypes.missing import notna

from pandas.arrays import (
DatetimeArray,
IntegerArray,
NumpyExtensionArray,
)
from pandas.core import algorithms
from pandas.core.algorithms import unique
from pandas.core.arrays import ArrowExtensionArray
from pandas.core.arrays.base import ExtensionArray
Expand Down Expand Up @@ -1273,58 +1268,6 @@ def coerce(values):
return values


def _attempt_YYYYMMDD(arg: npt.NDArray[np.object_], errors: str) -> np.ndarray | None:
"""
try to parse the YYYYMMDD/%Y%m%d format, try to deal with NaT-like,
arg is a passed in as an object dtype, but could really be ints/strings
with nan-like/or floats (e.g. with nan)

Parameters
----------
arg : np.ndarray[object]
errors : {'raise','ignore','coerce'}
"""

def calc(carg):
# calculate the actual result
carg = carg.astype(object, copy=False)
parsed = parsing.try_parse_year_month_day(
carg / 10000, carg / 100 % 100, carg % 100
)
return tslib.array_to_datetime(parsed, errors=errors)[0]

def calc_with_mask(carg, mask):
result = np.empty(carg.shape, dtype="M8[ns]")
iresult = result.view("i8")
iresult[~mask] = iNaT

masked_result = calc(carg[mask].astype(np.float64).astype(np.int64))
result[mask] = masked_result.astype("M8[ns]")
return result

# try intlike / strings that are ints
try:
return calc(arg.astype(np.int64))
except (ValueError, OverflowError, TypeError):
pass

# a float with actual np.nan
try:
carg = arg.astype(np.float64)
return calc_with_mask(carg, notna(carg))
except (ValueError, OverflowError, TypeError):
pass

# string with NaN-like
try:
mask = ~algorithms.isin(arg, list(nat_strings))
return calc_with_mask(arg, mask)
except (ValueError, OverflowError, TypeError):
pass

return None


__all__ = [
"DateParseError",
"should_cache",
Expand Down