tadeja commented on code in PR #55811:
URL: https://github.com/apache/arrow/pull/55811#discussion_r4770086472


##########
python/pyarrow/src/arrow/python/datetime.h:
##########
@@ -203,6 +209,44 @@ Result<PyObject*> StringToTzinfo(const std::string& tz, 
bool prefer_zoneinfo = t
 ARROW_PYTHON_EXPORT
 Result<std::string> TzinfoToString(PyObject* pytzinfo);
 
+/// \brief Convert Month to a python namedtuple.
+///
+/// Return a named tuple (pyarrow.Month) containing "months".
+///
+/// GIL must be held when calling this method.
+ARROW_PYTHON_EXPORT
+PyObject* MonthIntervalToNamedTuple(MonthIntervalType::c_type interval);
+
+/// \brief Convert the given Array to a PyList object containing
+/// pyarrow.Month objects.
+ARROW_PYTHON_EXPORT
+Result<PyObject*> MonthIntervalArrayToPyList(const MonthIntervalArray& array);
+
+/// \brief Convert the Scalar object to a pyarrow.Month (or None if
+/// is isn't valid).

Review Comment:
   ```suggestion
   /// it isn't valid).
   ```



##########
python/pyarrow/src/arrow/python/datetime.h:
##########
@@ -203,6 +209,44 @@ Result<PyObject*> StringToTzinfo(const std::string& tz, 
bool prefer_zoneinfo = t
 ARROW_PYTHON_EXPORT
 Result<std::string> TzinfoToString(PyObject* pytzinfo);
 
+/// \brief Convert Month to a python namedtuple.
+///
+/// Return a named tuple (pyarrow.Month) containing "months".
+///
+/// GIL must be held when calling this method.
+ARROW_PYTHON_EXPORT
+PyObject* MonthIntervalToNamedTuple(MonthIntervalType::c_type interval);
+
+/// \brief Convert the given Array to a PyList object containing
+/// pyarrow.Month objects.
+ARROW_PYTHON_EXPORT
+Result<PyObject*> MonthIntervalArrayToPyList(const MonthIntervalArray& array);
+
+/// \brief Convert the Scalar object to a pyarrow.Month (or None if
+/// is isn't valid).
+ARROW_PYTHON_EXPORT
+Result<PyObject*> MonthIntervalScalarToPyObject(const MonthIntervalScalar& 
scalar);
+
+/// \brief Convert DayTime to a python namedtuple.
+///
+/// Return a named tuple (pyarrow.DayTime) containing attributes
+/// "days", "milliseconds" in the given order.
+///
+/// GIL must be held when calling this method.
+ARROW_PYTHON_EXPORT
+PyObject* DayTimeIntervalToNamedTuple(
+    const DayTimeIntervalType::DayMilliseconds& interval);
+
+/// \brief Convert the given Array to a PyList object containing
+/// pyarrow.DayTime objects.
+ARROW_PYTHON_EXPORT
+Result<PyObject*> DayTimeIntervalArrayToPyList(const DayTimeIntervalArray& 
array);
+
+/// \brief Convert the Scalar object to a pyarrow.DayTime (or None if
+/// is isn't valid).

Review Comment:
   ```suggestion
   /// it isn't valid).
   ```



##########
python/pyarrow/types.pxi:
##########
@@ -4350,6 +4350,81 @@ def duration(unit):
     return out
 
 
+def month_interval():
+    """
+    Create instance of an interval type representing months
+    between two dates.
+
+    Examples
+    --------
+    Create an instance of an month_interval type:
+
+    >>> import pyarrow as pa
+    >>> pa.month_interval()
+    DataType(month_interval)
+
+    The type can't be created from Python values yet, but
+    compute functions return it:
+
+    >>> import pyarrow as pa
+    >>> import pyarrow.compute as pc
+    >>> import datetime
+    >>> arr1 = pa.array([datetime.datetime(2020, 1, 1)], 
type=pa.timestamp('s'))
+    >>> arr2 = pa.array([datetime.datetime(2020, 5, 5)], 
type=pa.timestamp('s'))
+
+    Create an array with month_interval type:
+
+    >>> pc.month_interval_between(arr1, arr2)
+    <pyarrow.lib.MonthIntervalArray object at ...>
+    [
+      4M
+    ]
+
+    or select a scalar with the same type:
+
+    >>> pc.month_interval_between(arr1, arr2)[0]
+    <pyarrow.MonthIntervalScalar: Month(months=4)>
+    """
+    return primitive_type(_Type_INTERVAL_MONTHS)
+
+
+def day_time_interval():
+    """
+    Create instance of an interval type representing day and
+    milliseconds between two dates.
+
+    Examples
+    --------
+    Create an instance of an day_time_interval type:

Review Comment:
   ```suggestion
       Create an instance of a day_time_interval type:
   ```



##########
python/pyarrow/src/arrow/python/datetime.cc:
##########
@@ -52,23 +52,36 @@ bool MatchFixedOffset(const std::string& tz, 
std::string_view* sign,
   return RegexMatch(regex, tz, {sign, hour, minute});
 }
 
-constexpr char* NonConst(const char* st) {
-  // Hack for python versions < 3.7 where members of PyStruct members
-  // where non-const (C++ doesn't like assigning string literals to these 
types)
-  return const_cast<char*>(st);
-}
+static PyTypeObject MonthTupleType = {};
+
+static PyStructSequence_Field MonthField[] = {
+    {"months", "The number of months in the interval"}, {nullptr, nullptr}};
+
+static PyStructSequence_Desc MonthTupleDesc = {
+    "Month", "A calendar interval consisting of months.", MonthField,
+    /*n_in_sequence=*/1};
+
+static PyTypeObject DayTimeTupleType = {};
+
+static PyStructSequence_Field DayTimeField[] = {
+    {"days", "The number days in the interval"},

Review Comment:
   ```suggestion
       {"days", "The number of days in the interval"},
   ```



##########
python/pyarrow/types.pxi:
##########
@@ -4350,6 +4350,81 @@ def duration(unit):
     return out
 
 
+def month_interval():
+    """
+    Create instance of an interval type representing months
+    between two dates.
+
+    Examples
+    --------
+    Create an instance of an month_interval type:

Review Comment:
   ```suggestion
       Create an instance of a month_interval type:
   ```



##########
python/pyarrow/types.pxi:
##########


Review Comment:
   This 'an' typo was there before PR (cannot add a suggestion here as github 
ruins it somehow) 



##########
python/pyarrow/src/arrow/python/datetime.h:
##########


Review Comment:
   This 'is isn't' typo was there before PR (I think adding a suggestion here 
would make github ruin it somehow ... so I won't!)



##########
python/pyarrow/src/arrow/python/datetime.cc:
##########
@@ -52,23 +52,36 @@ bool MatchFixedOffset(const std::string& tz, 
std::string_view* sign,
   return RegexMatch(regex, tz, {sign, hour, minute});
 }
 
-constexpr char* NonConst(const char* st) {
-  // Hack for python versions < 3.7 where members of PyStruct members
-  // where non-const (C++ doesn't like assigning string literals to these 
types)
-  return const_cast<char*>(st);
-}
+static PyTypeObject MonthTupleType = {};
+
+static PyStructSequence_Field MonthField[] = {
+    {"months", "The number of months in the interval"}, {nullptr, nullptr}};
+
+static PyStructSequence_Desc MonthTupleDesc = {
+    "Month", "A calendar interval consisting of months.", MonthField,
+    /*n_in_sequence=*/1};
+
+static PyTypeObject DayTimeTupleType = {};
+
+static PyStructSequence_Field DayTimeField[] = {
+    {"days", "The number days in the interval"},
+    {"milliseconds", "The number of milliseconds in the interval"},
+    {nullptr, nullptr}};
+
+static PyStructSequence_Desc DayTimeTupleDesc = {
+    "DayTime", "A calendar interval consisting of days and milliseconds.", 
DayTimeField,
+    /*n_in_sequence=*/2};
 
 static PyTypeObject MonthDayNanoTupleType = {};
 
 static PyStructSequence_Field MonthDayNanoField[] = {
-    {NonConst("months"), NonConst("The number of months in the interval")},
-    {NonConst("days"), NonConst("The number days in the interval")},
-    {NonConst("nanoseconds"), NonConst("The number of nanoseconds in the 
interval")},
+    {"months", "The number of months in the interval"},
+    {"days", "The number days in the interval"},

Review Comment:
   ```suggestion
       {"days", "The number of days in the interval"},
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to