You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Feiyang472 (via GitHub)" <gi...@apache.org> on 2024/08/17 22:06:16 UTC

[PR] GH-43684: [Integration, Parquet, Python] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Feiyang472 opened a new pull request, #43740:
URL: https://github.com/apache/arrow/pull/43740

   See
   https://github.com/apache/arrow/issues/43684


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "buaazhwb (via GitHub)" <gi...@apache.org>.
buaazhwb commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1730979030


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   > Wonder if this is true in CPython compiler? Since this style is widely used in `pyx` scripts...
   It's ok. This style is also widely used in pyx file like array.pxi  and it can save one copy of `T`



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1730390125


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   Wonder if this is true in CPython compiler? Since this style is widely used in `pyx` scripts...



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "Feiyang472 (via GitHub)" <gi...@apache.org>.
Feiyang472 commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2380556946

   @amoeba Hi, seems like we got no further comments, is this MR ready to be approved?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1731235342


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result
+            CPartitionPathFormat result_value
+        result = self.partitioning.Format(
+            Expression.unwrap(expr)
+        )
+        result_value = GetResultValue(result)
+
+        return frombytes(result_value.directory), frombytes(result_value.filename)

Review Comment:
   cc @jorisvandenbossche 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "buaazhwb (via GitHub)" <gi...@apache.org>.
buaazhwb commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1730979030


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   > Wonder if this is true in CPython compiler? Since this style is widely used in `pyx` scripts...
   
   It's ok. This style is also widely used in pyx file like array.pxi  and it can save one copy of `T`



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Integration, Parquet, Python] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2294998690

   :warning: GitHub issue #43684 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1731234035


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   This would simply be more readable by removing the temporary.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "mapleFU (via GitHub)" <gi...@apache.org>.
mapleFU commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1730981644


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   @pitrou I'm not familiar with CPython, and I didn't find the answer, do you think this would be cost, or this separate assign could be optimized out by compiler?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Integration, Parquet, Python] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1722697848


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+        """

Review Comment:
   Adding an example would be good.



##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path

Review Comment:
   ```suggestion
           Convert a filter expression into a tuple of (directory, filename) using 
           the current partitioning scheme
   ```



##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result
+            CPartitionPathFormat result_value
+        result = self.partitioning.Format(
+            Expression.unwrap(expr)
+        )
+        result_value = GetResultValue(result)
+
+        return frombytes(result_value.directory), frombytes(result_value.filename)

Review Comment:
   Could the remainder of this be simplified with `CPartitionPathFormat.wrap`? I'm not very familiar with Cython so let me know.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "Feiyang472 (via GitHub)" <gi...@apache.org>.
Feiyang472 commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1730040769


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+        """

Review Comment:
   I have added an example



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "Feiyang472 (via GitHub)" <gi...@apache.org>.
Feiyang472 commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2308210835

   I will add more docs and test over the weekend.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "Feiyang472 (via GitHub)" <gi...@apache.org>.
Feiyang472 commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1729832877


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result
+            CPartitionPathFormat result_value
+        result = self.partitioning.Format(
+            Expression.unwrap(expr)
+        )
+        result_value = GetResultValue(result)
+
+        return frombytes(result_value.directory), frombytes(result_value.filename)

