@@ -2006,6 +2006,20 @@ class Timedelta(_Timedelta):
2006
2006
" milliseconds" , " microseconds" , " nanoseconds" }
2007
2007
2008
2008
def __new__ (cls , object value = _no_input, unit = None , **kwargs ):
2009
+ unsupported_kwargs = set (kwargs)
2010
+ unsupported_kwargs.difference_update(cls ._req_any_kwargs_new)
2011
+ if unsupported_kwargs or (
2012
+ value is _no_input and
2013
+ not cls ._req_any_kwargs_new.intersection(kwargs)
2014
+ ):
2015
+ raise ValueError (
2016
+ # GH#53801
2017
+ " cannot construct a Timedelta from the passed arguments, "
2018
+ " allowed keywords are "
2019
+ " [weeks, days, hours, minutes, seconds, "
2020
+ " milliseconds, microseconds, nanoseconds]"
2021
+ )
2022
+
2009
2023
if value is _no_input:
2010
2024
if not len (kwargs):
2011
2025
raise ValueError (" cannot construct a Timedelta without a "
@@ -2014,16 +2028,6 @@ class Timedelta(_Timedelta):
2014
2028
2015
2029
kwargs = {key: _to_py_int_float(kwargs[key]) for key in kwargs}
2016
2030
2017
- unsupported_kwargs = set (kwargs)
2018
- unsupported_kwargs.difference_update(cls ._req_any_kwargs_new)
2019
- if unsupported_kwargs or not cls ._req_any_kwargs_new.intersection(kwargs):
2020
- raise ValueError (
2021
- " cannot construct a Timedelta from the passed arguments, "
2022
- " allowed keywords are "
2023
- " [weeks, days, hours, minutes, seconds, "
2024
- " milliseconds, microseconds, nanoseconds]"
2025
- )
2026
-
2027
2031
# GH43764, convert any input to nanoseconds first and then
2028
2032
# create the timedelta. This ensures that any potential
2029
2033
# nanosecond contributions from kwargs parsed as floats
0 commit comments