Review Comment:
   Hi @amoeba , I am fairly new to arrow cython api as well, so I might be wrong. `CPartitionPathFormat` is just cython's name (by arrow convention) for the `PartitionPathFormat` C struct. The `wrap` and `unwrap` methods are methods of the `_WeakRefable` class, which convert cpp shared pointers to cython wrappers or vice versa. Cpp shared pointers cannot be given to python, and cython classes cannot be given to C, but both can interact in cython code, hence the wrapping. C structs of builtin types, unlike shared pointers to objects, can be automatically converted by cython into python dicts. Here I have chosen to return a tuple instead, because it feels more pythonic.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2330469985

   Hi @Feiyang472, this is looking good. Thanks for continuing to work on it. I left one code suggestion and can you fix the numpydoc issue in https://github.com/apache/arrow/actions/runs/10670333956/job/29702635856?pr=43740#step:6:9090?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2404741859

   Revision: 1c8364ba88a1f351311791f3c5f6ffe3c4cb98cf
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-aee53b4c69](https://github.com/ursacomputing/crossbow/branches/all?query=actions-aee53b4c69)
   
   |Task|Status|
   |----|------|
   |example-python-minimal-build-fedora-conda|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-aee53b4c69-github-example-python-minimal-build-fedora-conda)](https://github.com/ursacomputing/crossbow/actions/runs/11272442167/job/31347369035)|
   |example-python-minimal-build-ubuntu-venv|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-aee53b4c69-github-example-python-minimal-build-ubuntu-venv)](https://github.com/ursacomputing/crossbow/actions/runs/11272442172/job/31347369143)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2400535349

   After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 44fb439ad91b802faf08cbf097b67fa84bdac8d1.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/31252868217) has more details. It also includes information about 2 possible false positives for unstable benchmarks that are known to sometimes produce them.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2332965777

   @jorisvandenbossche and/or @pitrou: The changes here look good to me, would either of you like to review?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1746347002


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   Temporary removed in [`4b4f3cf` (#43740)](https://github.com/apache/arrow/pull/43740/commits/4b4f3cfa39ec11c05d6fe779d7555f953f4ff88d).



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1746347002


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   Removed in [`4b4f3cf` (#43740)](https://github.com/apache/arrow/pull/43740/commits/4b4f3cfa39ec11c05d6fe779d7555f953f4ff88d).



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2406073992

   Thanks @raulcd.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "Feiyang472 (via GitHub)" <gi...@apache.org>.
Feiyang472 commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1729836067


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,28 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Parse a partition expression into a tuple of directory, path
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result
+            CPartitionPathFormat result_value
+        result = self.partitioning.Format(
+            Expression.unwrap(expr)
+        )
+        result_value = GetResultValue(result)
+
+        return frombytes(result_value.directory), frombytes(result_value.filename)

Review Comment:
   If we aim for symmetry with the existing `Parse` method, we could join the strings, probably less ambiguous



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "buaazhwb (via GitHub)" <gi...@apache.org>.
buaazhwb commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1730385434


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result

Review Comment:
   We can optimize the temporal variable `result` by combine `Format` and `GetResultValue`



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #43740:
URL: https://github.com/apache/arrow/pull/43740#discussion_r1744706643


##########
python/pyarrow/_dataset.pyx:
##########
@@ -2505,6 +2505,43 @@ cdef class Partitioning(_Weakrefable):
         result = self.partitioning.Parse(tobytes(path))
         return Expression.wrap(GetResultValue(result))
 
+    def format(self, expr):
+        """
+        Convert a filter expression into a tuple of (directory, filename) using 
+        the current partitioning scheme
+
+        Parameters
+        ----------
+        expr : pyarrow.dataset.Expression
+
+        Returns
+        -------
+        tuple[str, str]
+
+        Examples
+        --------
+
+        Specify the Schema for paths like "/2009/June":
+
+        >>> import pyarrow as pa
+        >>> import pyarrow.dataset as ds
+        >>> import pyarrow.compute as pc
+        >>> part = ds.partitioning(pa.schema([("year", pa.int16()),
+        ...                                   ("month", pa.string())]))
+        >>> part.format(
+        ...     (pc.field("year") == 1862) & (pc.field("month") == "Jan")
+        ... )
+        """
+        cdef:
+            CResult[CPartitionPathFormat] result
+            CPartitionPathFormat result_value
+        result = self.partitioning.Format(
+            Expression.unwrap(expr)
+        )
+        result_value = GetResultValue(result)
+
+        return frombytes(result_value.directory), frombytes(result_value.filename)

Review Comment:
   ```suggestion
           cdef:
               CPartitionPathFormat result
   
           result = GetResultValue(self.partitioning.Format(
               Expression.unwrap(expr)
           ))
   
           return frombytes(result.directory), frombytes(result.filename)
   ```



##########
python/pyarrow/tests/parquet/test_dataset.py:
##########
@@ -1216,7 +1222,6 @@ def test_read_table_duplicate_column_selection(tempdir):
 
 
 def test_dataset_partitioning(tempdir):
-    import pyarrow.dataset as ds

Review Comment:
   I don't think this and a few other changes are necessary here, can you revert just those that are formatting-related?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2404741052

   This PR seems to have broken tests if we run with minimal pyarrow (i.e no dataset) as pytest `@pytest.mark.parametrize` fails if dataset is not enabled:
   
   ```
    _ ERROR collecting miniconda-for-arrow/envs/pyarrow-3.10/lib/python3.10/site-packages/pyarrow/tests/test_dataset.py _
   miniconda-for-arrow/envs/pyarrow-3.10/lib/python3.10/site-packages/pyarrow/tests/test_dataset.py:740: in <module>
       (ds.HivePartitioning, (r"foo=A/bar=ant%20bee", ""), ("", "")),
   E   AttributeError: 'NoneType' object has no attribute 'HivePartitioning'
   ```
   I'll try to fix for 18.0.0


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-43684: [Python][Dataset] Python / Cython interface to C++ arrow::dataset::Partitioning::Format [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #43740:
URL: https://github.com/apache/arrow/pull/43740#issuecomment-2404737521

   @github-actions crossbow submit example-python-minimal-*


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org